summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2014-08-23 17:06:28 +0200
committerdavemds <dave@gurumeditation.it>2014-08-23 17:06:28 +0200
commit6d5a1d1169aa01a549cd8c28d97fc92ba904461c (patch)
tree1ed16d122673eb9ae2d018e6d330ea972fc25f4b
parenta41106348ac94f9aa559ae35d8ef7262ae9ea0d7 (diff)
use 3 spaces indentation, not 2
-rw-r--r--efl/dbus_mainloop/e_dbus.c650
1 files changed, 327 insertions, 323 deletions
diff --git a/efl/dbus_mainloop/e_dbus.c b/efl/dbus_mainloop/e_dbus.c
index 8798f46..ff9d9d4 100644
--- a/efl/dbus_mainloop/e_dbus.c
+++ b/efl/dbus_mainloop/e_dbus.c
@@ -44,90 +44,91 @@ static int _edbus_init_count = 0;
44static void 44static void
45e_dbus_message_free(void *data, void *message) 45e_dbus_message_free(void *data, void *message)
46{ 46{
47 dbus_message_unref(message); 47 dbus_message_unref(message);
48} 48}
49 49
50static DBusHandlerResult 50static DBusHandlerResult
51e_dbus_filter(DBusConnection *conn, DBusMessage *message, void *user_data) 51e_dbus_filter(DBusConnection *conn, DBusMessage *message, void *user_data)
52{ 52{
53 E_DBus_Connection *cd = user_data; 53 E_DBus_Connection *cd = user_data;
54 DBG("-----------------"); 54 DBG("-----------------");
55 DBG("Message!"); 55 DBG("Message!");
56 56
57 DBG("type: %s", dbus_message_type_to_string(dbus_message_get_type(message))); 57 DBG("type: %s", dbus_message_type_to_string(dbus_message_get_type(message)));
58 DBG("path: %s", dbus_message_get_path(message)); 58 DBG("path: %s", dbus_message_get_path(message));
59 DBG("interface: %s", dbus_message_get_interface(message)); 59 DBG("interface: %s", dbus_message_get_interface(message));
60 DBG("member: %s", dbus_message_get_member(message)); 60 DBG("member: %s", dbus_message_get_member(message));
61 DBG("sender: %s", dbus_message_get_sender(message)); 61 DBG("sender: %s", dbus_message_get_sender(message));
62 62
63 switch (dbus_message_get_type(message)) 63 switch (dbus_message_get_type(message))
64 { 64 {
65 case DBUS_MESSAGE_TYPE_METHOD_CALL: 65 case DBUS_MESSAGE_TYPE_METHOD_CALL:
66 DBG("signature: %s", dbus_message_get_signature(message)); 66 DBG("signature: %s", dbus_message_get_signature(message));
67 break; 67 break;
68 case DBUS_MESSAGE_TYPE_METHOD_RETURN: 68 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
69 DBG("reply serial %d", dbus_message_get_reply_serial(message)); 69 DBG("reply serial %d", dbus_message_get_reply_serial(message));
70 break; 70 break;
71 case DBUS_MESSAGE_TYPE_ERROR: 71 case DBUS_MESSAGE_TYPE_ERROR:
72 DBG("error: %s", dbus_message_get_error_name(message)); 72 DBG("error: %s", dbus_message_get_error_name(message));
73 break; 73 break;
74 case DBUS_MESSAGE_TYPE_SIGNAL: 74 case DBUS_MESSAGE_TYPE_SIGNAL:
75 dbus_message_ref(message); 75 dbus_message_ref(message);
76 if (cd->signal_dispatcher) cd->signal_dispatcher(cd, message); 76 if (cd->signal_dispatcher)
77 ecore_event_add(E_DBUS_EVENT_SIGNAL, message, e_dbus_message_free, NULL); 77 cd->signal_dispatcher(cd, message);
78 break; 78 ecore_event_add(E_DBUS_EVENT_SIGNAL, message, e_dbus_message_free, NULL);
79 default: 79 break;
80 break; 80 default:
81 } 81 break;
82 DBG("-----------------"); 82 }
83 83 DBG("-----------------");
84 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 84
85 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
85} 86}
86 87
87static Eina_Bool 88static Eina_Bool
88e_dbus_idler(void *data) 89e_dbus_idler(void *data)
89{ 90{
90 E_DBus_Connection *cd; 91 E_DBus_Connection *cd;
91 cd = data; 92 cd = data;
92 93
93 if (DBUS_DISPATCH_COMPLETE == dbus_connection_get_dispatch_status(cd->conn)) 94 if (DBUS_DISPATCH_COMPLETE == dbus_connection_get_dispatch_status(cd->conn))
94 { 95 {
95 DBG("done dispatching!"); 96 DBG("done dispatching!");
96 cd->idler = NULL; 97 cd->idler = NULL;
97 return ECORE_CALLBACK_CANCEL; 98 return ECORE_CALLBACK_CANCEL;
98 } 99 }
99 e_dbus_idler_active++; 100 e_dbus_idler_active++;
100 dbus_connection_ref(cd->conn); 101 dbus_connection_ref(cd->conn);
101 DBG("dispatch()"); 102 DBG("dispatch()");
102 dbus_connection_dispatch(cd->conn); 103 dbus_connection_dispatch(cd->conn);
103 dbus_connection_unref(cd->conn); 104 dbus_connection_unref(cd->conn);
104 e_dbus_idler_active--; 105 e_dbus_idler_active--;
105 // e_dbus_signal_handlers_clean(cd); // TODO XXX 106 // e_dbus_signal_handlers_clean(cd); // TODO XXX
106 if (!e_dbus_idler_active && close_connection) 107 if (!e_dbus_idler_active && close_connection)
107 { 108 {
108 do 109 do
109 { 110 {
110 e_dbus_connection_close(cd); 111 e_dbus_connection_close(cd);
111 } while (--close_connection); 112 } while (--close_connection);
112 } 113 }
113 return ECORE_CALLBACK_RENEW; 114 return ECORE_CALLBACK_RENEW;
114} 115}
115 116
116static void 117static void
117cb_dispatch_status(DBusConnection *conn, DBusDispatchStatus new_status, void *data) 118cb_dispatch_status(DBusConnection *conn, DBusDispatchStatus new_status, void *data)
118{ 119{
119 E_DBus_Connection *cd; 120 E_DBus_Connection *cd;
120 121
121 DBG("dispatch status: %d!", new_status); 122 DBG("dispatch status: %d!", new_status);
122 cd = data; 123 cd = data;
123 124
124 if (new_status == DBUS_DISPATCH_DATA_REMAINS && !cd->idler) 125 if (new_status == DBUS_DISPATCH_DATA_REMAINS && !cd->idler)
125 cd->idler = ecore_idler_add(e_dbus_idler, cd); 126 cd->idler = ecore_idler_add(e_dbus_idler, cd);
126 else if (new_status != DBUS_DISPATCH_DATA_REMAINS && cd->idler) 127 else if (new_status != DBUS_DISPATCH_DATA_REMAINS && cd->idler)
127 { 128 {
128 ecore_idler_del(cd->idler); 129 ecore_idler_del(cd->idler);
129 cd->idler = NULL; 130 cd->idler = NULL;
130 } 131 }
131} 132}
132 133
133 134
@@ -135,103 +136,106 @@ cb_dispatch_status(DBusConnection *conn, DBusDispatchStatus new_status, void *da
135static void 136static void
136e_dbus_fd_handler_del(E_DBus_Handler_Data *hd) 137e_dbus_fd_handler_del(E_DBus_Handler_Data *hd)
137{ 138{
138 if (!hd->fd_handler) return; 139 if (!hd->fd_handler) return;
139 140
140 DBG("handler disabled"); 141 DDBG(" FD handler del");
141 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler); 142 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler);
142 ecore_main_fd_handler_del(hd->fd_handler); 143 ecore_main_fd_handler_del(hd->fd_handler);
143 hd->fd_handler = NULL; 144 hd->fd_handler = NULL;
144} 145}
145 146
146static Eina_Bool 147static Eina_Bool
147e_dbus_fd_handler(void *data, Ecore_Fd_Handler *fd_handler) 148e_dbus_fd_handler(void *data, Ecore_Fd_Handler *fd_handler)
148{ 149{
149 E_DBus_Handler_Data *hd; 150 E_DBus_Handler_Data *hd;
150 unsigned int condition = 0; 151 unsigned int condition = 0;
151 152
152 DBG("fd handler (%p)!", fd_handler); 153 DBG("fd handler (%p)!", fd_handler);
153 154
154 hd = data; 155 hd = data;
155 156
156 if (!hd->enabled) 157 if (!hd->enabled)
157 { 158 {
158 e_dbus_fd_handler_del(hd); 159 e_dbus_fd_handler_del(hd);
159 return ECORE_CALLBACK_CANCEL; 160 return ECORE_CALLBACK_CANCEL;
160 } 161 }
161 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) condition |= DBUS_WATCH_READABLE; 162 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
162 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE)) condition |= DBUS_WATCH_WRITABLE; 163 condition |= DBUS_WATCH_READABLE;
163 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) condition |= DBUS_WATCH_ERROR; 164 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
164 DBG("fdh || READ: %d, WRITE: %d", 165 condition |= DBUS_WATCH_WRITABLE;
166 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
167 condition |= DBUS_WATCH_ERROR;
168 DBG("fdh || READ: %d, WRITE: %d",
165 (condition & DBUS_WATCH_READABLE) == DBUS_WATCH_READABLE, 169 (condition & DBUS_WATCH_READABLE) == DBUS_WATCH_READABLE,
166 (condition & DBUS_WATCH_WRITABLE) == DBUS_WATCH_WRITABLE); 170 (condition & DBUS_WATCH_WRITABLE) == DBUS_WATCH_WRITABLE);
167 171
168 if (condition & DBUS_WATCH_ERROR) DBG("DBUS watch error"); 172 if (condition & DBUS_WATCH_ERROR) DBG("DBUS watch error");
169 dbus_watch_handle(hd->watch, condition); 173 dbus_watch_handle(hd->watch, condition);
170 hd = NULL; 174 hd = NULL;
171 175
172 return ECORE_CALLBACK_RENEW; 176 return ECORE_CALLBACK_RENEW;
173} 177}
174 178
175static void 179static void
176e_dbus_fd_handler_add(E_DBus_Handler_Data *hd) 180e_dbus_fd_handler_add(E_DBus_Handler_Data *hd)
177{ 181{
178 unsigned int dflags; 182 unsigned int dflags;
179 Ecore_Fd_Handler_Flags eflags; 183 Ecore_Fd_Handler_Flags eflags;
180 Eina_List *l; 184 Eina_List *l;
181 Ecore_Fd_Handler *fdh; 185 Ecore_Fd_Handler *fdh;
182 186
183 DDBG("FD handler add"); 187 DDBG(" FD handler add");
184 if (hd->fd_handler) return; 188 if (hd->fd_handler) return;
185 dflags = dbus_watch_get_flags(hd->watch); 189 dflags = dbus_watch_get_flags(hd->watch);
186 eflags = ECORE_FD_ERROR; 190 eflags = ECORE_FD_ERROR;
187 if (dflags & DBUS_WATCH_READABLE) eflags |= ECORE_FD_READ; 191 if (dflags & DBUS_WATCH_READABLE) eflags |= ECORE_FD_READ;
188 if (dflags & DBUS_WATCH_WRITABLE) eflags |= ECORE_FD_WRITE; 192 if (dflags & DBUS_WATCH_WRITABLE) eflags |= ECORE_FD_WRITE;
189 193
190 EINA_LIST_FOREACH(hd->cd->fd_handlers, l, fdh) 194 EINA_LIST_FOREACH(hd->cd->fd_handlers, l, fdh)
191 { 195 {
192 if (ecore_main_fd_handler_fd_get(fdh) == hd->fd) return; 196 if (ecore_main_fd_handler_fd_get(fdh) == hd->fd) return;
193 } 197 }
194 198
195 DDBG("FD handler add on fd:%d (flags: %d)", hd->fd, dflags); 199 DDBG(" FD handler add on fd:%d (flags: %d)", hd->fd, dflags);
196 hd->fd_handler = ecore_main_fd_handler_add(hd->fd, 200 hd->fd_handler = ecore_main_fd_handler_add(hd->fd,
197 eflags, 201 eflags,
198 e_dbus_fd_handler, 202 e_dbus_fd_handler,
199 hd, 203 hd,
200 NULL, 204 NULL,
201 NULL); 205 NULL);
202 if (!hd->fd_handler) { DDBG("ERROR! cannot create FD handler") } 206 if (!hd->fd_handler) { DDBG("ERROR! cannot create FD handler") }
203 207
204 hd->cd->fd_handlers = eina_list_append(hd->cd->fd_handlers, hd->fd_handler); 208 hd->cd->fd_handlers = eina_list_append(hd->cd->fd_handlers, hd->fd_handler);
205} 209}
206 210
207static void 211static void
208e_dbus_handler_data_free(void *data) 212e_dbus_handler_data_free(void *data)
209{ 213{
210 E_DBus_Handler_Data *hd = data; 214 E_DBus_Handler_Data *hd = data;
211 215
212 DDBG("e_dbus_handler_data_free"); 216 DDBG("e_dbus_handler_data_free");
213 if (hd->fd_handler) 217 if (hd->fd_handler)
214 { 218 {
215 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler); 219 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler);
216 ecore_main_fd_handler_del(hd->fd_handler); 220 ecore_main_fd_handler_del(hd->fd_handler);
217 } 221 }
218 free(hd); 222 free(hd);
219} 223}
220 224
221static void 225static void
222e_dbus_handler_data_add(E_DBus_Connection *cd, DBusWatch *watch) 226e_dbus_handler_data_add(E_DBus_Connection *cd, DBusWatch *watch)
223{ 227{
224 E_DBus_Handler_Data *hd; 228 E_DBus_Handler_Data *hd;
225 229
226 hd = calloc(1, sizeof(E_DBus_Handler_Data)); 230 hd = calloc(1, sizeof(E_DBus_Handler_Data));
227 dbus_watch_set_data(watch, hd, e_dbus_handler_data_free); 231 dbus_watch_set_data(watch, hd, e_dbus_handler_data_free);
228 hd->cd = cd; 232 hd->cd = cd;
229 hd->watch = watch; 233 hd->watch = watch;
230 234
231 hd->enabled = dbus_watch_get_enabled(watch); 235 hd->enabled = dbus_watch_get_enabled(watch);
232 hd->fd = dbus_watch_get_unix_fd(hd->watch); 236 hd->fd = dbus_watch_get_unix_fd(hd->watch);
233 237
234 if (hd->enabled) e_dbus_fd_handler_add(hd); 238 if (hd->enabled) e_dbus_fd_handler_add(hd);
235} 239}
236 240
237 241
@@ -239,44 +243,44 @@ e_dbus_handler_data_add(E_DBus_Connection *cd, DBusWatch *watch)
239static dbus_bool_t 243static dbus_bool_t
240cb_watch_add(DBusWatch *watch, void *data) 244cb_watch_add(DBusWatch *watch, void *data)
241{ 245{
242 E_DBus_Connection *cd; 246 E_DBus_Connection *cd;
243 cd = data; 247 cd = data;
244 248
245 DDBG("Watch add on fd: %d (flags: %d) enable: %d", dbus_watch_get_unix_fd(watch), 249 DDBG("Watch add on fd: %d (flags: %d) enable: %d", dbus_watch_get_unix_fd(watch),
246 dbus_watch_get_flags(watch), dbus_watch_get_enabled(watch)); 250 dbus_watch_get_flags(watch), dbus_watch_get_enabled(watch));
247 251
248 e_dbus_handler_data_add(cd, watch); 252 e_dbus_handler_data_add(cd, watch);
249 253
250 return true; 254 return true;
251} 255}
252 256
253static void 257static void
254cb_watch_del(DBusWatch *watch, void *data) 258cb_watch_del(DBusWatch *watch, void *data)
255{ 259{
256 E_DBus_Handler_Data *hd; 260 E_DBus_Handler_Data *hd;
257 261
258 DDBG("Watch del on fd: %d (flags: %d)", dbus_watch_get_unix_fd(watch), 262 DDBG("Watch del on fd: %d (flags: %d)", dbus_watch_get_unix_fd(watch),
259 dbus_watch_get_flags(watch)); 263 dbus_watch_get_flags(watch));
260 264
261 hd = (E_DBus_Handler_Data *)dbus_watch_get_data(watch); 265 hd = (E_DBus_Handler_Data *)dbus_watch_get_data(watch);
262 e_dbus_fd_handler_del(hd); 266 e_dbus_fd_handler_del(hd);
263} 267}
264 268
265static void 269static void
266cb_watch_toggle(DBusWatch *watch, void *data) 270cb_watch_toggle(DBusWatch *watch, void *data)
267{ 271{
268 E_DBus_Handler_Data *hd; 272 E_DBus_Handler_Data *hd;
269 273
270 DDBG("Watch toggle on fd: %d (flags: %d) enable: %d", dbus_watch_get_unix_fd(watch), 274 DDBG("Watch toggle on fd: %d (flags: %d) enable: %d", dbus_watch_get_unix_fd(watch),
271 dbus_watch_get_flags(watch), dbus_watch_get_enabled(watch)); 275 dbus_watch_get_flags(watch), dbus_watch_get_enabled(watch));
272 276
273 hd = dbus_watch_get_data(watch); 277 hd = dbus_watch_get_data(watch);
274 if (!hd) return; 278 if (!hd) return;
275 279
276 hd->enabled = dbus_watch_get_enabled(watch); 280 hd->enabled = dbus_watch_get_enabled(watch);
277 281
278 if (hd->enabled) e_dbus_fd_handler_add(hd); 282 if (hd->enabled) e_dbus_fd_handler_add(hd);
279 else e_dbus_fd_handler_del(hd); 283 else e_dbus_fd_handler_del(hd);
280} 284}
281 285
282 286
@@ -284,89 +288,89 @@ cb_watch_toggle(DBusWatch *watch, void *data)
284static Eina_Bool 288static Eina_Bool
285e_dbus_timeout_handler(void *data) 289e_dbus_timeout_handler(void *data)
286{ 290{
287 E_DBus_Timeout_Data *td; 291 E_DBus_Timeout_Data *td;
288 292
289 td = data; 293 td = data;
290 294
291 if (!dbus_timeout_get_enabled(td->timeout)) 295 if (!dbus_timeout_get_enabled(td->timeout))
292 { 296 {
293 DBG("timeout_handler (not enabled, ending)"); 297 DBG("timeout_handler (not enabled, ending)");
294 td->handler = NULL; 298 td->handler = NULL;
295 return ECORE_CALLBACK_CANCEL; 299 return ECORE_CALLBACK_CANCEL;
296 } 300 }
297 301
298 DBG("timeout handler!"); 302 DBG("timeout handler!");
299 dbus_timeout_handle(td->timeout); 303 dbus_timeout_handle(td->timeout);
300 return ECORE_CALLBACK_CANCEL; 304 return ECORE_CALLBACK_CANCEL;
301} 305}
302 306
303static void 307static void
304e_dbus_timeout_data_free(void *timeout_data) 308e_dbus_timeout_data_free(void *timeout_data)
305{ 309{
306 E_DBus_Timeout_Data *td = timeout_data; 310 E_DBus_Timeout_Data *td = timeout_data;
307 DBG("e_dbus_timeout_data_free"); 311 DBG("e_dbus_timeout_data_free");
308 if (td->handler) ecore_timer_del(td->handler); 312 if (td->handler) ecore_timer_del(td->handler);
309 free(td); 313 free(td);
310} 314}
311 315
312static dbus_bool_t 316static dbus_bool_t
313cb_timeout_add(DBusTimeout *timeout, void *data) 317cb_timeout_add(DBusTimeout *timeout, void *data)
314{ 318{
315 E_DBus_Connection *cd; 319 E_DBus_Connection *cd;
316 E_DBus_Timeout_Data *td; 320 E_DBus_Timeout_Data *td;
317 321
318 cd = data; 322 cd = data;
319 DBG("timeout add!"); 323 DBG("timeout add!");
320 td = calloc(1, sizeof(E_DBus_Timeout_Data)); 324 td = calloc(1, sizeof(E_DBus_Timeout_Data));
321 td->cd = cd; 325 td->cd = cd;
322 dbus_timeout_set_data(timeout, (void *)td, e_dbus_timeout_data_free); 326 dbus_timeout_set_data(timeout, (void *)td, e_dbus_timeout_data_free);
323 327
324 td->interval = dbus_timeout_get_interval(timeout); 328 td->interval = dbus_timeout_get_interval(timeout);
325 td->timeout = timeout; 329 td->timeout = timeout;
326 330
327 if (dbus_timeout_get_enabled(timeout)) 331 if (dbus_timeout_get_enabled(timeout))
328 td->handler = ecore_timer_add(td->interval, e_dbus_timeout_handler, td); 332 td->handler = ecore_timer_add(td->interval, e_dbus_timeout_handler, td);
329 td->cd->timeouts = eina_list_append(td->cd->timeouts, td->handler); 333 td->cd->timeouts = eina_list_append(td->cd->timeouts, td->handler);
330 334
331 return true; 335 return true;
332} 336}
333 337
334static void 338static void
335cb_timeout_del(DBusTimeout *timeout, void *data) 339cb_timeout_del(DBusTimeout *timeout, void *data)
336{ 340{
337 E_DBus_Timeout_Data *td; 341 E_DBus_Timeout_Data *td;
338 DBG("timeout del!"); 342 DBG("timeout del!");
339 343
340 td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout); 344 td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout);
341 345
342 if (td->handler) 346 if (td->handler)
343 { 347 {
344 td->cd->timeouts = eina_list_remove(td->cd->timeouts, td->handler); 348 td->cd->timeouts = eina_list_remove(td->cd->timeouts, td->handler);
345 ecore_timer_del(td->handler); 349 ecore_timer_del(td->handler);
346 td->handler = NULL; 350 td->handler = NULL;
347 } 351 }
348 352
349 /* Note: timeout data gets freed when the timeout itself is freed by dbus */ 353 /* Note: timeout data gets freed when the timeout itself is freed by dbus */
350} 354}
351 355
352static void 356static void
353cb_timeout_toggle(DBusTimeout *timeout, void *data) 357cb_timeout_toggle(DBusTimeout *timeout, void *data)
354{ 358{
355 E_DBus_Timeout_Data *td; 359 E_DBus_Timeout_Data *td;
356 DBG("timeout toggle!"); 360 DBG("timeout toggle!");
357 361
358 td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout); 362 td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout);
359 363
360 if (dbus_timeout_get_enabled(td->timeout)) 364 if (dbus_timeout_get_enabled(td->timeout))
361 { 365 {
362 td->interval = dbus_timeout_get_interval(timeout); 366 td->interval = dbus_timeout_get_interval(timeout);
363 td->handler = ecore_timer_add(td->interval, e_dbus_timeout_handler, td); 367 td->handler = ecore_timer_add(td->interval, e_dbus_timeout_handler, td);
364 } 368 }
365 else 369 else
366 { 370 {
367 ecore_timer_del(td->handler); 371 ecore_timer_del(td->handler);
368 td->handler = NULL; 372 td->handler = NULL;
369 } 373 }
370} 374}
371 375
372 376
@@ -374,53 +378,53 @@ cb_timeout_toggle(DBusTimeout *timeout, void *data)
374static E_DBus_Connection * 378static E_DBus_Connection *
375e_dbus_connection_new(DBusConnection *conn) 379e_dbus_connection_new(DBusConnection *conn)
376{ 380{
377 E_DBus_Connection *cd; 381 E_DBus_Connection *cd;
378 const char *conn_name; 382 const char *conn_name;
379 383
380 cd = calloc(1, sizeof(E_DBus_Connection)); 384 cd = calloc(1, sizeof(E_DBus_Connection));
381 if (!cd) return NULL; 385 if (!cd) return NULL;
382 386
383 cd->conn = conn; 387 cd->conn = conn;
384 conn_name = dbus_bus_get_unique_name(conn); 388 conn_name = dbus_bus_get_unique_name(conn);
385 if (conn_name) 389 if (conn_name)
386 { 390 {
387 DBG("Connected! Name: %s", conn_name); 391 DBG("Connected! Name: %s", conn_name);
388 cd->conn_name = strdup(conn_name); 392 cd->conn_name = strdup(conn_name);
389 } 393 }
390 else 394 else
391 DBG("Not connected"); 395 DBG("Not connected");
392 396
393 cd->shared_type = (unsigned int)-1; 397 cd->shared_type = (unsigned int)-1;
394 cd->fd_handlers = NULL; 398 cd->fd_handlers = NULL;
395 cd->timeouts = NULL; 399 cd->timeouts = NULL;
396 400
397 return cd; 401 return cd;
398} 402}
399 403
400static void 404static void
401e_dbus_connection_free(void *data) 405e_dbus_connection_free(void *data)
402{ 406{
403 E_DBus_Connection *cd = data; 407 E_DBus_Connection *cd = data;
404 Ecore_Fd_Handler *fd_handler; 408 Ecore_Fd_Handler *fd_handler;
405 Ecore_Timer *timer; 409 Ecore_Timer *timer;
406 DBG("e_dbus_connection free!"); 410 DBG("e_dbus_connection free!");
407 411
408 EINA_LIST_FREE(cd->fd_handlers, fd_handler) 412 EINA_LIST_FREE(cd->fd_handlers, fd_handler)
409 ecore_main_fd_handler_del(fd_handler); 413 ecore_main_fd_handler_del(fd_handler);
410 414
411 EINA_LIST_FREE(cd->timeouts, timer) 415 EINA_LIST_FREE(cd->timeouts, timer)
412 ecore_timer_del(timer); 416 ecore_timer_del(timer);
413 417
414 // if (cd->shared_type != (unsigned int)-1) 418 // if (cd->shared_type != (unsigned int)-1)
415 // shared_connections[cd->shared_type] = NULL; 419 // shared_connections[cd->shared_type] = NULL;
416 420
417 // e_dbus_signal_handlers_free_all(cd); 421 // e_dbus_signal_handlers_free_all(cd);
418 422
419 if (cd->conn_name) free(cd->conn_name); 423 if (cd->conn_name) free(cd->conn_name);
420 424
421 if (cd->idler) ecore_idler_del(cd->idler); 425 if (cd->idler) ecore_idler_del(cd->idler);
422 426
423 free(cd); 427 free(cd);
424} 428}
425 429
426 430
@@ -428,129 +432,129 @@ e_dbus_connection_free(void *data)
428int 432int
429e_dbus_init(void) 433e_dbus_init(void)
430{ 434{
431 if (++_edbus_init_count != 1) 435 if (++_edbus_init_count != 1)
432 return _edbus_init_count; 436 return _edbus_init_count;
433 437
434 if (!eina_init()) 438 if (!eina_init())
435 { 439 {
436 fprintf(stderr,"E-dbus: Enable to initialize eina\n"); 440 fprintf(stderr,"E-dbus: Enable to initialize eina\n");
437 return --_edbus_init_count; 441 return --_edbus_init_count;
438 } 442 }
439 443
440 _e_dbus_log_dom = eina_log_domain_register("e_dbus", E_DBUS_COLOR_DEFAULT); 444 _e_dbus_log_dom = eina_log_domain_register("e_dbus", E_DBUS_COLOR_DEFAULT);
441 if (_e_dbus_log_dom < 0) 445 if (_e_dbus_log_dom < 0)
442 { 446 {
443 EINA_LOG_ERR("Unable to create an 'e_dbus' log domain"); 447 EINA_LOG_ERR("Unable to create an 'e_dbus' log domain");
444 eina_shutdown(); 448 eina_shutdown();
445 return --_edbus_init_count; 449 return --_edbus_init_count;
446 } 450 }
447 451
448 if (!ecore_init()) 452 if (!ecore_init())
449 { 453 {
450 ERR("E-dbus: Unable to initialize ecore"); 454 ERR("E-dbus: Unable to initialize ecore");
451 eina_shutdown(); 455 eina_shutdown();
452 return --_edbus_init_count; 456 return --_edbus_init_count;
453 } 457 }
454 458
455 E_DBUS_EVENT_SIGNAL = ecore_event_type_new(); 459 E_DBUS_EVENT_SIGNAL = ecore_event_type_new();
456 460
457 return _edbus_init_count; 461 return _edbus_init_count;
458} 462}
459 463
460int 464int
461e_dbus_shutdown(void) 465e_dbus_shutdown(void)
462{ 466{
463 if (_edbus_init_count <= 0) 467 if (_edbus_init_count <= 0)
464 { 468 {
465 EINA_LOG_ERR("Init count not greater than 0 in shutdown."); 469 EINA_LOG_ERR("Init count not greater than 0 in shutdown.");
466 return 0; 470 return 0;
467 } 471 }
468 if (--_edbus_init_count) 472 if (--_edbus_init_count)
469 return _edbus_init_count; 473 return _edbus_init_count;
470 474
471 ecore_shutdown(); 475 ecore_shutdown();
472 eina_log_domain_unregister(_e_dbus_log_dom); 476 eina_log_domain_unregister(_e_dbus_log_dom);
473 _e_dbus_log_dom = -1; 477 _e_dbus_log_dom = -1;
474 eina_shutdown(); 478 eina_shutdown();
475 479
476 return _edbus_init_count; 480 return _edbus_init_count;
477} 481}
478 482
479E_DBus_Connection * 483E_DBus_Connection *
480e_dbus_connection_setup(DBusConnection *conn) 484e_dbus_connection_setup(DBusConnection *conn)
481{ 485{
482 E_DBus_Connection *cd; 486 E_DBus_Connection *cd;
483 487
484 cd = e_dbus_connection_new(conn); 488 cd = e_dbus_connection_new(conn);
485 if (!cd) return NULL; 489 if (!cd) return NULL;
486 490
487 /* connection_setup */ 491 /* connection_setup */
488 dbus_connection_set_exit_on_disconnect(cd->conn, EINA_FALSE); 492 dbus_connection_set_exit_on_disconnect(cd->conn, EINA_FALSE);
489 dbus_connection_allocate_data_slot(&connection_slot); 493 dbus_connection_allocate_data_slot(&connection_slot);
490 494
491 dbus_connection_set_data(cd->conn, connection_slot, (void *)cd, e_dbus_connection_free); 495 dbus_connection_set_data(cd->conn, connection_slot, (void *)cd,
492 dbus_connection_set_watch_functions(cd->conn, 496 e_dbus_connection_free);
493 cb_watch_add, 497 dbus_connection_set_watch_functions(cd->conn,
494 cb_watch_del, 498 cb_watch_add,
495 cb_watch_toggle, 499 cb_watch_del,
496 cd, 500 cb_watch_toggle,
497 NULL); 501 cd,
498 502 NULL);
499 dbus_connection_set_timeout_functions(cd->conn, 503
500 cb_timeout_add, 504 dbus_connection_set_timeout_functions(cd->conn,
501 cb_timeout_del, 505 cb_timeout_add,
502 cb_timeout_toggle, 506 cb_timeout_del,
503 cd, 507 cb_timeout_toggle,
504 NULL); 508 cd,
505 509 NULL);
506 dbus_connection_set_dispatch_status_function(cd->conn, cb_dispatch_status, cd, NULL); 510
507 dbus_connection_add_filter(cd->conn, e_dbus_filter, cd, NULL); 511 dbus_connection_set_dispatch_status_function(cd->conn, cb_dispatch_status, cd, NULL);
508 512 dbus_connection_add_filter(cd->conn, e_dbus_filter, cd, NULL);
509 cb_dispatch_status(cd->conn, dbus_connection_get_dispatch_status(cd->conn), cd); 513 cb_dispatch_status(cd->conn, dbus_connection_get_dispatch_status(cd->conn), cd);
510 514
511 return cd; 515 return cd;
512} 516}
513 517
514void 518void
515e_dbus_connection_close(E_DBus_Connection *conn) 519e_dbus_connection_close(E_DBus_Connection *conn)
516{ 520{
517 if (!conn) return; 521 if (!conn) return;
518 DBG("e_dbus_connection_close"); 522 DBG("e_dbus_connection_close");
519 523
520 if (e_dbus_idler_active) 524 if (e_dbus_idler_active)
521 { 525 {
522 close_connection++; 526 close_connection++;
523 return; 527 return;
524 } 528 }
525 if (--(conn->refcount) != 0) return; 529 if (--(conn->refcount) != 0) return;
526 530
527 dbus_connection_free_data_slot(&connection_slot); 531 dbus_connection_free_data_slot(&connection_slot);
528 dbus_connection_remove_filter(conn->conn, e_dbus_filter, conn); 532 dbus_connection_remove_filter(conn->conn, e_dbus_filter, conn);
529 dbus_connection_set_watch_functions (conn->conn, 533 dbus_connection_set_watch_functions(conn->conn,
530 NULL, 534 NULL,
531 NULL, 535 NULL,
532 NULL, 536 NULL,
533 NULL, NULL); 537 NULL, NULL);
534 538
535 dbus_connection_set_timeout_functions (conn->conn, 539 dbus_connection_set_timeout_functions(conn->conn,
536 NULL, 540 NULL,
537 NULL, 541 NULL,
538 NULL, 542 NULL,
539 NULL, NULL); 543 NULL, NULL);
540 544
541 dbus_connection_set_dispatch_status_function (conn->conn, NULL, NULL, NULL); 545 dbus_connection_set_dispatch_status_function(conn->conn, NULL, NULL, NULL);
542 546
543 /* Idler functin must be cancelled when dbus connection is unreferenced */ 547 /* Idler functin must be cancelled when dbus connection is unreferenced */
544 if (conn->idler) 548 if (conn->idler)
545 { 549 {
546 ecore_idler_del(conn->idler); 550 ecore_idler_del(conn->idler);
547 conn->idler = NULL; 551 conn->idler = NULL;
548 } 552 }
549 553
550 dbus_connection_close(conn->conn); 554 dbus_connection_close(conn->conn);
551 dbus_connection_unref(conn->conn); 555 dbus_connection_unref(conn->conn);
552 556
553 // Note: the E_DBus_Connection gets freed when the dbus_connection is cleaned up by the previous unref 557 // Note: the E_DBus_Connection gets freed when the dbus_connection is cleaned up by the previous unref
554} 558}
555 559
556 560