Module: sip-router Branch: alexh/dialog-sync-wip Commit: 6ceddd9bf832220b05684ff439eb085b8daff240 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6ceddd9b...
Author: Alex Hermann alex@speakup.nl Committer: Alex Hermann alex@speakup.nl Date: Tue Aug 26 16:23:21 2014 +0200
dmq: Add init_callback() to API
The init_callback is called after DMQ has synced with the notification_peer. This callback can thus be used to send/broadcast messages as early as possible.
---
modules/dialog/dlg_dmq.c | 1 + modules/dmq/notification_peer.c | 21 +++++++++++++++++++++ modules/dmq/peer.h | 2 ++ modules/htable/ht_dmq.c | 1 + 4 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/modules/dialog/dlg_dmq.c b/modules/dialog/dlg_dmq.c index 2b11453..f659a70 100644 --- a/modules/dialog/dlg_dmq.c +++ b/modules/dialog/dlg_dmq.c @@ -51,6 +51,7 @@ int dlg_dmq_initialize() }
not_peer.callback = dlg_dmq_handle_msg; + not_peer.init_callback = NULL; not_peer.description.s = "dialog"; not_peer.description.len = 6; not_peer.peer_id.s = "dialog"; diff --git a/modules/dmq/notification_peer.c b/modules/dmq/notification_peer.c index 2f459e1..e7704f0 100644 --- a/modules/dmq/notification_peer.c +++ b/modules/dmq/notification_peer.c @@ -36,6 +36,7 @@ int add_notification_peer() { dmq_peer_t not_peer; not_peer.callback = dmq_notification_callback; + not_peer.init_callback = NULL; not_peer.description.s = "notification_peer"; not_peer.description.len = 17; not_peer.peer_id.s = "notification_peer"; @@ -165,11 +166,27 @@ error: return -1; }
+ +int run_init_callbacks() { + dmq_peer_t* crt; + + crt = peer_list->peers; + while(crt) { + if (crt->init_callback) { + crt->init_callback(); + } + crt = crt->next; + } + return 0; +} + + /** * @brief dmq notification callback */ int dmq_notification_callback(struct sip_msg* msg, peer_reponse_t* resp) { + static int firstrun = 1; int nodes_recv; str* response_body = NULL; int maxforwards = 0; @@ -206,6 +223,10 @@ int dmq_notification_callback(struct sip_msg* msg, peer_reponse_t* resp) ¬ification_callback, maxforwards, ¬ification_content_type); } pkg_free(response_body); + if (firstrun) { + run_init_callbacks(); + firstrun = 0; + } return 0; error: return -1; diff --git a/modules/dmq/peer.h b/modules/dmq/peer.h index 7ce4434..bd1a15d 100644 --- a/modules/dmq/peer.h +++ b/modules/dmq/peer.h @@ -42,11 +42,13 @@ typedef struct peer_response { } peer_reponse_t;
typedef int(*peer_callback_t)(struct sip_msg*, peer_reponse_t* resp); +typedef int(*init_callback_t)();
typedef struct dmq_peer { str peer_id; str description; peer_callback_t callback; + init_callback_t init_callback; struct dmq_peer* next; } dmq_peer_t;
diff --git a/modules/htable/ht_dmq.c b/modules/htable/ht_dmq.c index 284c3dc..21755a7 100644 --- a/modules/htable/ht_dmq.c +++ b/modules/htable/ht_dmq.c @@ -59,6 +59,7 @@ int ht_dmq_initialize() }
not_peer.callback = ht_dmq_handle_msg; + not_peer.init_callback = NULL; not_peer.description.s = "htable"; not_peer.description.len = 6; not_peer.peer_id.s = "htable";