Browse code

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.

Alex Hermann authored on 26/08/2014 14:23:21
Showing 4 changed files
... ...
@@ -51,6 +51,7 @@ int dlg_dmq_initialize()
51 51
 	}
52 52
 
53 53
 	not_peer.callback = dlg_dmq_handle_msg;
54
+	not_peer.init_callback = NULL;
54 55
 	not_peer.description.s = "dialog";
55 56
 	not_peer.description.len = 6;
56 57
 	not_peer.peer_id.s = "dialog";
... ...
@@ -36,6 +36,7 @@ int add_notification_peer()
36 36
 {
37 37
 	dmq_peer_t not_peer;
38 38
 	not_peer.callback = dmq_notification_callback;
39
+	not_peer.init_callback = NULL;
39 40
 	not_peer.description.s = "notification_peer";
40 41
 	not_peer.description.len = 17;
41 42
 	not_peer.peer_id.s = "notification_peer";
... ...
@@ -165,11 +166,27 @@ error:
165 166
 	return -1;
166 167
 }
167 168
 
169
+
170
+int run_init_callbacks() {
171
+	dmq_peer_t* crt;
172
+
173
+	crt = peer_list->peers;
174
+	while(crt) {
175
+		if (crt->init_callback) {
176
+			crt->init_callback();
177
+		}
178
+		crt = crt->next;
179
+	}
180
+	return 0;
181
+}
182
+
183
+
168 184
 /**
169 185
  * @brief dmq notification callback
170 186
  */
171 187
 int dmq_notification_callback(struct sip_msg* msg, peer_reponse_t* resp)
172 188
 {
189
+	static int firstrun = 1;
173 190
 	int nodes_recv;
174 191
 	str* response_body = NULL;
175 192
 	int maxforwards = 0;
... ...
@@ -206,6 +223,10 @@ int dmq_notification_callback(struct sip_msg* msg, peer_reponse_t* resp)
206 223
 				&notification_callback, maxforwards, &notification_content_type);
207 224
 	}
208 225
 	pkg_free(response_body);
226
+	if (firstrun) {
227
+		run_init_callbacks();
228
+		firstrun = 0;
229
+	}
209 230
 	return 0;
210 231
 error:
211 232
 	return -1;
... ...
@@ -42,11 +42,13 @@ typedef struct peer_response {
42 42
 } peer_reponse_t;
43 43
 
44 44
 typedef int(*peer_callback_t)(struct sip_msg*, peer_reponse_t* resp);
45
+typedef int(*init_callback_t)();
45 46
 
46 47
 typedef struct dmq_peer {
47 48
 	str peer_id;
48 49
 	str description;
49 50
 	peer_callback_t callback;
51
+	init_callback_t init_callback;
50 52
 	struct dmq_peer* next;
51 53
 } dmq_peer_t;
52 54
 
... ...
@@ -59,6 +59,7 @@ int ht_dmq_initialize()
59 59
         }
60 60
 
61 61
 	not_peer.callback = ht_dmq_handle_msg;
62
+	not_peer.init_callback = NULL;
62 63
 	not_peer.description.s = "htable";
63 64
 	not_peer.description.len = 6;
64 65
 	not_peer.peer_id.s = "htable";