diff options
author | Determinant <[email protected]> | 2019-06-03 17:30:01 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-06-03 17:30:01 -0400 |
commit | 9f294eb2e0ae0bed8120fc34fd9782f2f0a9ac74 (patch) | |
tree | d5005c9888874bd2b169fcd51418a3fab36fe631 /src/network.cpp | |
parent | 9ec5a371f5c05fda8ddeac3470be6fc5c67d44e9 (diff) |
WIP: C bindings
Diffstat (limited to 'src/network.cpp')
-rw-r--r-- | src/network.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
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 |