Merge lp:~mhr3/libzeitgeist/fix-reconnect into lp:libzeitgeist

Proposed by Michal Hruby
Status: Merged
Merged at revision: 212
Proposed branch: lp:~mhr3/libzeitgeist/fix-reconnect
Merge into: lp:libzeitgeist
Diff against target: 164 lines (+56/-24)
1 file modified
src/zeitgeist-log.c (+56/-24)
To merge this branch: bzr merge lp:~mhr3/libzeitgeist/fix-reconnect
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen Approve
Review via email: mp+79298@code.launchpad.net

Description of the change

A little bit of clarification - at first I went without the private is_connected member and I was calling g_object_notify (..., "connected") in the ..._appearead and ..._vanished callbacks, but it turned out that the g-name-owner property isn't yet updated when that callback is being processed, therefore zg might have been killed, and you would get a notification, but calling is_connected () would return TRUE.

Therefore I just added the private member and am updating everything in the name_owner_changed callback.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/zeitgeist-log.c'
2--- src/zeitgeist-log.c 2011-07-11 17:55:46 +0000
3+++ src/zeitgeist-log.c 2011-10-13 15:10:28 +0000
4@@ -66,6 +66,9 @@
5 /* Method calls queued up while waiting for a proxy */
6 GSList *method_dispatch_queue;
7
8+ /* Are we connected to Zeitgeist? */
9+ gboolean is_connected;
10+
11 } ZeitgeistLogPrivate;
12
13 /* Property ids */
14@@ -93,9 +96,9 @@
15 const gchar *name_owner,
16 gpointer user_data);
17
18-static void _zeitgeist_log_on_zg_vanished (GDBusConnection *connection,
19- const gchar *name,
20- gpointer user_data);
21+static void _zeitgeist_log_on_name_owner_changed (GObject *proxy,
22+ GParamSpec *pspec,
23+ gpointer user_data);
24
25 static void _zeitgeist_log_on_zg_proxy_acquired (GObject *source_object,
26 GAsyncResult *res,
27@@ -123,16 +126,17 @@
28 ZeitgeistLogPrivate *priv;
29
30 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
31-
32+ priv->log = NULL;
33+
34 /* Reset hash set of monitors */
35 priv->monitors = g_hash_table_new (g_direct_hash, g_direct_equal);
36-
37+
38 /* Set up the connection to the ZG daemon */
39 priv->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
40 "org.gnome.zeitgeist.Engine",
41 G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
42 _zeitgeist_log_on_zg_appeared,
43- _zeitgeist_log_on_zg_vanished,
44+ NULL,
45 self,
46 NULL);
47 }
48@@ -182,11 +186,12 @@
49 GParamSpec *pspec)
50 {
51 ZeitgeistLogPrivate *priv = ZEITGEIST_LOG_GET_PRIVATE (object);
52+ gchar *name_owner;
53
54 switch (prop_id)
55 {
56 case PROP_CONNECTED:
57- g_value_set_boolean (value, priv->log != NULL);
58+ g_value_set_boolean (value, priv->is_connected);
59 break;
60 default:
61 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
62@@ -984,15 +989,18 @@
63 priv->connection = g_object_ref (connection);
64 }
65
66- g_dbus_proxy_new (connection,
67- G_DBUS_PROXY_FLAGS_NONE,
68- NULL,
69- name_owner,
70- "/org/gnome/zeitgeist/log/activity",
71- "org.gnome.zeitgeist.Log",
72- NULL,
73- _zeitgeist_log_on_zg_proxy_acquired,
74- g_object_ref (self));
75+ if (priv->log == NULL)
76+ {
77+ g_dbus_proxy_new (connection,
78+ G_DBUS_PROXY_FLAGS_NONE,
79+ NULL,
80+ name,
81+ "/org/gnome/zeitgeist/log/activity",
82+ "org.gnome.zeitgeist.Log",
83+ NULL,
84+ _zeitgeist_log_on_zg_proxy_acquired,
85+ g_object_ref (self));
86+ }
87 }
88
89 /* Async callback for when a proxy is ready
90@@ -1030,6 +1038,9 @@
91 goto cleanup;
92 }
93
94+ g_signal_connect (priv->log, "notify::g-name-owner",
95+ G_CALLBACK (_zeitgeist_log_on_name_owner_changed), self);
96+
97 /* Reinstate all active monitors */
98 g_hash_table_iter_init (&iter, priv->monitors);
99 while (g_hash_table_iter_next (&iter, &monitor, &dummy))
100@@ -1037,6 +1048,7 @@
101 _zeitgeist_log_install_monitor (self, ZEITGEIST_MONITOR (monitor));
102 }
103
104+ priv->is_connected = TRUE;
105 g_object_notify (G_OBJECT (self), "connected");
106
107 /* Dispatch all queued method calls we got while we didn't have a proxy.
108@@ -1052,20 +1064,40 @@
109
110 /* Called when the Zeitgeist daemon leaves the bus */
111 static void
112-_zeitgeist_log_on_zg_vanished (GDBusConnection *connection,
113- const gchar *name,
114- gpointer user_data)
115+_zeitgeist_log_on_name_owner_changed (GObject *proxy,
116+ GParamSpec *pspec,
117+ gpointer user_data)
118 {
119 ZeitgeistLog *self;
120 ZeitgeistLogPrivate *priv;
121+ gchar *name_owner;
122+ gboolean connected;
123+ GHashTableIter iter;
124+ gpointer monitor, dummy;
125
126 self = ZEITGEIST_LOG (user_data);
127 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
128
129- g_object_unref (priv->log);
130- priv->log = NULL;
131-
132- g_object_notify (G_OBJECT (self), "connected");
133+ name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy));
134+ connected = name_owner != NULL;
135+
136+ if (connected)
137+ {
138+ /* Reinstate all active monitors */
139+ g_hash_table_iter_init (&iter, priv->monitors);
140+ while (g_hash_table_iter_next (&iter, &monitor, &dummy))
141+ {
142+ _zeitgeist_log_install_monitor (self, ZEITGEIST_MONITOR (monitor));
143+ }
144+ }
145+
146+ if (priv->is_connected ^ connected) /* XOR here! */
147+ {
148+ priv->is_connected = connected;
149+ g_object_notify (G_OBJECT (self), "connected");
150+ }
151+
152+ if (name_owner) g_free (name_owner);
153 }
154
155 gboolean
156@@ -1074,7 +1106,7 @@
157 ZeitgeistLogPrivate *priv;
158
159 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
160- return priv->log != NULL;
161+ return priv->is_connected;
162 }
163
164 /*

Subscribers

People subscribed via source and target branches