Merge lp:~ted/libindicator/unwatching-shouldnt-be-a-crime into lp:libindicator/0.4

Proposed by Ted Gould
Status: Merged
Merged at revision: 367
Proposed branch: lp:~ted/libindicator/unwatching-shouldnt-be-a-crime
Merge into: lp:libindicator/0.4
Diff against target: 365 lines (+273/-4)
7 files modified
.bzrignore (+4/-0)
libindicator/indicator-service.c (+29/-3)
tests/Makefile.am (+54/-0)
tests/service-version-good-service.c (+14/-1)
tests/service-version-multiwatch-manager-impolite.c (+61/-0)
tests/service-version-multiwatch-manager.c (+63/-0)
tests/service-version-multiwatch-service.c (+48/-0)
To merge this branch: bzr merge lp:~ted/libindicator/unwatching-shouldnt-be-a-crime
Reviewer Review Type Date Requested Status
Jason Smith (community) Approve
Review via email: mp+29582@code.launchpad.net

Description of the change

Fix to not use the proxy when it's being destroyed.

To post a comment you must log in.
371. By Ted Gould

Taking it to the next level with impoliteness.

372. By Ted Gould

We want the key not the value.

Revision history for this message
Jason Smith (jassmith) wrote :

+1 looks good. We should look into if the proxy issue with dispose can be fixed and upstreamed

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2010-03-10 17:45:53 +0000
3+++ .bzrignore 2010-07-09 18:15:53 +0000
4@@ -152,3 +152,7 @@
5 tests/test-desktop-shortcuts-tester
6 tests/test-desktop-shortcuts-touch-test
7 libindicator/libindicator_la-indicator-image-helper.lo
8+tests/service-version-multiwatch-manager
9+tests/service-version-multiwatch-tester
10+tests/service-version-multiwatch-service
11+tests/service-version-multiwatch-manager-impolite
12
13=== modified file 'libindicator/indicator-service.c'
14--- libindicator/indicator-service.c 2010-07-08 17:36:50 +0000
15+++ libindicator/indicator-service.c 2010-07-09 18:15:53 +0000
16@@ -395,15 +395,38 @@
17 return;
18 }
19
20+typedef struct _hash_table_find_t hash_table_find_t;
21+struct _hash_table_find_t {
22+ GObject * proxy;
23+ gchar * name;
24+};
25+
26+/* Look in the hash table for the proxy, as it won't give us
27+ its name. */
28+static gboolean
29+hash_table_find (gpointer key, gpointer value, gpointer user_data)
30+{
31+ hash_table_find_t * finddata = (hash_table_find_t *)user_data;
32+ if (value == finddata->proxy) {
33+ finddata->name = key;
34+ return TRUE;
35+ }
36+ return FALSE;
37+}
38+
39 /* If the proxy gets destroyed that's the same as getting an
40 unwatch signal. Make it so. */
41 static void
42 proxy_destroyed (GObject * proxy, gpointer user_data)
43 {
44 g_return_if_fail(INDICATOR_IS_SERVICE(user_data));
45-
46- const gchar * name = dbus_g_proxy_get_bus_name(DBUS_G_PROXY(proxy));
47- unwatch_core(INDICATOR_SERVICE(user_data), name);
48+ IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(user_data);
49+
50+ hash_table_find_t finddata = {0};
51+ finddata.proxy = proxy;
52+
53+ g_hash_table_find(priv->watchers, hash_table_find, &finddata);
54+ unwatch_core(INDICATOR_SERVICE(user_data), finddata.name);
55
56 return;
57 }
58@@ -466,6 +489,9 @@
59 static void
60 unwatch_core (IndicatorService * service, const gchar * name)
61 {
62+ g_return_if_fail(name != NULL);
63+ g_return_if_fail(INDICATOR_IS_SERVICE(service));
64+
65 IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service);
66
67 /* Remove us from the watcher list here */
68
69=== modified file 'tests/Makefile.am'
70--- tests/Makefile.am 2010-04-09 16:53:36 +0000
71+++ tests/Makefile.am 2010-07-09 18:15:53 +0000
72@@ -304,6 +304,60 @@
73 DISTCLEANFILES += service-version-tester service-version-bad.service service-version-good.service
74
75 #############################
76+# Service Versions
77+#############################
78+
79+check_PROGRAMS += service-version-multiwatch-manager
80+
81+service_version_manager_SOURCES = \
82+ service-version-values.h \
83+ service-version-multiwatch-manager.c
84+
85+service_version_multiwatch_manager_CFLAGS = \
86+ -Wall -Werror \
87+ $(LIBINDICATOR_CFLAGS) -I$(top_srcdir)
88+
89+service_version_multiwatch_manager_LDADD = \
90+ $(LIBINDICATOR_LIBS) \
91+ $(top_builddir)/libindicator/.libs/libindicator.a
92+
93+check_PROGRAMS += service-version-multiwatch-manager-impolite
94+
95+service_version_manager_impolite_SOURCES = \
96+ service-version-values.h \
97+ service-version-multiwatch-manager-impolite.c
98+
99+service_version_multiwatch_manager_impolite_CFLAGS = \
100+ -Wall -Werror \
101+ $(LIBINDICATOR_CFLAGS) -I$(top_srcdir)
102+
103+service_version_multiwatch_manager_impolite_LDADD = \
104+ $(LIBINDICATOR_LIBS) \
105+ $(top_builddir)/libindicator/.libs/libindicator.a
106+
107+check_PROGRAMS += service-version-multiwatch-service
108+
109+service_version_multiwatch_service_SOURCES = \
110+ service-version-values.h \
111+ service-version-multiwatch-service.c
112+
113+service_version_multiwatch_service_CFLAGS = \
114+ -Wall -Werror \
115+ $(LIBINDICATOR_CFLAGS) -I$(top_srcdir)
116+
117+service_version_multiwatch_service_LDADD = \
118+ $(LIBINDICATOR_LIBS) \
119+ $(top_builddir)/libindicator/.libs/libindicator.a
120+
121+service-version-multiwatch-tester: service-version-multiwatch-manager service-version-multiwatch-service service-version-multiwatch-manager-impolite Makefile.am
122+ @echo "#!/bin/sh" > $@
123+ @echo dbus-test-runner --task ./service-version-multiwatch-service --task-name Service --task ./service-version-multiwatch-manager --task-name Manager1 --task ./service-version-multiwatch-manager --task-name Manager2 --task ./service-version-multiwatch-manager --task-name Manager3 --task ./service-version-multiwatch-manager --task-name Manager4 --task ./service-version-multiwatch-manager --task-name Manager5 --task ./service-version-multiwatch-manager-impolite --task-name Impolite1 --task ./service-version-multiwatch-manager-impolite --task-name Impolite2 --task ./service-version-multiwatch-manager-impolite --task-name Impolite3 >> $@
124+ @chmod +x $@
125+
126+TESTS += service-version-multiwatch-tester
127+DISTCLEANFILES += service-version-multiwatch-tester
128+
129+#############################
130 # Service Manager Shutdown
131 #############################
132
133
134=== modified file 'tests/service-version-good-service.c'
135--- tests/service-version-good-service.c 2009-12-02 21:11:29 +0000
136+++ tests/service-version-good-service.c 2010-07-09 18:15:53 +0000
137@@ -5,12 +5,19 @@
138
139 static GMainLoop * mainloop = NULL;
140 static gboolean passed = FALSE;
141+static IndicatorService * is = NULL;
142
143 gboolean
144 timeout (gpointer data)
145 {
146 passed = FALSE;
147 g_debug("Timeout with no shutdown.");
148+
149+ if (is != NULL) {
150+ g_object_unref(is);
151+ is = NULL;
152+ }
153+
154 g_main_loop_quit(mainloop);
155 return FALSE;
156 }
157@@ -20,6 +27,12 @@
158 {
159 g_debug("Shutdown");
160 passed = TRUE;
161+
162+ if (is != NULL) {
163+ g_object_unref(is);
164+ is = NULL;
165+ }
166+
167 g_main_loop_quit(mainloop);
168 return;
169 }
170@@ -29,7 +42,7 @@
171 {
172 g_type_init();
173
174- IndicatorService * is = indicator_service_new_version("org.ayatana.version.good", SERVICE_VERSION_GOOD);
175+ is = indicator_service_new_version("org.ayatana.version.good", SERVICE_VERSION_GOOD);
176 g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL);
177
178 g_timeout_add_seconds(1, timeout, NULL);
179
180=== added file 'tests/service-version-multiwatch-manager-impolite.c'
181--- tests/service-version-multiwatch-manager-impolite.c 1970-01-01 00:00:00 +0000
182+++ tests/service-version-multiwatch-manager-impolite.c 2010-07-09 18:15:53 +0000
183@@ -0,0 +1,61 @@
184+
185+#include <glib.h>
186+#include "libindicator/indicator-service-manager.h"
187+#include "service-version-values.h"
188+
189+static GMainLoop * mainloop = NULL;
190+static gboolean passed = FALSE;
191+static IndicatorServiceManager * goodis = NULL;
192+
193+gboolean
194+timeout (gpointer data)
195+{
196+ g_debug("Timeout.");
197+ passed = FALSE;
198+ g_main_loop_quit(mainloop);
199+ return FALSE;
200+}
201+
202+void
203+connection_good (IndicatorServiceManager * sm, gboolean connected, gpointer user_data)
204+{
205+ if (!connected) return;
206+ g_debug("Connection From Service.");
207+ passed = TRUE;
208+ g_main_loop_quit(mainloop);
209+ return;
210+}
211+
212+gboolean
213+delay_start (gpointer data)
214+{
215+ g_debug("Starting Manager");
216+
217+ goodis = indicator_service_manager_new_version("org.ayatana.version.good", SERVICE_VERSION_GOOD);
218+ g_signal_connect(G_OBJECT(goodis), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_good), NULL);
219+
220+ g_timeout_add_seconds(1, timeout, NULL);
221+
222+ return FALSE;
223+}
224+
225+int
226+main (int argc, char ** argv)
227+{
228+ g_type_init();
229+ g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);
230+ g_print("Manager: DBUS_SESSION_BUS_ADDRESS = %s\n", g_getenv("DBUS_SESSION_BUS_ADDRESS"));
231+
232+ g_timeout_add(500, delay_start, NULL);
233+
234+ mainloop = g_main_loop_new(NULL, FALSE);
235+ g_main_loop_run(mainloop);
236+
237+ g_debug("Quiting");
238+ if (passed) {
239+ g_debug("Passed");
240+ return 0;
241+ }
242+ g_debug("Failed");
243+ return 1;
244+}
245
246=== added file 'tests/service-version-multiwatch-manager.c'
247--- tests/service-version-multiwatch-manager.c 1970-01-01 00:00:00 +0000
248+++ tests/service-version-multiwatch-manager.c 2010-07-09 18:15:53 +0000
249@@ -0,0 +1,63 @@
250+
251+#include <glib.h>
252+#include "libindicator/indicator-service-manager.h"
253+#include "service-version-values.h"
254+
255+static GMainLoop * mainloop = NULL;
256+static gboolean passed = FALSE;
257+static IndicatorServiceManager * goodis = NULL;
258+
259+gboolean
260+timeout (gpointer data)
261+{
262+ g_debug("Timeout.");
263+ passed = FALSE;
264+ g_main_loop_quit(mainloop);
265+ return FALSE;
266+}
267+
268+void
269+connection_good (IndicatorServiceManager * sm, gboolean connected, gpointer user_data)
270+{
271+ if (!connected) return;
272+ g_debug("Connection From Service.");
273+ passed = TRUE;
274+ g_main_loop_quit(mainloop);
275+ return;
276+}
277+
278+gboolean
279+delay_start (gpointer data)
280+{
281+ g_debug("Starting Manager");
282+
283+ goodis = indicator_service_manager_new_version("org.ayatana.version.good", SERVICE_VERSION_GOOD);
284+ g_signal_connect(G_OBJECT(goodis), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_good), NULL);
285+
286+ g_timeout_add_seconds(1, timeout, NULL);
287+
288+ return FALSE;
289+}
290+
291+int
292+main (int argc, char ** argv)
293+{
294+ g_type_init();
295+ g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);
296+ g_print("Manager: DBUS_SESSION_BUS_ADDRESS = %s\n", g_getenv("DBUS_SESSION_BUS_ADDRESS"));
297+
298+ g_timeout_add(500, delay_start, NULL);
299+
300+ mainloop = g_main_loop_new(NULL, FALSE);
301+ g_main_loop_run(mainloop);
302+
303+ g_object_unref(goodis);
304+
305+ g_debug("Quiting");
306+ if (passed) {
307+ g_debug("Passed");
308+ return 0;
309+ }
310+ g_debug("Failed");
311+ return 1;
312+}
313
314=== added file 'tests/service-version-multiwatch-service.c'
315--- tests/service-version-multiwatch-service.c 1970-01-01 00:00:00 +0000
316+++ tests/service-version-multiwatch-service.c 2010-07-09 18:15:53 +0000
317@@ -0,0 +1,48 @@
318+
319+#include <glib.h>
320+#include "libindicator/indicator-service.h"
321+#include "service-version-values.h"
322+
323+static GMainLoop * mainloop = NULL;
324+static gboolean passed = FALSE;
325+
326+gboolean
327+timeout (gpointer data)
328+{
329+ passed = FALSE;
330+ g_debug("Timeout with no shutdown.");
331+ g_main_loop_quit(mainloop);
332+ return FALSE;
333+}
334+
335+void
336+shutdown (void)
337+{
338+ g_debug("Shutdown");
339+ passed = TRUE;
340+ g_main_loop_quit(mainloop);
341+ return;
342+}
343+
344+int
345+main (int argc, char ** argv)
346+{
347+ g_type_init();
348+ g_debug("Service starting");
349+
350+ IndicatorService * is = indicator_service_new_version("org.ayatana.version.good", SERVICE_VERSION_GOOD);
351+ g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL);
352+
353+ g_timeout_add_seconds(2, timeout, NULL);
354+
355+ mainloop = g_main_loop_new(NULL, FALSE);
356+ g_main_loop_run(mainloop);
357+
358+ g_debug("Quiting");
359+ if (passed) {
360+ g_debug("Passed");
361+ return 0;
362+ }
363+ g_debug("Failed");
364+ return 1;
365+}

Subscribers

People subscribed via source and target branches