aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/event.cpp24
-rw-r--r--src/msg.cpp23
-rw-r--r--src/network.cpp22
-rw-r--r--src/stream.cpp27
-rw-r--r--src/type.cpp20
5 files changed, 107 insertions, 9 deletions
diff --git a/src/event.cpp b/src/event.cpp
new file mode 100644
index 0000000..050914c
--- /dev/null
+++ b/src/event.cpp
@@ -0,0 +1,24 @@
+#ifdef SALTICIDAE_CBINDINGS
+#include "salticidae/event.h"
+
+extern "C" {
+
+eventcontext_t *eventcontext_new() { return new eventcontext_t(); }
+
+void eventcontext_dispatch(eventcontext_t *self) { return self->dispatch(); }
+
+void eventcontext_stop(eventcontext_t *self) { return self->stop(); }
+
+void eventcontext_free(eventcontext_t *self) { delete self; }
+
+void sigev_new(const eventcontext_t *self, sigev_callback_t cb) {
+ return new SigEvent(*self, cb);
+}
+
+void sigev_add(sigev_t *self, int sig) { self->add(sig); }
+
+void sigev_delete() { delete self; }
+
+}
+
+#endif
diff --git a/src/msg.cpp b/src/msg.cpp
index e69de29..e75d7d4 100644
--- a/src/msg.cpp
+++ b/src/msg.cpp
@@ -0,0 +1,23 @@
+#ifdef SALTICIDAE_CBINDINGS
+#include "salticidae/msg.h"
+
+extern "C" {
+
+msg_t *msg_new(_opcode_t opcode, bytearray_t *_moved_payload) {
+ auto res = new msg_t(opcode, *payload);
+ bytearray_free(payload);
+}
+
+datastream_t *msg_get_payload(msg_t *msg) {
+ return new datastream_t(msg->get_payload());
+}
+
+const _opcode_t msg_get_opcode(const msg_t *msg) {
+ return msg->get_opcode();
+}
+
+void msg_free(msg_t *msg) { delete msg; }
+
+}
+
+#endif
diff --git a/src/network.cpp b/src/network.cpp
index cefe723..0b12131 100644
--- a/src/network.cpp
+++ b/src/network.cpp
@@ -1,16 +1,11 @@
-#include "salticidae/network.h"
#ifdef SALTICIDAE_CBINDINGS
+#include "salticidae/network.h"
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) {
+msgnetwork_t *msgnetwork_new(const eventcontext_t *ec, const msgnetwork_config_t *config) {
return new msgnetwork_t(*ec, *config);
}
@@ -47,6 +42,19 @@ void msgnetwork_reg_handler(msgnetwork_t *self,
}
#endif
+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) {
+ auto conn = salticidae::static_pointer_cast<msgnetwork_t::Conn>(_conn);
+ cb(&conn, connected);
+ });
+}
+
+msgnetwork_t *msgnetwork_conn_get_net(const msgnetwork_conn_t *conn) {
+ return (*conn)->get_net();
+}
+
+void msgnetwork_start(msgnetwork_t *self) { self->start(); }
+
}
#endif
diff --git a/src/stream.cpp b/src/stream.cpp
index 8846414..f3dd322 100644
--- a/src/stream.cpp
+++ b/src/stream.cpp
@@ -1,9 +1,8 @@
+#ifdef SALTICIDAE_CBINDINGS
#include "salticidae/stream.h"
using namespace salticidae;
-#ifdef __cplusplus
-
extern "C" {
uint256_t *uint256_new() { return new uint256_t(); }
@@ -56,6 +55,30 @@ void datastream_put_data(datastream_t *self,
self->put_data(begin, end);
}
+uint8_t datastream_get_u8(datastream_t *self) {
+ uint8_t val; *self >> val; return val;
+}
+
+uint16_t datastream_get_u16(datastream_t *self) {
+ uint16_t val; *self >> val; return val;
+}
+
+uint32_t datastream_get_u32(datastream_t *self) {
+ uint32_t val; *self >> val; return val;
+}
+
+int8_t datastream_get_i8(datastream_t *self) {
+ int8_t val; *self >> val; return val;
+}
+
+int16_t datastream_get_i16(datastream_t *self) {
+ int16_t val; *self >> val; return val;
+}
+
+int32_t datastream_get_i32(datastream_t *self) {
+ int32_t val; *self >> val; return val;
+}
+
const uint8_t *datastream_get_data_inplace(datastream_t *self, size_t len) {
return self->get_data_inplace(len);
}
diff --git a/src/type.cpp b/src/type.cpp
new file mode 100644
index 0000000..8290a07
--- /dev/null
+++ b/src/type.cpp
@@ -0,0 +1,20 @@
+#ifdef SALTICIDAE_CBINDINGS
+#include "salticidae/type.h"
+
+extern "C" {
+
+uint8_t *bytearray_data(bytearray_t *arr) {
+ return &(*arr)[0];
+}
+
+size_t bytearray_size(bytearray_t *arr) {
+ return arr->size();
+}
+
+void bytearray_free(bytearray_t *arr) {
+ delete arr;
+}
+
+}
+
+#endif