summaryrefslogtreecommitdiff
path: root/legacy/edbus
diff options
context:
space:
mode:
authorJosé Roberto de Souza <zehortigoza@profusion.mobi>2012-10-02 21:41:58 +0000
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2012-10-02 21:41:58 +0000
commitde5d201e7e12a5e4413f1ba6e74afda30f30035a (patch)
tree929754080f25dc4a0924ef5619503bbc8ae8da3e /legacy/edbus
parentc2e818bd3ff8ee02b94cec4dfb4b45f8853934b5 (diff)
edbus: Add flag to name_owner_changed_callback_add to
allow initial call Patch by: José Roberto de Souza <zehortigoza@profusion.mobi> SVN revision: 77338
Diffstat (limited to 'legacy/edbus')
-rw-r--r--legacy/edbus/src/examples/client.c5
-rw-r--r--legacy/edbus/src/lib/edbus_core.c13
-rw-r--r--legacy/edbus/src/lib/edbus_freedesktop.h19
3 files changed, 30 insertions, 7 deletions
diff --git a/legacy/edbus/src/examples/client.c b/legacy/edbus/src/examples/client.c
index f48dab8550..58a8c9562d 100644
--- a/legacy/edbus/src/examples/client.c
+++ b/legacy/edbus/src/examples/client.c
@@ -235,7 +235,7 @@ add_name_owner2(void *data)
235{ 235{
236 EDBus_Connection *conn = data; 236 EDBus_Connection *conn = data;
237 edbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed2, 237 edbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed2,
238 NULL); 238 NULL, EINA_TRUE);
239 return EINA_FALSE; 239 return EINA_FALSE;
240} 240}
241 241
@@ -266,7 +266,8 @@ main(void)
266 edbus_proxy_call(proxy, "SendString", _on_send_string, NULL, -1, "s", string_value); 266 edbus_proxy_call(proxy, "SendString", _on_send_string, NULL, -1, "s", string_value);
267 edbus_proxy_call(proxy, "AsyncTest", _on_async_test, NULL, -1, ""); 267 edbus_proxy_call(proxy, "AsyncTest", _on_async_test, NULL, -1, "");
268 268
269 edbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed, conn); 269 edbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed,
270 conn, EINA_TRUE);
270 ecore_timer_add(3, add_name_owner2, conn); 271 ecore_timer_add(3, add_name_owner2, conn);
271 272
272 ecore_main_loop_begin(); 273 ecore_main_loop_begin();
diff --git a/legacy/edbus/src/lib/edbus_core.c b/legacy/edbus/src/lib/edbus_core.c
index ced7c99d37..66f5c47283 100644
--- a/legacy/edbus/src/lib/edbus_core.c
+++ b/legacy/edbus/src/lib/edbus_core.c
@@ -49,6 +49,7 @@ typedef struct _EDBus_Connection_Context_NOC_Cb
49 const void *cb_data; 49 const void *cb_data;
50 Eina_Bool deleted : 1; 50 Eina_Bool deleted : 1;
51 Ecore_Idler *idler; 51 Ecore_Idler *idler;
52 Eina_Bool allow_initial : 1;
52} EDBus_Connection_Context_NOC_Cb; 53} EDBus_Connection_Context_NOC_Cb;
53 54
54typedef struct _EDBus_Handler_Data 55typedef struct _EDBus_Handler_Data
@@ -499,7 +500,7 @@ on_get_name_owner(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
499 ERR("Error getting arguments from GetNameOwner"); 500 ERR("Error getting arguments from GetNameOwner");
500 501
501 cn->unique_id = eina_stringshare_add(unique_id); 502 cn->unique_id = eina_stringshare_add(unique_id);
502 edbus_dispatch_name_owner_change(cn, ""); 503 edbus_dispatch_name_owner_change(cn, NULL);
503} 504}
504 505
505static void 506static void
@@ -1157,11 +1158,14 @@ static void
1157edbus_dispatch_name_owner_change(EDBus_Connection_Name *cn, const char *old_id) 1158edbus_dispatch_name_owner_change(EDBus_Connection_Name *cn, const char *old_id)
1158{ 1159{
1159 EDBus_Connection_Context_NOC_Cb *ctx; 1160 EDBus_Connection_Context_NOC_Cb *ctx;
1161 const char *previous_id = !old_id ? "" : old_id;
1160 cn->event_handlers.walking++; 1162 cn->event_handlers.walking++;
1161 EINA_INLIST_FOREACH(cn->event_handlers.list, ctx) 1163 EINA_INLIST_FOREACH(cn->event_handlers.list, ctx)
1162 { 1164 {
1163 if (ctx->deleted) continue; 1165 if (ctx->deleted) continue;
1164 ctx->cb((void *)ctx->cb_data, cn->name, old_id, cn->unique_id); 1166 if (!old_id && !ctx->allow_initial)
1167 continue;
1168 ctx->cb((void *)ctx->cb_data, cn->name, previous_id, cn->unique_id);
1165 } 1169 }
1166 cn->event_handlers.walking--; 1170 cn->event_handlers.walking--;
1167} 1171}
@@ -1184,7 +1188,7 @@ dispach_name_owner_cb(void *context)
1184} 1188}
1185 1189
1186EAPI void 1190EAPI void
1187edbus_name_owner_changed_callback_add(EDBus_Connection *conn, const char *bus, EDBus_Name_Owner_Changed_Cb cb, const void *cb_data) 1191edbus_name_owner_changed_callback_add(EDBus_Connection *conn, const char *bus, EDBus_Name_Owner_Changed_Cb cb, const void *cb_data, Eina_Bool allow_initial_call)
1188{ 1192{
1189 EDBus_Connection_Name *cn; 1193 EDBus_Connection_Name *cn;
1190 EDBus_Connection_Context_NOC_Cb *ctx; 1194 EDBus_Connection_Context_NOC_Cb *ctx;
@@ -1209,10 +1213,11 @@ edbus_name_owner_changed_callback_add(EDBus_Connection *conn, const char *bus, E
1209 EINA_SAFETY_ON_NULL_GOTO(ctx, cleanup); 1213 EINA_SAFETY_ON_NULL_GOTO(ctx, cleanup);
1210 ctx->cb = cb; 1214 ctx->cb = cb;
1211 ctx->cb_data = cb_data; 1215 ctx->cb_data = cb_data;
1216 ctx->allow_initial = allow_initial_call;
1212 1217
1213 cn->event_handlers.list = eina_inlist_append(cn->event_handlers.list, 1218 cn->event_handlers.list = eina_inlist_append(cn->event_handlers.list,
1214 EINA_INLIST_GET(ctx)); 1219 EINA_INLIST_GET(ctx));
1215 if (cn->unique_id) 1220 if (cn->unique_id && allow_initial_call)
1216 { 1221 {
1217 dispatch_name_owner_data *dispatch_data; 1222 dispatch_name_owner_data *dispatch_data;
1218 dispatch_data = malloc(sizeof(dispatch_name_owner_data)); 1223 dispatch_data = malloc(sizeof(dispatch_name_owner_data));
diff --git a/legacy/edbus/src/lib/edbus_freedesktop.h b/legacy/edbus/src/lib/edbus_freedesktop.h
index 1bdfddd277..639fc9a4af 100644
--- a/legacy/edbus/src/lib/edbus_freedesktop.h
+++ b/legacy/edbus/src/lib/edbus_freedesktop.h
@@ -37,7 +37,24 @@ EAPI EDBus_Pending *edbus_name_start(EDBus_Connection *conn, const char *
37 37
38typedef void (*EDBus_Name_Owner_Changed_Cb)(void *data, const char *bus, const char *old_id, const char *new_id); 38typedef void (*EDBus_Name_Owner_Changed_Cb)(void *data, const char *bus, const char *old_id, const char *new_id);
39 39
40EAPI void edbus_name_owner_changed_callback_add(EDBus_Connection *conn, const char *bus, EDBus_Name_Owner_Changed_Cb cb, const void *cb_data); 40/**
41 * Add a callback to be called when unique id of a bus name changed.
42 *
43 * @param conn connection
44 * @param bus name of bus
45 * @param cb callback
46 * @param cb_data context data
47 * @param allow_initial_call allow call callback with actual id of the bus
48 */
49EAPI void edbus_name_owner_changed_callback_add(EDBus_Connection *conn, const char *bus, EDBus_Name_Owner_Changed_Cb cb, const void *cb_data, Eina_Bool allow_initial_call);
50/**
51 * Remove callback added with edbus_name_owner_changed_callback_add().
52 *
53 * @param conn connection
54 * @param bus name of bus
55 * @param cb callback
56 * @param cb_data context data
57 */
41EAPI void edbus_name_owner_changed_callback_del(EDBus_Connection *conn, const char *bus, EDBus_Name_Owner_Changed_Cb cb, const void *cb_data); 58EAPI void edbus_name_owner_changed_callback_del(EDBus_Connection *conn, const char *bus, EDBus_Name_Owner_Changed_Cb cb, const void *cb_data);
42 59
43/** 60/**