summaryrefslogtreecommitdiff
path: root/efl/dbus_mainloop
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2013-04-06 20:46:20 +0200
committerdavemds <dave@gurumeditation.it>2013-04-06 20:46:20 +0200
commit51b1cadd931416a87af8cce6bb63496cb1f9f630 (patch)
tree2ea16347b684963885984eaf8fc2945b26feee95 /efl/dbus_mainloop
parentb6eb161da26f552a1063df118134942cc78d1302 (diff)
Python-EFL: use eina_log in dbus_mainloop
Diffstat (limited to 'efl/dbus_mainloop')
-rw-r--r--efl/dbus_mainloop/e_dbus.c95
1 files changed, 57 insertions, 38 deletions
diff --git a/efl/dbus_mainloop/e_dbus.c b/efl/dbus_mainloop/e_dbus.c
index a45f00c..7a9cacb 100644
--- a/efl/dbus_mainloop/e_dbus.c
+++ b/efl/dbus_mainloop/e_dbus.c
@@ -21,6 +21,15 @@
21#include "e_dbus.h" 21#include "e_dbus.h"
22 22
23 23
24#ifndef E_DBUS_COLOR_DEFAULT
25#define E_DBUS_COLOR_DEFAULT EINA_COLOR_CYAN
26#endif
27static int _e_dbus_log_dom = -1;
28#define DBG(...) EINA_LOG_DOM_DBG(_e_dbus_log_dom, __VA_ARGS__)
29#define INFO(...) EINA_LOG_DOM_INFO(_e_dbus_log_dom, __VA_ARGS__)
30#define WARN(...) EINA_LOG_DOM_WARN(_e_dbus_log_dom, __VA_ARGS__)
31#define ERR(...) EINA_LOG_DOM_ERR(_e_dbus_log_dom, __VA_ARGS__)
32
24int E_DBUS_EVENT_SIGNAL = 0; 33int E_DBUS_EVENT_SIGNAL = 0;
25static int connection_slot = -1; 34static int connection_slot = -1;
26static int e_dbus_idler_active = 0; 35static int e_dbus_idler_active = 0;
@@ -33,7 +42,7 @@ e_dbus_fd_handler_del(E_DBus_Handler_Data *hd)
33{ 42{
34 if (!hd->fd_handler) return; 43 if (!hd->fd_handler) return;
35 44
36 printf("handler disabled\n"); 45 DBG("handler disabled");
37 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler); 46 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler);
38 ecore_main_fd_handler_del(hd->fd_handler); 47 ecore_main_fd_handler_del(hd->fd_handler);
39 hd->fd_handler = NULL; 48 hd->fd_handler = NULL;
@@ -45,7 +54,7 @@ e_dbus_fd_handler(void *data, Ecore_Fd_Handler *fd_handler)
45 E_DBus_Handler_Data *hd; 54 E_DBus_Handler_Data *hd;
46 unsigned int condition = 0; 55 unsigned int condition = 0;
47 56
48 printf("fd handler (%p)!\n", fd_handler); 57 DBG("fd handler (%p)!", fd_handler);
49 58
50 hd = data; 59 hd = data;
51 60
@@ -57,11 +66,11 @@ e_dbus_fd_handler(void *data, Ecore_Fd_Handler *fd_handler)
57 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) condition |= DBUS_WATCH_READABLE; 66 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) condition |= DBUS_WATCH_READABLE;
58 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE)) condition |= DBUS_WATCH_WRITABLE; 67 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE)) condition |= DBUS_WATCH_WRITABLE;
59 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) condition |= DBUS_WATCH_ERROR; 68 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) condition |= DBUS_WATCH_ERROR;
60 printf("fdh || READ: %d, WRITE: %d\n", 69 DBG("fdh || READ: %d, WRITE: %d",
61 (condition & DBUS_WATCH_READABLE) == DBUS_WATCH_READABLE, 70 (condition & DBUS_WATCH_READABLE) == DBUS_WATCH_READABLE,
62 (condition & DBUS_WATCH_WRITABLE) == DBUS_WATCH_WRITABLE); 71 (condition & DBUS_WATCH_WRITABLE) == DBUS_WATCH_WRITABLE);
63 72
64 if (condition & DBUS_WATCH_ERROR) printf("DBUS watch error\n"); 73 if (condition & DBUS_WATCH_ERROR) DBG("DBUS watch error");
65 dbus_watch_handle(hd->watch, condition); 74 dbus_watch_handle(hd->watch, condition);
66 hd = NULL; 75 hd = NULL;
67 76
@@ -87,7 +96,7 @@ e_dbus_fd_handler_add(E_DBus_Handler_Data *hd)
87 if (ecore_main_fd_handler_fd_get(fdh) == hd->fd) return; 96 if (ecore_main_fd_handler_fd_get(fdh) == hd->fd) return;
88 } 97 }
89 98
90 printf("fd handler add (%d)\n", hd->fd); 99 DBG("fd handler add (%d)", hd->fd);
91 hd->fd_handler = ecore_main_fd_handler_add(hd->fd, 100 hd->fd_handler = ecore_main_fd_handler_add(hd->fd,
92 eflags, 101 eflags,
93 e_dbus_fd_handler, 102 e_dbus_fd_handler,
@@ -102,8 +111,8 @@ static void
102e_dbus_handler_data_free(void *data) 111e_dbus_handler_data_free(void *data)
103{ 112{
104 E_DBus_Handler_Data *hd = data; 113 E_DBus_Handler_Data *hd = data;
105 114
106 printf("e_dbus_handler_data_free\n"); 115 DBG("e_dbus_handler_data_free");
107 if (hd->fd_handler) 116 if (hd->fd_handler)
108 { 117 {
109 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler); 118 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler);
@@ -128,7 +137,7 @@ e_dbus_connection_data_watch_add(E_DBus_Connection *cd, DBusWatch *watch)
128// #else 137// #else
129 // hd->fd = dbus_watch_get_fd(hd->watch); 138 // hd->fd = dbus_watch_get_fd(hd->watch);
130// #endif 139// #endif
131 printf("watch add (enabled: %d)\n", hd->enabled); 140 DBG("watch add (enabled: %d)", hd->enabled);
132 if (hd->enabled) e_dbus_fd_handler_add(hd); 141 if (hd->enabled) e_dbus_fd_handler_add(hd);
133} 142}
134 143
@@ -142,25 +151,25 @@ static DBusHandlerResult
142e_dbus_filter(DBusConnection *conn, DBusMessage *message, void *user_data) 151e_dbus_filter(DBusConnection *conn, DBusMessage *message, void *user_data)
143{ 152{
144 E_DBus_Connection *cd = user_data; 153 E_DBus_Connection *cd = user_data;
145 printf("-----------------\n"); 154 DBG("-----------------");
146 printf("Message!\n"); 155 DBG("Message!");
147 156
148 printf("type: %s\n", dbus_message_type_to_string(dbus_message_get_type(message))); 157 DBG("type: %s", dbus_message_type_to_string(dbus_message_get_type(message)));
149 printf("path: %s\n", dbus_message_get_path(message)); 158 DBG("path: %s", dbus_message_get_path(message));
150 printf("interface: %s\n", dbus_message_get_interface(message)); 159 DBG("interface: %s", dbus_message_get_interface(message));
151 printf("member: %s\n", dbus_message_get_member(message)); 160 DBG("member: %s", dbus_message_get_member(message));
152 printf("sender: %s\n", dbus_message_get_sender(message)); 161 DBG("sender: %s", dbus_message_get_sender(message));
153 162
154 switch (dbus_message_get_type(message)) 163 switch (dbus_message_get_type(message))
155 { 164 {
156 case DBUS_MESSAGE_TYPE_METHOD_CALL: 165 case DBUS_MESSAGE_TYPE_METHOD_CALL:
157 printf("signature: %s\n", dbus_message_get_signature(message)); 166 DBG("signature: %s", dbus_message_get_signature(message));
158 break; 167 break;
159 case DBUS_MESSAGE_TYPE_METHOD_RETURN: 168 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
160 printf("reply serial %d\n", dbus_message_get_reply_serial(message)); 169 DBG("reply serial %d", dbus_message_get_reply_serial(message));
161 break; 170 break;
162 case DBUS_MESSAGE_TYPE_ERROR: 171 case DBUS_MESSAGE_TYPE_ERROR:
163 printf("error: %s\n", dbus_message_get_error_name(message)); 172 DBG("error: %s", dbus_message_get_error_name(message));
164 break; 173 break;
165 case DBUS_MESSAGE_TYPE_SIGNAL: 174 case DBUS_MESSAGE_TYPE_SIGNAL:
166 dbus_message_ref(message); 175 dbus_message_ref(message);
@@ -170,7 +179,7 @@ e_dbus_filter(DBusConnection *conn, DBusMessage *message, void *user_data)
170 default: 179 default:
171 break; 180 break;
172 } 181 }
173 printf("-----------------\n"); 182 DBG("-----------------");
174 183
175 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 184 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
176} 185}
@@ -183,13 +192,13 @@ e_dbus_idler(void *data)
183 192
184 if (DBUS_DISPATCH_COMPLETE == dbus_connection_get_dispatch_status(cd->conn)) 193 if (DBUS_DISPATCH_COMPLETE == dbus_connection_get_dispatch_status(cd->conn))
185 { 194 {
186 printf("done dispatching!\n"); 195 DBG("done dispatching!");
187 cd->idler = NULL; 196 cd->idler = NULL;
188 return ECORE_CALLBACK_CANCEL; 197 return ECORE_CALLBACK_CANCEL;
189 } 198 }
190 e_dbus_idler_active++; 199 e_dbus_idler_active++;
191 dbus_connection_ref(cd->conn); 200 dbus_connection_ref(cd->conn);
192 printf("dispatch()\n"); 201 DBG("dispatch()");
193 dbus_connection_dispatch(cd->conn); 202 dbus_connection_dispatch(cd->conn);
194 dbus_connection_unref(cd->conn); 203 dbus_connection_unref(cd->conn);
195 e_dbus_idler_active--; 204 e_dbus_idler_active--;
@@ -209,7 +218,7 @@ cb_dispatch_status(DBusConnection *conn, DBusDispatchStatus new_status, void *da
209{ 218{
210 E_DBus_Connection *cd; 219 E_DBus_Connection *cd;
211 220
212 printf("dispatch status: %d!\n", new_status); 221 DBG("dispatch status: %d!", new_status);
213 cd = data; 222 cd = data;
214 223
215 if (new_status == DBUS_DISPATCH_DATA_REMAINS && !cd->idler) 224 if (new_status == DBUS_DISPATCH_DATA_REMAINS && !cd->idler)
@@ -229,7 +238,7 @@ cb_watch_add(DBusWatch *watch, void *data)
229 E_DBus_Connection *cd; 238 E_DBus_Connection *cd;
230 cd = data; 239 cd = data;
231 240
232 printf("cb_watch_add\n"); 241 DBG("cb_watch_add");
233 e_dbus_connection_data_watch_add(cd, watch); 242 e_dbus_connection_data_watch_add(cd, watch);
234 243
235 return true; 244 return true;
@@ -240,7 +249,7 @@ cb_watch_del(DBusWatch *watch, void *data)
240{ 249{
241 E_DBus_Handler_Data *hd; 250 E_DBus_Handler_Data *hd;
242 251
243 printf("cb_watch_del\n"); 252 DBG("cb_watch_del");
244 hd = (E_DBus_Handler_Data *)dbus_watch_get_data(watch); 253 hd = (E_DBus_Handler_Data *)dbus_watch_get_data(watch);
245 e_dbus_fd_handler_del(hd); 254 e_dbus_fd_handler_del(hd);
246} 255}
@@ -250,14 +259,14 @@ cb_watch_toggle(DBusWatch *watch, void *data)
250{ 259{
251 E_DBus_Handler_Data *hd; 260 E_DBus_Handler_Data *hd;
252 261
253 printf("cb_watch_toggle\n"); 262 DBG("cb_watch_toggle");
254 hd = dbus_watch_get_data(watch); 263 hd = dbus_watch_get_data(watch);
255 264
256 if (!hd) return; 265 if (!hd) return;
257 266
258 hd->enabled = dbus_watch_get_enabled(watch); 267 hd->enabled = dbus_watch_get_enabled(watch);
259 268
260 printf("watch %p is %sabled\n", hd, hd->enabled ? "en" : "dis"); 269 INFO("watch %p is %sabled", hd, hd->enabled ? "en" : "dis");
261 if (hd->enabled) e_dbus_fd_handler_add(hd); 270 if (hd->enabled) e_dbus_fd_handler_add(hd);
262 else e_dbus_fd_handler_del(hd); 271 else e_dbus_fd_handler_del(hd);
263} 272}
@@ -273,12 +282,12 @@ e_dbus_timeout_handler(void *data)
273 282
274 if (!dbus_timeout_get_enabled(td->timeout)) 283 if (!dbus_timeout_get_enabled(td->timeout))
275 { 284 {
276 printf("timeout_handler (not enabled, ending)\n"); 285 DBG("timeout_handler (not enabled, ending)");
277 td->handler = NULL; 286 td->handler = NULL;
278 return ECORE_CALLBACK_CANCEL; 287 return ECORE_CALLBACK_CANCEL;
279 } 288 }
280 289
281 printf("timeout handler!\n"); 290 DBG("timeout handler!");
282 dbus_timeout_handle(td->timeout); 291 dbus_timeout_handle(td->timeout);
283 return ECORE_CALLBACK_CANCEL; 292 return ECORE_CALLBACK_CANCEL;
284} 293}
@@ -287,7 +296,7 @@ static void
287e_dbus_timeout_data_free(void *timeout_data) 296e_dbus_timeout_data_free(void *timeout_data)
288{ 297{
289 E_DBus_Timeout_Data *td = timeout_data; 298 E_DBus_Timeout_Data *td = timeout_data;
290 printf("e_dbus_timeout_data_free\n"); 299 DBG("e_dbus_timeout_data_free");
291 if (td->handler) ecore_timer_del(td->handler); 300 if (td->handler) ecore_timer_del(td->handler);
292 free(td); 301 free(td);
293} 302}
@@ -299,7 +308,7 @@ cb_timeout_add(DBusTimeout *timeout, void *data)
299 E_DBus_Timeout_Data *td; 308 E_DBus_Timeout_Data *td;
300 309
301 cd = data; 310 cd = data;
302 printf("timeout add!\n"); 311 DBG("timeout add!");
303 td = calloc(1, sizeof(E_DBus_Timeout_Data)); 312 td = calloc(1, sizeof(E_DBus_Timeout_Data));
304 td->cd = cd; 313 td->cd = cd;
305 dbus_timeout_set_data(timeout, (void *)td, e_dbus_timeout_data_free); 314 dbus_timeout_set_data(timeout, (void *)td, e_dbus_timeout_data_free);
@@ -318,7 +327,7 @@ static void
318cb_timeout_del(DBusTimeout *timeout, void *data) 327cb_timeout_del(DBusTimeout *timeout, void *data)
319{ 328{
320 E_DBus_Timeout_Data *td; 329 E_DBus_Timeout_Data *td;
321 printf("timeout del!\n"); 330 DBG("timeout del!");
322 331
323 td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout); 332 td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout);
324 333
@@ -336,7 +345,7 @@ static void
336cb_timeout_toggle(DBusTimeout *timeout, void *data) 345cb_timeout_toggle(DBusTimeout *timeout, void *data)
337{ 346{
338 E_DBus_Timeout_Data *td; 347 E_DBus_Timeout_Data *td;
339 printf("timeout toggle!\n"); 348 DBG("timeout toggle!");
340 349
341 td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout); 350 td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout);
342 351
@@ -367,11 +376,11 @@ e_dbus_connection_new(DBusConnection *conn)
367 conn_name = dbus_bus_get_unique_name(conn); 376 conn_name = dbus_bus_get_unique_name(conn);
368 if (conn_name) 377 if (conn_name)
369 { 378 {
370 printf("Connected! Name: %s\n", conn_name); 379 DBG("Connected! Name: %s", conn_name);
371 cd->conn_name = strdup(conn_name); 380 cd->conn_name = strdup(conn_name);
372 } 381 }
373 else 382 else
374 printf("Not connected\n"); 383 DBG("Not connected");
375 384
376 cd->shared_type = (unsigned int)-1; 385 cd->shared_type = (unsigned int)-1;
377 cd->fd_handlers = NULL; 386 cd->fd_handlers = NULL;
@@ -386,7 +395,7 @@ e_dbus_connection_free(void *data)
386 E_DBus_Connection *cd = data; 395 E_DBus_Connection *cd = data;
387 Ecore_Fd_Handler *fd_handler; 396 Ecore_Fd_Handler *fd_handler;
388 Ecore_Timer *timer; 397 Ecore_Timer *timer;
389 printf("e_dbus_connection free!\n"); 398 DBG("e_dbus_connection free!");
390 399
391 EINA_LIST_FREE(cd->fd_handlers, fd_handler) 400 EINA_LIST_FREE(cd->fd_handlers, fd_handler)
392 ecore_main_fd_handler_del(fd_handler); 401 ecore_main_fd_handler_del(fd_handler);
@@ -420,9 +429,17 @@ e_dbus_init(void)
420 return --_edbus_init_count; 429 return --_edbus_init_count;
421 } 430 }
422 431
432 _e_dbus_log_dom = eina_log_domain_register("e_dbus", E_DBUS_COLOR_DEFAULT);
433 if (_e_dbus_log_dom < 0)
434 {
435 EINA_LOG_ERR("Unable to create an 'e_dbus' log domain");
436 eina_shutdown();
437 return --_edbus_init_count;
438 }
439
423 if (!ecore_init()) 440 if (!ecore_init())
424 { 441 {
425 fprintf(stderr, "E-dbus: Unable to initialize ecore\n"); 442 ERR("E-dbus: Unable to initialize ecore");
426 eina_shutdown(); 443 eina_shutdown();
427 return --_edbus_init_count; 444 return --_edbus_init_count;
428 } 445 }
@@ -438,7 +455,7 @@ e_dbus_shutdown(void)
438{ 455{
439 if (_edbus_init_count <= 0) 456 if (_edbus_init_count <= 0)
440 { 457 {
441 fprintf(stderr, "Init count not greater than 0 in shutdown.\n"); 458 EINA_LOG_ERR("Init count not greater than 0 in shutdown.");
442 return 0; 459 return 0;
443 } 460 }
444 if (--_edbus_init_count) 461 if (--_edbus_init_count)
@@ -446,6 +463,8 @@ e_dbus_shutdown(void)
446 463
447 // e_dbus_object_shutdown(); 464 // e_dbus_object_shutdown();
448 ecore_shutdown(); 465 ecore_shutdown();
466 eina_log_domain_unregister(_e_dbus_log_dom);
467 _e_dbus_log_dom = -1;
449 eina_shutdown(); 468 eina_shutdown();
450 469
451 return _edbus_init_count; 470 return _edbus_init_count;
@@ -490,7 +509,7 @@ void
490e_dbus_connection_close(E_DBus_Connection *conn) 509e_dbus_connection_close(E_DBus_Connection *conn)
491{ 510{
492 if (!conn) return; 511 if (!conn) return;
493 printf("e_dbus_connection_close\n"); 512 DBG("e_dbus_connection_close");
494 513
495 if (e_dbus_idler_active) 514 if (e_dbus_idler_active)
496 { 515 {