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
=== modified file 'src/zeitgeist-log.c'
--- src/zeitgeist-log.c 2011-07-11 17:55:46 +0000
+++ src/zeitgeist-log.c 2011-10-13 15:10:28 +0000
@@ -66,6 +66,9 @@
66 /* Method calls queued up while waiting for a proxy */66 /* Method calls queued up while waiting for a proxy */
67 GSList *method_dispatch_queue;67 GSList *method_dispatch_queue;
6868
69 /* Are we connected to Zeitgeist? */
70 gboolean is_connected;
71
69} ZeitgeistLogPrivate;72} ZeitgeistLogPrivate;
7073
71/* Property ids */74/* Property ids */
@@ -93,9 +96,9 @@
93 const gchar *name_owner,96 const gchar *name_owner,
94 gpointer user_data);97 gpointer user_data);
9598
96static void _zeitgeist_log_on_zg_vanished (GDBusConnection *connection,99static void _zeitgeist_log_on_name_owner_changed (GObject *proxy,
97 const gchar *name,100 GParamSpec *pspec,
98 gpointer user_data);101 gpointer user_data);
99102
100static void _zeitgeist_log_on_zg_proxy_acquired (GObject *source_object,103static void _zeitgeist_log_on_zg_proxy_acquired (GObject *source_object,
101 GAsyncResult *res,104 GAsyncResult *res,
@@ -123,16 +126,17 @@
123 ZeitgeistLogPrivate *priv;126 ZeitgeistLogPrivate *priv;
124127
125 priv = ZEITGEIST_LOG_GET_PRIVATE (self);128 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
126 129 priv->log = NULL;
130
127 /* Reset hash set of monitors */131 /* Reset hash set of monitors */
128 priv->monitors = g_hash_table_new (g_direct_hash, g_direct_equal);132 priv->monitors = g_hash_table_new (g_direct_hash, g_direct_equal);
129 133
130 /* Set up the connection to the ZG daemon */134 /* Set up the connection to the ZG daemon */
131 priv->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION,135 priv->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
132 "org.gnome.zeitgeist.Engine",136 "org.gnome.zeitgeist.Engine",
133 G_BUS_NAME_WATCHER_FLAGS_AUTO_START,137 G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
134 _zeitgeist_log_on_zg_appeared,138 _zeitgeist_log_on_zg_appeared,
135 _zeitgeist_log_on_zg_vanished,139 NULL,
136 self,140 self,
137 NULL);141 NULL);
138}142}
@@ -182,11 +186,12 @@
182 GParamSpec *pspec)186 GParamSpec *pspec)
183{187{
184 ZeitgeistLogPrivate *priv = ZEITGEIST_LOG_GET_PRIVATE (object);188 ZeitgeistLogPrivate *priv = ZEITGEIST_LOG_GET_PRIVATE (object);
189 gchar *name_owner;
185190
186 switch (prop_id)191 switch (prop_id)
187 {192 {
188 case PROP_CONNECTED:193 case PROP_CONNECTED:
189 g_value_set_boolean (value, priv->log != NULL);194 g_value_set_boolean (value, priv->is_connected);
190 break;195 break;
191 default:196 default:
192 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);197 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -984,15 +989,18 @@
984 priv->connection = g_object_ref (connection);989 priv->connection = g_object_ref (connection);
985 }990 }
986991
987 g_dbus_proxy_new (connection,992 if (priv->log == NULL)
988 G_DBUS_PROXY_FLAGS_NONE,993 {
989 NULL,994 g_dbus_proxy_new (connection,
990 name_owner,995 G_DBUS_PROXY_FLAGS_NONE,
991 "/org/gnome/zeitgeist/log/activity",996 NULL,
992 "org.gnome.zeitgeist.Log",997 name,
993 NULL,998 "/org/gnome/zeitgeist/log/activity",
994 _zeitgeist_log_on_zg_proxy_acquired,999 "org.gnome.zeitgeist.Log",
995 g_object_ref (self));1000 NULL,
1001 _zeitgeist_log_on_zg_proxy_acquired,
1002 g_object_ref (self));
1003 }
996}1004}
9971005
998/* Async callback for when a proxy is ready1006/* Async callback for when a proxy is ready
@@ -1030,6 +1038,9 @@
1030 goto cleanup;1038 goto cleanup;
1031 }1039 }
10321040
1041 g_signal_connect (priv->log, "notify::g-name-owner",
1042 G_CALLBACK (_zeitgeist_log_on_name_owner_changed), self);
1043
1033 /* Reinstate all active monitors */1044 /* Reinstate all active monitors */
1034 g_hash_table_iter_init (&iter, priv->monitors);1045 g_hash_table_iter_init (&iter, priv->monitors);
1035 while (g_hash_table_iter_next (&iter, &monitor, &dummy))1046 while (g_hash_table_iter_next (&iter, &monitor, &dummy))
@@ -1037,6 +1048,7 @@
1037 _zeitgeist_log_install_monitor (self, ZEITGEIST_MONITOR (monitor));1048 _zeitgeist_log_install_monitor (self, ZEITGEIST_MONITOR (monitor));
1038 }1049 }
10391050
1051 priv->is_connected = TRUE;
1040 g_object_notify (G_OBJECT (self), "connected");1052 g_object_notify (G_OBJECT (self), "connected");
10411053
1042 /* Dispatch all queued method calls we got while we didn't have a proxy.1054 /* Dispatch all queued method calls we got while we didn't have a proxy.
@@ -1052,20 +1064,40 @@
10521064
1053/* Called when the Zeitgeist daemon leaves the bus */1065/* Called when the Zeitgeist daemon leaves the bus */
1054static void1066static void
1055_zeitgeist_log_on_zg_vanished (GDBusConnection *connection,1067_zeitgeist_log_on_name_owner_changed (GObject *proxy,
1056 const gchar *name,1068 GParamSpec *pspec,
1057 gpointer user_data)1069 gpointer user_data)
1058{1070{
1059 ZeitgeistLog *self;1071 ZeitgeistLog *self;
1060 ZeitgeistLogPrivate *priv;1072 ZeitgeistLogPrivate *priv;
1073 gchar *name_owner;
1074 gboolean connected;
1075 GHashTableIter iter;
1076 gpointer monitor, dummy;
10611077
1062 self = ZEITGEIST_LOG (user_data);1078 self = ZEITGEIST_LOG (user_data);
1063 priv = ZEITGEIST_LOG_GET_PRIVATE (self);1079 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
10641080
1065 g_object_unref (priv->log);1081 name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy));
1066 priv->log = NULL;1082 connected = name_owner != NULL;
10671083
1068 g_object_notify (G_OBJECT (self), "connected");1084 if (connected)
1085 {
1086 /* Reinstate all active monitors */
1087 g_hash_table_iter_init (&iter, priv->monitors);
1088 while (g_hash_table_iter_next (&iter, &monitor, &dummy))
1089 {
1090 _zeitgeist_log_install_monitor (self, ZEITGEIST_MONITOR (monitor));
1091 }
1092 }
1093
1094 if (priv->is_connected ^ connected) /* XOR here! */
1095 {
1096 priv->is_connected = connected;
1097 g_object_notify (G_OBJECT (self), "connected");
1098 }
1099
1100 if (name_owner) g_free (name_owner);
1069}1101}
10701102
1071gboolean1103gboolean
@@ -1074,7 +1106,7 @@
1074 ZeitgeistLogPrivate *priv;1106 ZeitgeistLogPrivate *priv;
10751107
1076 priv = ZEITGEIST_LOG_GET_PRIVATE (self);1108 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
1077 return priv->log != NULL;1109 return priv->is_connected;
1078}1110}
10791111
1080/*1112/*

Subscribers

People subscribed via source and target branches