summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLubos Dolezel <lubos@dolezel.info>2015-07-07 21:20:20 +0200
committerLubos Dolezel <lubos@dolezel.info>2015-07-07 21:20:20 +0200
commit415aa345125e48f5be1ee47296b00e49a587f2ae (patch)
tree1751df83ab6030a5bd787bf406c83d5940e05435 /src
parentdb51799e5b64e406bb83576ad609075142c26a86 (diff)
downloadtwinkle-415aa345125e48f5be1ee47296b00e49a587f2ae.tar
twinkle-415aa345125e48f5be1ee47296b00e49a587f2ae.tar.gz
twinkle-415aa345125e48f5be1ee47296b00e49a587f2ae.tar.lz
twinkle-415aa345125e48f5be1ee47296b00e49a587f2ae.tar.xz
twinkle-415aa345125e48f5be1ee47296b00e49a587f2ae.zip
Support function calls on event queues (useful for #17)
Diffstat (limited to 'src')
-rw-r--r--src/events.cpp22
-rw-r--r--src/events.h12
-rw-r--r--src/userintf.cpp3
3 files changed, 37 insertions, 0 deletions
diff --git a/src/events.cpp b/src/events.cpp
index 45c4f1d..a034d4d 100644
--- a/src/events.cpp
+++ b/src/events.cpp
@@ -506,6 +506,22 @@ unsigned short t_event_tcp_ping::get_dst_port(void) const {
}
///////////////////////////////////////////////////////////
+// class t_event_fncall
+///////////////////////////////////////////////////////////
+
+t_event_fncall::t_event_fncall(std::function<void()> fn)
+ : m_fn(fn) {
+
+}
+void t_event_fncall::invoke() {
+ m_fn();
+}
+
+t_event_type t_event_fncall::get_type(void) const {
+ return EV_FN_CALL;
+}
+
+///////////////////////////////////////////////////////////
// class t_event_queue
///////////////////////////////////////////////////////////
@@ -545,6 +561,12 @@ void t_event_queue::push_quit(void) {
push(event);
}
+void t_event_queue::push_fncall(std::function<void()> fn) {
+ t_event_fncall* event = new t_event_fncall(fn);
+ MEMMAN_NEW(event);
+ push(event);
+}
+
void t_event_queue::push_network(t_sip_message *m, const t_ip_port &ip_port) {
t_event_network *event = new t_event_network(m);
MEMMAN_NEW(event);
diff --git a/src/events.h b/src/events.h
index c13e9c0..460ae95 100644
--- a/src/events.h
+++ b/src/events.h
@@ -58,6 +58,7 @@ enum t_event_type {
EV_ASYNC_RESPONSE, /**< Response on an asynchronous question */
EV_BROKEN_CONNECTION, /**< Persitent connection to SIP proxy broken */
EV_TCP_PING, /**< Send a TCP ping (double CRLF) */
+ EV_FN_CALL, /**< Queued function call */
};
/** Abstract parent class for all events */
@@ -627,6 +628,14 @@ public:
//@}
};
+class t_event_fncall : public t_event {
+public:
+ t_event_fncall(std::function<void()> fn);
+ void invoke();
+ virtual t_event_type get_type(void) const override;
+private:
+ std::function<void()> m_fn;
+};
/**
* Event queue.
@@ -663,6 +672,9 @@ public:
/** Push a quit event into the queue. */
void push_quit(void);
+ /** Push a queued function call */
+ void push_fncall(std::function<void()> fn);
+
/**
* Create a network event and push it into the queue.
* @param m [in] SIP message.
diff --git a/src/userintf.cpp b/src/userintf.cpp
index 71ca14a..bbd7fe6 100644
--- a/src/userintf.cpp
+++ b/src/userintf.cpp
@@ -2242,6 +2242,9 @@ void t_userintf::process_events(void) {
case EV_QUIT:
quit = true;
break;
+ case EV_FN_CALL:
+ static_cast<t_event_fncall*>(event)->invoke();
+ break;
default:
assert(false);
break;