diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.h.in | 1 | ||||
-rw-r--r-- | src/msg.cpp | 0 | ||||
-rw-r--r-- | src/netaddr.cpp | 30 | ||||
-rw-r--r-- | src/network.cpp | 52 | ||||
-rw-r--r-- | src/stream.cpp | 69 |
5 files changed, 152 insertions, 0 deletions
diff --git a/src/config.h.in b/src/config.h.in index fb39d63..c4ab698 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -6,5 +6,6 @@ #cmakedefine SALTICIDAE_MSG_STAT #cmakedefine SALTICIDAE_NOCHECK #cmakedefine SALTICIDAE_NOCHECKSUM +#cmakedefine SALTICIDAE_CBINDINGS #endif diff --git a/src/msg.cpp b/src/msg.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/msg.cpp diff --git a/src/netaddr.cpp b/src/netaddr.cpp new file mode 100644 index 0000000..a3a54bf --- /dev/null +++ b/src/netaddr.cpp @@ -0,0 +1,30 @@ +#include "salticidae/netaddr.h" + +using namespace salticidae; + +#ifdef __cplusplus + +extern "C" { + +netaddr_t *netaddr_new() { return new NetAddr(); } +netaddr_t *netaddr_new_from_ip_port(uint32_t ip, uint16_t port) { + return new NetAddr(ip, port); +} + +netaddr_t *netaddr_new_from_sip_port(const char *ip, uint16_t port) { + return new NetAddr(ip, port); +} + +netaddr_t *netaddr_new_from_sipport(const char *ip_port_addr) { + return new NetAddr(ip_port_addr); +} + +bool netaddr_is_eq(const netaddr_t *a, const netaddr_t *b) { + return *a == *b; +} + +bool netaddr_is_null(const netaddr_t *self) { return self->is_null(); } + +} + +#endif diff --git a/src/network.cpp b/src/network.cpp new file mode 100644 index 0000000..cefe723 --- /dev/null +++ b/src/network.cpp @@ -0,0 +1,52 @@ +#include "salticidae/network.h" +#ifdef SALTICIDAE_CBINDINGS + +using namespace salticidae; + +extern "C" { + +msg_t _test_create_msg() { + return msg_t(0x0, bytearray_t()); +} + + +msgnetwork_t *msgnetwork_new(const EventContext *ec, const msgnetwork_config_t *config) { + return new msgnetwork_t(*ec, *config); +} + +bool msgnetwork_send_msg(msgnetwork_t *self, + const msg_t *msg, const msgnetwork_conn_t *conn) { + return self->send_msg(*msg, *conn); +} + +msgnetwork_conn_t *msgnetwork_connect(msgnetwork_t *self, const netaddr_t *addr) { + return new msgnetwork_t::conn_t(self->connect(*addr)); +} + +void msgnetwork_listen(msgnetwork_t *self, const netaddr_t *listen_addr) { + self->listen(*listen_addr); +} + +#ifdef SALTICIDAE_CBINDINGS_STR_OP +void msgnetwork_reg_handler(msgnetwork_t *self, + const char *opcode, + msgnetwork_msg_callback_t cb) { + self->set_handler(std::string(opcode), + [cb](const msgnetwork_t::Msg &msg, const msgnetwork_t::conn_t &conn) { + cb(&msg, &conn); + }); +} +#else +void msgnetwork_reg_handler(msgnetwork_t *self, + uint8_t opcode, + msgnetwork_msg_callback_t cb) { + self->set_handler(opcode, + [cb](const msgnetwork_t::Msg &msg, const msgnetwork_t::conn_t &conn) { + cb(&msg, &conn); + }); +} +#endif + +} + +#endif diff --git a/src/stream.cpp b/src/stream.cpp new file mode 100644 index 0000000..8846414 --- /dev/null +++ b/src/stream.cpp @@ -0,0 +1,69 @@ +#include "salticidae/stream.h" + +using namespace salticidae; + +#ifdef __cplusplus + +extern "C" { + +uint256_t *uint256_new() { return new uint256_t(); } +uint256_t *uint256_new_from_bytes(const uint8_t *arr) { + return new uint256_t(arr); +} + +bool uint256_is_null(const uint256_t *self) { return self->is_null(); } +bool uint256_is_eq(const uint256_t *a, const uint256_t *b) { + return *a == *b; +} + +void uint256_serialize(const uint256_t *self, datastream_t *s) { + self->serialize(*s); +} + +void uint256_unserialize(uint256_t *self, datastream_t *s) { + self->unserialize(*s); +} + +datastream_t *datastream_new() { return new DataStream(); } +datastream_t *datastream_new_from_bytes(const uint8_t *begin, const uint8_t *end) { + return new DataStream(begin, end); +} + +void datastream_assign_by_copy(datastream_t *dst, const datastream_t *src) { + *dst = *src; +} + +void datastream_assign_by_move(datastream_t *dst, datastream_t *src) { + *dst = std::move(*src); +} + +uint8_t *datastream_data(datastream_t *self) { return self->data(); } + +void datastream_clear(datastream_t *self) { self->clear(); } + +size_t datastream_size(const datastream_t *self) { return self->size(); } + +void datastream_put_u8(datastream_t *self, uint8_t val) { *self << val; } +void datastream_put_u16(datastream_t *self, uint16_t val) { *self << val; } +void datastream_put_u32(datastream_t *self, uint32_t val) { *self << val; } + +void datastream_put_i8(datastream_t *self, int8_t val) { *self << val; } +void datastream_put_i16(datastream_t *self, int16_t val) { *self << val; } +void datastream_put_i32(datastream_t *self, int32_t val) { *self << val; } + +void datastream_put_data(datastream_t *self, + uint8_t *begin, uint8_t *end) { + self->put_data(begin, end); +} + +const uint8_t *datastream_get_data_inplace(datastream_t *self, size_t len) { + return self->get_data_inplace(len); +} + +uint256_t *datastream_get_hash(const datastream_t *self) { + return new uint256_t(self->get_hash()); +} + +} + +#endif |