diff options
author | Determinant <[email protected]> | 2019-06-08 19:22:29 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-06-08 19:22:29 -0400 |
commit | 66c711cf653b082ae07e1119417dcb3461039c80 (patch) | |
tree | 4f018d84c6efc4dbaa3cf31102e26c0dd5db8b76 /src | |
parent | 1f5bffd006ef432a2fa12fe5baf03c7160c42f73 (diff) |
major API update
Diffstat (limited to 'src')
-rw-r--r-- | src/event.cpp | 38 | ||||
-rw-r--r-- | src/network.cpp | 15 | ||||
-rw-r--r-- | src/stream.cpp | 6 |
3 files changed, 48 insertions, 11 deletions
diff --git a/src/event.cpp b/src/event.cpp index 6078c37..2e38e5f 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -12,14 +12,48 @@ void eventcontext_dispatch(eventcontext_t *self) { return self->dispatch(); } void eventcontext_stop(eventcontext_t *self) { return self->stop(); } -sigev_t *sigev_new(const eventcontext_t *self, sigev_callback_t cb) { - return new sigev_t(*self, cb); +sigev_t *sigev_new(const eventcontext_t *self, sigev_callback_t callback) { + return new sigev_t(*self, callback); +} + +threadcall_t *threadcall_new(const eventcontext_t *ec) { return new threadcall_t(*ec); } + +void threadcall_free(threadcall_t *self) { delete self; } + +void threadcall_async_call(threadcall_t *self, threadcall_callback_t callback, void *userdata) { + self->async_call([=](salticidae::ThreadCall::Handle &h) { + callback(&h, userdata); + }); +} + +eventcontext_t *threadcall_get_ec(threadcall_t *self) { + return new eventcontext_t(self->get_ec()); } void sigev_free(sigev_t *self) { delete self; } void sigev_add(sigev_t *self, int sig) { self->add(sig); } +timerev_t *timerev_new(const eventcontext_t *ec, timerev_callback_t callback) { + return new timerev_t(*ec, [callback](salticidae::TimerEvent &ev) { + callback(&ev); + }); +} + +void timerev_set_callback(timerev_t *self, timerev_callback_t callback) { + self->set_callback([callback](salticidae::TimerEvent &ev) { + callback(&ev); + }); +} + +void timerev_free(timerev_t *self) { delete self; } + +void timerev_add(timerev_t *self, double t_sec) { self->add(t_sec); } + +void timerev_del(timerev_t *self) { self->del(); } + +void timerev_clear(timerev_t *self) { self->clear(); } + } #endif diff --git a/src/network.cpp b/src/network.cpp index eb32f62..c14531c 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -35,17 +35,20 @@ void msgnetwork_listen(msgnetwork_t *self, const netaddr_t *listen_addr) { void msgnetwork_reg_handler(msgnetwork_t *self, _opcode_t opcode, - msgnetwork_msg_callback_t cb) { + msgnetwork_msg_callback_t cb, + void *userdata) { self->set_handler(opcode, - [cb](const msgnetwork_t::Msg &msg, const msgnetwork_conn_t &conn) { - cb(&msg, &conn); + [=](const msgnetwork_t::Msg &msg, const msgnetwork_conn_t &conn) { + cb(&msg, &conn, userdata); }); } -void msgnetwork_reg_conn_handler(msgnetwork_t *self, msgnetwork_conn_callback_t cb) { - self->reg_conn_handler([cb](const ConnPool::conn_t &_conn, bool connected) { +void msgnetwork_reg_conn_handler(msgnetwork_t *self, + msgnetwork_conn_callback_t cb, + void *userdata) { + self->reg_conn_handler([=](const ConnPool::conn_t &_conn, bool connected) { auto conn = salticidae::static_pointer_cast<msgnetwork_t::Conn>(_conn); - cb(&conn, connected); + cb(&conn, connected, userdata); }); } diff --git a/src/stream.cpp b/src/stream.cpp index 9dfe5fc..9ad41aa 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -77,9 +77,9 @@ uint256_t *datastream_get_hash(const datastream_t *self) { return new uint256_t(self->get_hash()); } -bytearray_t *datastream_to_bytearray(datastream_t *_moved_self) { - auto res = new bytearray_t(std::move(*_moved_self)); - delete _moved_self; +bytearray_t *bytearray_new_moved_from_datastream(datastream_t *_moved_src) { + auto res = new bytearray_t(std::move(*_moved_src)); + delete _moved_src; return res; } |