aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/event.cpp8
-rw-r--r--src/msg.cpp6
-rw-r--r--src/netaddr.cpp3
-rw-r--r--src/network.cpp33
-rw-r--r--src/stream.cpp42
-rw-r--r--src/type.cpp4
6 files changed, 39 insertions, 57 deletions
diff --git a/src/event.cpp b/src/event.cpp
index 0daa498..6078c37 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -6,19 +6,19 @@ extern "C" {
eventcontext_t *eventcontext_new() { return new eventcontext_t(); }
+void eventcontext_free(eventcontext_t *self) { delete self; }
+
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; }
-
sigev_t *sigev_new(const eventcontext_t *self, sigev_callback_t cb) {
return new sigev_t(*self, cb);
}
-void sigev_add(sigev_t *self, int sig) { self->add(sig); }
+void sigev_free(sigev_t *self) { delete self; }
-void sigev_delete(sigev_t *self) { delete self; }
+void sigev_add(sigev_t *self, int sig) { self->add(sig); }
}
diff --git a/src/msg.cpp b/src/msg.cpp
index caee1c7..33dc31c 100644
--- a/src/msg.cpp
+++ b/src/msg.cpp
@@ -10,16 +10,16 @@ msg_t *msg_new(_opcode_t opcode, bytearray_t *_moved_payload) {
return res;
}
+void msg_free(msg_t *msg) { delete msg; }
+
datastream_t *msg_get_payload(const msg_t *msg) {
return new datastream_t(msg->get_payload());
}
-const _opcode_t msg_get_opcode(const msg_t *msg) {
+_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/netaddr.cpp b/src/netaddr.cpp
index 1803629..3c2618a 100644
--- a/src/netaddr.cpp
+++ b/src/netaddr.cpp
@@ -5,6 +5,9 @@
extern "C" {
netaddr_t *netaddr_new() { return new netaddr_t(); }
+
+void netaddr_free(const netaddr_t *self) { delete self; }
+
netaddr_t *netaddr_new_from_ip_port(uint32_t ip, uint16_t port) {
return new netaddr_t(ip, port);
}
diff --git a/src/network.cpp b/src/network.cpp
index 58b3ce1..9fc07fe 100644
--- a/src/network.cpp
+++ b/src/network.cpp
@@ -6,13 +6,21 @@ using namespace salticidae;
extern "C" {
+msgnetwork_config_t *msgnetwork_config_new() {
+ return new msgnetwork_config_t();
+}
+
+void msgnetwork_config_free(const msgnetwork_config_t *self) { delete self; }
+
msgnetwork_t *msgnetwork_new(const eventcontext_t *ec, const msgnetwork_config_t *config) {
return new msgnetwork_t(*ec, *config);
}
+void msgnetwork_free(const msgnetwork_t *self) { delete self; }
+
bool msgnetwork_send_msg(msgnetwork_t *self,
const msg_t *msg, const msgnetwork_conn_t *conn) {
- return self->send_msg(*msg, *conn);
+ return self->send_msg(*msg, *conn);
}
msgnetwork_conn_t *msgnetwork_connect(msgnetwork_t *self, const netaddr_t *addr) {
@@ -23,25 +31,14 @@ 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,
+ _opcode_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
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) {
@@ -50,12 +47,12 @@ void msgnetwork_reg_conn_handler(msgnetwork_t *self, msgnetwork_conn_callback_t
});
}
+void msgnetwork_start(msgnetwork_t *self) { self->start(); }
+
msgnetwork_t *msgnetwork_conn_get_net(const msgnetwork_conn_t *conn) {
return (*conn)->get_net();
}
-void msgnetwork_start(msgnetwork_t *self) { self->start(); }
-
msgnetwork_conn_mode_t msgnetwork_conn_get_mode(const msgnetwork_conn_t *conn) {
return (msgnetwork_conn_mode_t)(*conn)->get_mode();
}
@@ -64,12 +61,6 @@ netaddr_t *msgnetwork_conn_get_addr(const msgnetwork_conn_t *conn) {
return new netaddr_t((*conn)->get_addr());
}
-msgnetwork_config_t *msgnetwork_config_new() {
- return new msgnetwork_config_t();
-}
-
-void msgnetwork_config_free(msgnetwork_config_t *self) { delete self; }
-
}
#endif
diff --git a/src/stream.cpp b/src/stream.cpp
index 2fe1a11..1925419 100644
--- a/src/stream.cpp
+++ b/src/stream.cpp
@@ -8,6 +8,7 @@ uint256_t *uint256_new() { return new uint256_t(); }
uint256_t *uint256_new_from_bytes(const uint8_t *arr) {
return new uint256_t(arr);
}
+void uint256_free(const uint256_t *self) { delete self; }
bool uint256_is_null(const uint256_t *self) { return self->is_null(); }
bool uint256_is_eq(const uint256_t *a, const uint256_t *b) {
@@ -26,6 +27,7 @@ datastream_t *datastream_new() { return new datastream_t(); }
datastream_t *datastream_new_from_bytes(const uint8_t *begin, const uint8_t *end) {
return new datastream_t(begin, end);
}
+void datastream_free(const datastream_t *self) { delete self; }
void datastream_assign_by_copy(datastream_t *dst, const datastream_t *src) {
*dst = *src;
@@ -44,39 +46,27 @@ 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_u64(datastream_t *self, uint64_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_i64(datastream_t *self, int64_t val) { *self << val; }
void datastream_put_data(datastream_t *self,
const uint8_t *begin, const uint8_t *end) {
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;
-}
+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; }
+uint64_t datastream_get_u64(datastream_t *self) { uint64_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;
-}
+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; }
+int64_t datastream_get_i64(datastream_t *self) { int64_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);
@@ -86,11 +76,9 @@ uint256_t *datastream_get_hash(const datastream_t *self) {
return new uint256_t(self->get_hash());
}
-void datastream_free(const datastream_t *self) { delete self; }
-
-bytearray_t *datastream_to_bytearray(datastream_t *self) {
- auto res = new bytearray_t(std::move(*self));
- delete self;
+bytearray_t *datastream_to_bytearray(datastream_t *_moved_self) {
+ auto res = new bytearray_t(std::move(*_moved_self));
+ delete _moved_self;
return res;
}
diff --git a/src/type.cpp b/src/type.cpp
index 90d5055..397daac 100644
--- a/src/type.cpp
+++ b/src/type.cpp
@@ -6,12 +6,12 @@ extern "C" {
bytearray_t *bytearray_new() { return new bytearray_t(); }
+void bytearray_free(bytearray_t *arr) { delete arr; }
+
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