summaryrefslogtreecommitdiff
path: root/src/examples/eldbus
diff options
context:
space:
mode:
authorJosé Roberto de Souza <jose.souza@intel.com>2013-07-05 14:45:48 -0300
committerJosé Roberto de Souza <jose.souza@intel.com>2013-07-05 16:08:01 -0300
commit20d9e486a8c20c9cc3f00d4c7627a0fd4a36885f (patch)
tree449e394917b2f427bc272349351ac7bb13a5cec9 /src/examples/eldbus
parentdadf38cb2f9c40df33ad004adc6549f036df7a81 (diff)
eldbus: Handle removal of last reference of connection inside of callback
Diffstat (limited to 'src/examples/eldbus')
-rw-r--r--src/examples/eldbus/client.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/examples/eldbus/client.c b/src/examples/eldbus/client.c
index 18a1fcd..fe8391f 100644
--- a/src/examples/eldbus/client.c
+++ b/src/examples/eldbus/client.c
@@ -12,6 +12,9 @@
12static int _client_log_dom = -1; 12static int _client_log_dom = -1;
13#define ERR(...) EINA_LOG_DOM_ERR(_client_log_dom, __VA_ARGS__) 13#define ERR(...) EINA_LOG_DOM_ERR(_client_log_dom, __VA_ARGS__)
14 14
15static Eldbus_Connection *conn = NULL;
16static Ecore_Timer *timeout = NULL;
17
15static void 18static void
16_on_alive(void *context EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED) 19_on_alive(void *context EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED)
17{ 20{
@@ -53,7 +56,12 @@ test(void)
53 static int n = 0; 56 static int n = 0;
54 n++; 57 n++;
55 if (n >= NTESTS) 58 if (n >= NTESTS)
56 printf("Passed in all tests\n"); 59 {
60 printf("Passed in all tests\nExiting...\n");
61 eldbus_connection_unref(conn);
62 conn = NULL;
63 ecore_main_loop_quit();
64 }
57 else 65 else
58 printf("Passed in %d/%d tests\n", n, NTESTS); 66 printf("Passed in %d/%d tests\n", n, NTESTS);
59} 67}
@@ -270,14 +278,15 @@ on_name_owner_changed(void *data EINA_UNUSED, const char *bus, const char *old_i
270static Eina_Bool 278static Eina_Bool
271finish(void *data EINA_UNUSED) 279finish(void *data EINA_UNUSED)
272{ 280{
281 ERR("Timeout\nSome error happened or server is taking too much time to respond.");
273 ecore_main_loop_quit(); 282 ecore_main_loop_quit();
283 timeout = NULL;
274 return ECORE_CALLBACK_CANCEL; 284 return ECORE_CALLBACK_CANCEL;
275} 285}
276 286
277int 287int
278main(void) 288main(void)
279{ 289{
280 Eldbus_Connection *conn;
281 Eldbus_Object *obj; 290 Eldbus_Object *obj;
282 Eldbus_Proxy *proxy; 291 Eldbus_Proxy *proxy;
283 292
@@ -317,11 +326,14 @@ main(void)
317 326
318 eldbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed, 327 eldbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed,
319 conn, EINA_TRUE); 328 conn, EINA_TRUE);
320 ecore_timer_add(30, finish, NULL); 329 timeout = ecore_timer_add(30, finish, NULL);
321 330
322 ecore_main_loop_begin(); 331 ecore_main_loop_begin();
323 332
324 eldbus_connection_unref(conn); 333 if (timeout)
334 ecore_timer_del(timeout);
335 if (conn)
336 eldbus_connection_unref(conn);
325 337
326 eldbus_shutdown(); 338 eldbus_shutdown();
327 ecore_shutdown(); 339 ecore_shutdown();