summaryrefslogtreecommitdiff
path: root/efl
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2014-08-23 20:37:15 +0200
committerdavemds <dave@gurumeditation.it>2014-08-23 20:37:15 +0200
commitd0bea312ef54cc515a3f7b0b9135b550bff90ed3 (patch)
treecc79713b4e9f74409515b9b39df7841dfd1903c2 /efl
parentbc02e43181b3c669f89cbed5e942aa5c1be2ebbe (diff)
dbus_mainloop: reworked how we manage the dbus watch requests.
Dbus can request (via watch_add) more than one watch on the same fd (one for write and one for read), but ecore cannot setup more than one fd_handler on the same fd. So we need to manage this (weired) case internally, reusing an existing fd_handler for more than one dbus watch. This, at the end of the story, fix the ability to connect to the (fucking) PulseAudio dbus server, that do not use the Session or System buses, but provide its own bus.
Diffstat (limited to 'efl')
-rw-r--r--efl/dbus_mainloop/e_dbus.c171
-rw-r--r--efl/dbus_mainloop/e_dbus.h4
2 files changed, 78 insertions, 97 deletions
diff --git a/efl/dbus_mainloop/e_dbus.c b/efl/dbus_mainloop/e_dbus.c
index ad45f8b..20875ba 100644
--- a/efl/dbus_mainloop/e_dbus.c
+++ b/efl/dbus_mainloop/e_dbus.c
@@ -58,7 +58,6 @@ e_dbus_idler(void *data)
58 dbus_connection_dispatch(cd->conn); 58 dbus_connection_dispatch(cd->conn);
59 dbus_connection_unref(cd->conn); 59 dbus_connection_unref(cd->conn);
60 e_dbus_idler_active--; 60 e_dbus_idler_active--;
61 // e_dbus_signal_handlers_clean(cd); // TODO XXX
62 if (!e_dbus_idler_active && close_connection) 61 if (!e_dbus_idler_active && close_connection)
63 { 62 {
64 do 63 do
@@ -88,124 +87,102 @@ cb_dispatch_status(DBusConnection *conn, DBusDispatchStatus new_status, void *da
88 87
89 88
90/* ecore fd handler */ 89/* ecore fd handler */
91static void
92e_dbus_fd_handler_del(E_DBus_Handler_Data *hd)
93{
94 if (!hd->fd_handler) return;
95
96 DDBG(" FD handler del");
97 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler);
98 ecore_main_fd_handler_del(hd->fd_handler);
99 hd->fd_handler = NULL;
100}
101
102static Eina_Bool 90static Eina_Bool
103e_dbus_fd_handler(void *data, Ecore_Fd_Handler *fd_handler) 91e_dbus_fd_handler(void *data, Ecore_Fd_Handler *fd_handler)
104{ 92{
105 E_DBus_Handler_Data *hd; 93 E_DBus_Handler_Data *hd = data;
106 unsigned int condition = 0; 94 unsigned int condition = 0;
107 95
108 DBG("fd handler (%p)!", fd_handler); 96 DDBG("DATA READY ON FD");
109
110 hd = data;
111
112 if (!dbus_watch_get_enabled(hd->watch))
113 {
114 e_dbus_fd_handler_del(hd);
115 return ECORE_CALLBACK_CANCEL;
116 }
117 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) 97 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
118 condition |= DBUS_WATCH_READABLE; 98 condition |= DBUS_WATCH_READABLE;
119 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE)) 99 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
120 condition |= DBUS_WATCH_WRITABLE; 100 condition |= DBUS_WATCH_WRITABLE;
121 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) 101 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
122 condition |= DBUS_WATCH_ERROR; 102 condition |= DBUS_WATCH_ERROR;
123 DBG("fdh || READ: %d, WRITE: %d",
124 (condition & DBUS_WATCH_READABLE) == DBUS_WATCH_READABLE,
125 (condition & DBUS_WATCH_WRITABLE) == DBUS_WATCH_WRITABLE);
126
127 if (condition & DBUS_WATCH_ERROR) DBG("DBUS watch error");
128 dbus_watch_handle(hd->watch, condition);
129 hd = NULL;
130 103
104 if (hd->watch_read && dbus_watch_get_enabled(hd->watch_read))
105 dbus_watch_handle(hd->watch_read, condition);
106 if (hd->watch_read != hd->watch_write &&
107 hd->watch_write && dbus_watch_get_enabled(hd->watch_write))
108 dbus_watch_handle(hd->watch_write, condition);
109
131 return ECORE_CALLBACK_RENEW; 110 return ECORE_CALLBACK_RENEW;
132} 111}
133 112
134static void 113static void
135e_dbus_fd_handler_add(E_DBus_Handler_Data *hd) 114e_dbus_fd_handler_update(E_DBus_Handler_Data *hd)
136{ 115{
137 unsigned int dflags; 116 Ecore_Fd_Handler_Flags eflags = ECORE_FD_ERROR;
138 Ecore_Fd_Handler_Flags eflags;
139 Eina_List *l;
140 Ecore_Fd_Handler *fdh;
141 int fd;
142
143 DDBG(" FD handler add");
144 if (hd->fd_handler) return;
145
146 fd = dbus_watch_get_unix_fd(hd->watch);
147 dflags = dbus_watch_get_flags(hd->watch);
148 eflags = ECORE_FD_ERROR;
149 if (dflags & DBUS_WATCH_READABLE) eflags |= ECORE_FD_READ;
150 if (dflags & DBUS_WATCH_WRITABLE) eflags |= ECORE_FD_WRITE;
151 117
152 EINA_LIST_FOREACH(hd->cd->fd_handlers, l, fdh) 118 if (hd->watch_read && dbus_watch_get_enabled(hd->watch_read))
153 { 119 eflags |= ECORE_FD_READ;
154 if (ecore_main_fd_handler_fd_get(fdh) == fd) return; 120 if (hd->watch_write && dbus_watch_get_enabled(hd->watch_write))
155 } 121 eflags |= ECORE_FD_WRITE;
156 122
157 DDBG(" FD handler add on fd:%d (flags: %d)", fd, dflags); 123 DDBG("FD update %d (flags: %d)", hd->fd, eflags)
158 hd->fd_handler = ecore_main_fd_handler_add(fd, 124 ecore_main_fd_handler_active_set(hd->fd_handler, eflags);
159 eflags,
160 e_dbus_fd_handler,
161 hd,
162 NULL,
163 NULL);
164 if (!hd->fd_handler) { DDBG("ERROR! cannot create FD handler") }
165
166 hd->cd->fd_handlers = eina_list_append(hd->cd->fd_handlers, hd->fd_handler);
167} 125}
168 126
169static void 127static void
170e_dbus_handler_data_free(void *data) 128e_dbus_fd_handler_add(E_DBus_Connection *cd, DBusWatch *watch)
171{ 129{
172 E_DBus_Handler_Data *hd = data; 130 E_DBus_Handler_Data *hd = NULL, *hd2;
131 Eina_List *l;
132 int dflags;
133 int fd;
134
135 fd = dbus_watch_get_unix_fd(watch);
136 dflags = dbus_watch_get_flags(watch);
173 137
174 DDBG("e_dbus_handler_data_free"); 138 EINA_LIST_FOREACH(cd->fd_handlers, l, hd2)
175 if (hd->fd_handler)
176 { 139 {
177 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->fd_handler); 140 if (hd2->fd == fd)
178 ecore_main_fd_handler_del(hd->fd_handler); 141 {
142 hd = hd2;
143 break;
144 }
179 } 145 }
180 free(hd); 146
147 if (!hd)
148 {
149 hd = calloc(1, sizeof(E_DBus_Handler_Data));
150 if (!hd) return;
151 hd->cd = cd;
152 hd->fd = fd;
153 hd->fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_ERROR,
154 e_dbus_fd_handler,
155 hd, NULL, NULL);
156 if (!hd->fd_handler) { DDBG("ERROR! cannot create FD handler") }
157 cd->fd_handlers = eina_list_append(cd->fd_handlers, hd);
158 }
159
160 if (dflags & DBUS_WATCH_READABLE) hd->watch_read = watch;
161 if (dflags & DBUS_WATCH_WRITABLE) hd->watch_write = watch;
162 dbus_watch_set_data(watch, hd, NULL);
163 e_dbus_fd_handler_update(hd);
181} 164}
182 165
183static void 166static void
184e_dbus_handler_data_add(E_DBus_Connection *cd, DBusWatch *watch) 167e_dbus_fd_handler_del(E_DBus_Handler_Data *hd)
185{ 168{
186 E_DBus_Handler_Data *hd; 169 DDBG(" FD handler del");
187 170 hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd);
188 hd = calloc(1, sizeof(E_DBus_Handler_Data)); 171 ecore_main_fd_handler_del(hd->fd_handler);
189 dbus_watch_set_data(watch, hd, e_dbus_handler_data_free); 172 free(hd);
190 hd->cd = cd;
191 hd->watch = watch;
192
193 if (dbus_watch_get_enabled(watch))
194 e_dbus_fd_handler_add(hd);
195} 173}
196 174
197
198/* watch */ 175/* watch */
199static dbus_bool_t 176static dbus_bool_t
200cb_watch_add(DBusWatch *watch, void *data) 177cb_watch_add(DBusWatch *watch, void *data)
201{ 178{
202 E_DBus_Connection *cd; 179 E_DBus_Connection *cd = data;
203 cd = data;
204 180
205 DDBG("Watch add on fd: %d (flags: %d) enable: %d", dbus_watch_get_unix_fd(watch), 181 DDBG("Watch add on fd: %d (flags: %d) enable: %d",
206 dbus_watch_get_flags(watch), dbus_watch_get_enabled(watch)); 182 dbus_watch_get_unix_fd(watch), dbus_watch_get_flags(watch),
183 dbus_watch_get_enabled(watch));
207 184
208 e_dbus_handler_data_add(cd, watch); 185 e_dbus_fd_handler_add(cd, watch);
209 186
210 return true; 187 return true;
211} 188}
@@ -218,8 +195,16 @@ cb_watch_del(DBusWatch *watch, void *data)
218 DDBG("Watch del on fd: %d (flags: %d)", dbus_watch_get_unix_fd(watch), 195 DDBG("Watch del on fd: %d (flags: %d)", dbus_watch_get_unix_fd(watch),
219 dbus_watch_get_flags(watch)); 196 dbus_watch_get_flags(watch));
220 197
221 hd = (E_DBus_Handler_Data *)dbus_watch_get_data(watch); 198 hd = dbus_watch_get_data(watch);
222 e_dbus_fd_handler_del(hd); 199
200 int dflags = dbus_watch_get_flags(watch);
201 if (dflags & DBUS_WATCH_READABLE) hd->watch_read = NULL;
202 if (dflags & DBUS_WATCH_WRITABLE) hd->watch_write = NULL;
203
204 if (!hd->watch_read && !hd->watch_write)
205 e_dbus_fd_handler_del(hd);
206 else
207 e_dbus_fd_handler_update(hd);
223} 208}
224 209
225static void 210static void
@@ -227,16 +212,12 @@ cb_watch_toggle(DBusWatch *watch, void *data)
227{ 212{
228 E_DBus_Handler_Data *hd; 213 E_DBus_Handler_Data *hd;
229 214
230 DDBG("Watch toggle on fd: %d (flags: %d) enable: %d", dbus_watch_get_unix_fd(watch), 215 DDBG("Watch toggle on fd: %d (flags: %d) enable: %d",
231 dbus_watch_get_flags(watch), dbus_watch_get_enabled(watch)); 216 dbus_watch_get_unix_fd(watch), dbus_watch_get_flags(watch),
217 dbus_watch_get_enabled(watch));
232 218
233 hd = dbus_watch_get_data(watch); 219 hd = dbus_watch_get_data(watch);
234 if (!hd) return; 220 e_dbus_fd_handler_update(hd);
235
236 if (dbus_watch_get_enabled(watch))
237 e_dbus_fd_handler_add(hd);
238 else
239 e_dbus_fd_handler_del(hd);
240} 221}
241 222
242 223
@@ -361,12 +342,12 @@ static void
361e_dbus_connection_free(void *data) 342e_dbus_connection_free(void *data)
362{ 343{
363 E_DBus_Connection *cd = data; 344 E_DBus_Connection *cd = data;
364 Ecore_Fd_Handler *fd_handler; 345 E_DBus_Handler_Data *hd;
365 Ecore_Timer *timer; 346 Ecore_Timer *timer;
366 DBG("e_dbus_connection free!"); 347 DBG("e_dbus_connection free!");
367 348
368 EINA_LIST_FREE(cd->fd_handlers, fd_handler) 349 EINA_LIST_FREE(cd->fd_handlers, hd)
369 ecore_main_fd_handler_del(fd_handler); 350 e_dbus_fd_handler_del(hd);
370 351
371 EINA_LIST_FREE(cd->timeouts, timer) 352 EINA_LIST_FREE(cd->timeouts, timer)
372 ecore_timer_del(timer); 353 ecore_timer_del(timer);
@@ -374,8 +355,6 @@ e_dbus_connection_free(void *data)
374 // if (cd->shared_type != (unsigned int)-1) 355 // if (cd->shared_type != (unsigned int)-1)
375 // shared_connections[cd->shared_type] = NULL; 356 // shared_connections[cd->shared_type] = NULL;
376 357
377 // e_dbus_signal_handlers_free_all(cd);
378
379 if (cd->conn_name) free(cd->conn_name); 358 if (cd->conn_name) free(cd->conn_name);
380 359
381 if (cd->idler) ecore_idler_del(cd->idler); 360 if (cd->idler) ecore_idler_del(cd->idler);
diff --git a/efl/dbus_mainloop/e_dbus.h b/efl/dbus_mainloop/e_dbus.h
index dff55fb..7b4939a 100644
--- a/efl/dbus_mainloop/e_dbus.h
+++ b/efl/dbus_mainloop/e_dbus.h
@@ -47,9 +47,11 @@ struct E_DBus_Connection
47 47
48struct E_DBus_Handler_Data 48struct E_DBus_Handler_Data
49{ 49{
50 int fd;
50 Ecore_Fd_Handler *fd_handler; 51 Ecore_Fd_Handler *fd_handler;
51 E_DBus_Connection *cd; 52 E_DBus_Connection *cd;
52 DBusWatch *watch; 53 DBusWatch *watch_read;
54 DBusWatch *watch_write;
53}; 55};
54 56
55struct E_DBus_Timeout_Data 57struct E_DBus_Timeout_Data