summaryrefslogtreecommitdiff
path: root/legacy/edbus
diff options
context:
space:
mode:
authorJosé Roberto de Souza <zehortigoza@profusion.mobi>2012-10-02 21:41:53 +0000
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2012-10-02 21:41:53 +0000
commitc2e818bd3ff8ee02b94cec4dfb4b45f8853934b5 (patch)
treeb17bc33d5a259799dc22b67ca2e0687809f63c35 /legacy/edbus
parent4be3f1e204af476568431dbe4d7f3a223c2c5acf (diff)
edbus: Call callback if already have a unique id when
another callback is added Patch by: José Roberto de Souza <zehortigoza@profusion.mobi> SVN revision: 77337
Diffstat (limited to 'legacy/edbus')
-rw-r--r--legacy/edbus/src/examples/client.c27
-rw-r--r--legacy/edbus/src/lib/edbus_core.c33
2 files changed, 60 insertions, 0 deletions
diff --git a/legacy/edbus/src/examples/client.c b/legacy/edbus/src/examples/client.c
index 80ae728e72..f48dab8550 100644
--- a/legacy/edbus/src/examples/client.c
+++ b/legacy/edbus/src/examples/client.c
@@ -218,6 +218,27 @@ _on_async_test(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
218 printf("%s\n", str); 218 printf("%s\n", str);
219} 219}
220 220
221static void
222on_name_owner_changed2(void *data, const char *bus, const char *old_id, const char *new_id)
223{
224 printf("2 - Bus=%s | old=%s | new=%s\n", bus, old_id, new_id);
225}
226
227static void
228on_name_owner_changed(void *data, const char *bus, const char *old_id, const char *new_id)
229{
230 printf("Bus=%s | old=%s | new=%s\n", bus, old_id, new_id);
231}
232
233static Eina_Bool
234add_name_owner2(void *data)
235{
236 EDBus_Connection *conn = data;
237 edbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed2,
238 NULL);
239 return EINA_FALSE;
240}
241
221int 242int
222main(void) 243main(void)
223{ 244{
@@ -245,8 +266,14 @@ main(void)
245 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);
246 edbus_proxy_call(proxy, "AsyncTest", _on_async_test, NULL, -1, ""); 267 edbus_proxy_call(proxy, "AsyncTest", _on_async_test, NULL, -1, "");
247 268
269 edbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed, conn);
270 ecore_timer_add(3, add_name_owner2, conn);
271
248 ecore_main_loop_begin(); 272 ecore_main_loop_begin();
249 273
274 edbus_name_owner_changed_callback_del(conn, BUS, on_name_owner_changed, conn);
275 edbus_name_owner_changed_callback_del(conn, BUS, on_name_owner_changed2,
276 NULL);
250 edbus_connection_unref(conn); 277 edbus_connection_unref(conn);
251 278
252 edbus_shutdown(); 279 edbus_shutdown();
diff --git a/legacy/edbus/src/lib/edbus_core.c b/legacy/edbus/src/lib/edbus_core.c
index 4fec737dbd..ced7c99d37 100644
--- a/legacy/edbus/src/lib/edbus_core.c
+++ b/legacy/edbus/src/lib/edbus_core.c
@@ -48,6 +48,7 @@ typedef struct _EDBus_Connection_Context_NOC_Cb
48 EDBus_Name_Owner_Changed_Cb cb; 48 EDBus_Name_Owner_Changed_Cb 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} EDBus_Connection_Context_NOC_Cb; 52} EDBus_Connection_Context_NOC_Cb;
52 53
53typedef struct _EDBus_Handler_Data 54typedef struct _EDBus_Handler_Data
@@ -1165,6 +1166,23 @@ edbus_dispatch_name_owner_change(EDBus_Connection_Name *cn, const char *old_id)
1165 cn->event_handlers.walking--; 1166 cn->event_handlers.walking--;
1166} 1167}
1167 1168
1169typedef struct _dispach_name_owner_data
1170{
1171 EDBus_Connection_Context_NOC_Cb *ctx;
1172 const EDBus_Connection_Name *cn;
1173} dispatch_name_owner_data;
1174
1175static Eina_Bool
1176dispach_name_owner_cb(void *context)
1177{
1178 dispatch_name_owner_data *data = context;
1179 data->ctx->cb((void *)data->ctx->cb_data, data->cn->name, "",
1180 data->cn->unique_id);
1181 data->ctx->idler = NULL;
1182 free(data);
1183 return ECORE_CALLBACK_CANCEL;
1184}
1185
1168EAPI void 1186EAPI void
1169edbus_name_owner_changed_callback_add(EDBus_Connection *conn, const char *bus, EDBus_Name_Owner_Changed_Cb cb, const void *cb_data) 1187edbus_name_owner_changed_callback_add(EDBus_Connection *conn, const char *bus, EDBus_Name_Owner_Changed_Cb cb, const void *cb_data)
1170{ 1188{
@@ -1194,6 +1212,15 @@ edbus_name_owner_changed_callback_add(EDBus_Connection *conn, const char *bus, E
1194 1212
1195 cn->event_handlers.list = eina_inlist_append(cn->event_handlers.list, 1213 cn->event_handlers.list = eina_inlist_append(cn->event_handlers.list,
1196 EINA_INLIST_GET(ctx)); 1214 EINA_INLIST_GET(ctx));
1215 if (cn->unique_id)
1216 {
1217 dispatch_name_owner_data *dispatch_data;
1218 dispatch_data = malloc(sizeof(dispatch_name_owner_data));
1219 EINA_SAFETY_ON_NULL_RETURN(dispatch_data);
1220 dispatch_data->cn = cn;
1221 dispatch_data->ctx = ctx;
1222 ctx->idler = ecore_idler_add(dispach_name_owner_cb, dispatch_data);
1223 }
1197 return; 1224 return;
1198 1225
1199cleanup: 1226cleanup:
@@ -1235,6 +1262,12 @@ edbus_name_owner_changed_callback_del(EDBus_Connection *conn, const char *bus, E
1235 1262
1236 cn->event_handlers.list = eina_inlist_remove(cn->event_handlers.list, 1263 cn->event_handlers.list = eina_inlist_remove(cn->event_handlers.list,
1237 EINA_INLIST_GET(found)); 1264 EINA_INLIST_GET(found));
1265 if (found->idler)
1266 {
1267 dispatch_name_owner_data *data;
1268 data = ecore_idler_del(found->idler);
1269 free(data);
1270 }
1238 free(found); 1271 free(found);
1239 edbus_connection_name_owner_monitor(conn, cn, EINA_FALSE); 1272 edbus_connection_name_owner_monitor(conn, cn, EINA_FALSE);
1240} 1273}