aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-06-28 17:10:36 -0400
committerDeterminant <[email protected]>2019-06-28 17:10:36 -0400
commitfedfeaced48150e27907628244e95ca54dbe7c02 (patch)
tree40643888f7f1fe4ddfe75f777c7dddd5c276feb9
parent06b5a84602dc6a5dd76d82c9f88359cdb8cf52da (diff)
more api
-rw-r--r--include/salticidae/event.h16
-rw-r--r--include/salticidae/msg.h8
-rw-r--r--src/event.cpp24
-rw-r--r--src/msg.cpp8
4 files changed, 52 insertions, 4 deletions
diff --git a/include/salticidae/event.h b/include/salticidae/event.h
index a7ea209..9b8bea1 100644
--- a/include/salticidae/event.h
+++ b/include/salticidae/event.h
@@ -733,16 +733,21 @@ using threadcall_t = salticidae::ThreadCall;
using threadcall_handle_t = salticidae::ThreadCall::Handle;
using sigev_t = salticidae::SigEvent;
using timerev_t = salticidae::TimerEvent;
+using mpscqueue_t = salticidae::MPSCQueueEventDriven<void *>;
#endif
#else
+
+#include <stdbool.h>
#include "config.h"
+
#ifdef SALTICIDAE_CBINDINGS
typedef struct eventcontext_t eventcontext_t;
typedef struct threadcall_t threadcall_t;
typedef struct threadcall_handle_t threadcall_handle_t;
typedef struct sigev_t sigev_t;
typedef struct timerev_t timerev_t;
+typedef struct mpscqueue_t mpscqueue_t;
#endif
#endif
@@ -771,7 +776,7 @@ void sigev_del(sigev_t *self);
void sigev_clear(sigev_t *self);
const eventcontext_t *sigev_get_ec(const sigev_t *self);
-typedef void (*timerev_callback_t)(timerev_t *, void *);
+typedef void (*timerev_callback_t)(timerev_t *self, void *userdata);
timerev_t *timerev_new(const eventcontext_t *ec, timerev_callback_t callback, void *);
void timerev_set_callback(timerev_t *self, timerev_callback_t callback, void *);
void timerev_free(timerev_t *self);
@@ -780,6 +785,15 @@ void timerev_del(timerev_t *self);
void timerev_clear(timerev_t *self);
const eventcontext_t *timerev_get_ec(const timerev_t *self);
+typedef bool (*mpscqueue_callback_t)(mpscqueue_t *self, void *userdata);
+mpscqueue_t *mpscqueue_new();
+void mpscqueue_free(mpscqueue_t *self);
+void mpscqueue_reg_handler(mpscqueue_t *self, const eventcontext_t *ec, mpscqueue_callback_t callback, void *);
+void mpscqueue_unreg_handler(mpscqueue_t *self);
+bool mpscqueue_enqueue(mpscqueue_t *self, void *elem, bool unbounded);
+bool mpscqueue_try_dequeue(mpscqueue_t *self, void **elem);
+void mpscqueue_set_capacity(mpscqueue_t *self, size_t cap);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/salticidae/msg.h b/include/salticidae/msg.h
index 2f597fc..670d942 100644
--- a/include/salticidae/msg.h
+++ b/include/salticidae/msg.h
@@ -154,8 +154,14 @@ class MsgBase {
size_t get_length() const { return length; }
+ uint32_t get_magic() const { return magic; }
+
const opcode_t &get_opcode() const { return opcode; }
+ void set_magic(uint32_t _magic) {
+ magic = _magic;
+ }
+
void set_opcode(const opcode_t &_opcode) {
opcode = _opcode;
}
@@ -289,6 +295,8 @@ msg_t *msg_new_moved_from_bytearray(_opcode_t opcode, bytearray_t *_moved_payloa
void msg_free(msg_t *msg);
datastream_t *msg_consume_payload(const msg_t *msg);
_opcode_t msg_get_opcode(const msg_t *msg);
+uint32_t msg_get_magic(const msg_t *msg);
+void msg_set_magic(msg_t *msg, uint32_t magic);
#ifdef __cplusplus
}
diff --git a/src/event.cpp b/src/event.cpp
index 2fe2861..18aca18 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -69,6 +69,30 @@ void timerev_del(timerev_t *self) { self->del(); }
void timerev_clear(timerev_t *self) { self->clear(); }
+mpscqueue_t *mpscqueue_new() { return new mpscqueue_t(); }
+
+void mpscqueue_free(mpscqueue_t *self) { delete self; }
+
+void mpscqueue_reg_handler(mpscqueue_t *self, const eventcontext_t *ec, mpscqueue_callback_t callback, void *userdata) {
+ self->reg_handler(*ec, [=](mpscqueue_t &q) {
+ return callback(&q, userdata);
+ });
+}
+
+void mpscqueue_unreg_handler(mpscqueue_t *self) { self->unreg_handler(); }
+
+bool mpscqueue_enqueue(mpscqueue_t *self, void *elem, bool unbounded) {
+ return self->enqueue(elem, unbounded);
+}
+
+bool mpscqueue_try_dequeue(mpscqueue_t *self, void **elem) {
+ return self->try_dequeue(*elem);
+}
+
+void mpscqueue_set_capacity(mpscqueue_t *self, size_t cap) {
+ self->set_capacity(cap);
+}
+
}
#endif
diff --git a/src/msg.cpp b/src/msg.cpp
index be5b4b1..7ad0629 100644
--- a/src/msg.cpp
+++ b/src/msg.cpp
@@ -14,9 +14,11 @@ datastream_t *msg_consume_payload(const msg_t *msg) {
return new datastream_t(msg->get_payload());
}
-_opcode_t msg_get_opcode(const msg_t *msg) {
- return msg->get_opcode();
-}
+_opcode_t msg_get_opcode(const msg_t *self) { return self->get_opcode(); }
+
+uint32_t msg_get_magic(const msg_t *self) { return self->get_magic(); }
+
+void msg_set_magic(msg_t *self, uint32_t magic) { return self->set_magic(magic); }
}