Merge lp:~rainct/libzeitgeist/986230 into lp:libzeitgeist

Proposed by Siegfried Gevatter
Status: Merged
Merged at revision: 237
Proposed branch: lp:~rainct/libzeitgeist/986230
Merge into: lp:libzeitgeist
Diff against target: 201 lines (+69/-10)
2 files modified
configure.ac (+1/-1)
src/zeitgeist-log.c (+68/-9)
To merge this branch: bzr merge lp:~rainct/libzeitgeist/986230
Reviewer Review Type Date Requested Status
Michal Hruby (community) Needs Fixing
Review via email: mp+102971@code.launchpad.net
To post a comment you must log in.
lp:~rainct/libzeitgeist/986230 updated
238. By Siegfried Gevatter

Call callbacks with g_idle and properly free stuff.

Revision history for this message
Michal Hruby (mhr3) wrote :

There's still one issue left - if the cancellable is cancelled, _finish needs to throw IO_ERROR_CANCELLED even if it wanted to throw the log_error. Ideally we'd just use g_simple_async_result_set_check_cancellable, but that's available only from 2.32, so we need to implement it manually.

review: Needs Fixing
lp:~rainct/libzeitgeist/986230 updated
239. By Siegfried Gevatter

Return G_IO_ERROR_CANCELLED when the cancellable is activated

We do this by abusing GSimpleAsyncResult to get a copy of the
cancellable.

Revision history for this message
Michal Hruby (mhr3) wrote :

Actually, looking at the non-trivial changes this requires, let's just bump the gio dependency and use the check_cancellable method.

lp:~rainct/libzeitgeist/986230 updated
240. By Siegfried Gevatter

So now we're gonna use g_simple_async_result_set_check_cancellable :)

Revision history for this message
Michal Hruby (mhr3) wrote :

To make sure this doesn't get lost: (from IRC)

- shouldn't you still check for log_error != NULL in the _finish methods?
- also log_error is not freed in finalize
- and if you use simple..._set_from_error, you don't need to copy it yourself

Revision history for this message
Michal Hruby (mhr3) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2012-04-05 10:11:53 +0000
+++ configure.ac 2012-04-24 15:44:23 +0000
@@ -69,7 +69,7 @@
69####################################################################69####################################################################
70# Check library deps70# Check library deps
71####################################################################71####################################################################
72GLIB_REQUIRED=2.2672GLIB_REQUIRED=2.32
73PKG_CHECK_MODULES(GLIB2, [glib-2.0 >= $GLIB_REQUIRED ])73PKG_CHECK_MODULES(GLIB2, [glib-2.0 >= $GLIB_REQUIRED ])
74PKG_CHECK_MODULES(GOBJECT2, [gobject-2.0 >= $GLIB_REQUIRED ])74PKG_CHECK_MODULES(GOBJECT2, [gobject-2.0 >= $GLIB_REQUIRED ])
75PKG_CHECK_MODULES(GIO2, [gio-2.0 >= $GLIB_REQUIRED ])75PKG_CHECK_MODULES(GIO2, [gio-2.0 >= $GLIB_REQUIRED ])
7676
=== modified file 'src/zeitgeist-log.c'
--- src/zeitgeist-log.c 2012-03-26 11:03:34 +0000
+++ src/zeitgeist-log.c 2012-04-24 15:44:23 +0000
@@ -57,6 +57,10 @@
57 * If log != NULL it means we have a connection */57 * If log != NULL it means we have a connection */
58 GDBusProxy *log;58 GDBusProxy *log;
5959
60 /* In case auto-launching the ZG daemon failed, this
61 * variable will hold the error. */
62 GError *log_error;
63
60 /* Hash set of ZeitgeistMonitors we've installed.64 /* Hash set of ZeitgeistMonitors we've installed.
61 * We store a map of (monitor, registration_id) */65 * We store a map of (monitor, registration_id) */
62 GHashTable *monitors;66 GHashTable *monitors;
@@ -124,6 +128,7 @@
124128
125 priv = ZEITGEIST_LOG_GET_PRIVATE (self);129 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
126 priv->log = NULL;130 priv->log = NULL;
131 priv->log_error = NULL;
127132
128 /* Reset hash set of monitors */133 /* Reset hash set of monitors */
129 priv->monitors = g_hash_table_new (g_direct_hash, g_direct_equal);134 priv->monitors = g_hash_table_new (g_direct_hash, g_direct_equal);
@@ -251,6 +256,8 @@
251dispatch_method (MethodDispatchContext *ctx)256dispatch_method (MethodDispatchContext *ctx)
252{257{
253 ZeitgeistLogPrivate *priv;258 ZeitgeistLogPrivate *priv;
259 GSimpleAsyncResult *async_result;
260 GError *error_copy;
254261
255 priv = ZEITGEIST_LOG_GET_PRIVATE (ctx->self);262 priv = ZEITGEIST_LOG_GET_PRIVATE (ctx->self);
256263
@@ -265,9 +272,33 @@
265 dispatch_async_callback,272 dispatch_async_callback,
266 ctx);273 ctx);
267 }274 }
275 else if (priv->log_error)
276 {
277 // Zeitgeist couldn't be auto-started. We'll run the callback
278 // anyway and give it an error.
279 if (ctx->cb != NULL)
280 {
281 async_result = g_simple_async_result_new (G_OBJECT(ctx->self),
282 ctx->cb,
283 ctx,
284 NULL);
285 g_simple_async_result_set_check_cancellable (async_result,
286 ctx->cancellable);
287 error_copy = g_error_copy (priv->log_error);
288 g_simple_async_result_take_error (async_result, error_copy);
289 g_simple_async_result_complete_in_idle (async_result);
290 g_object_unref (async_result);
291 }
292
293 g_object_unref (ctx->self);
294 g_free (ctx);
295 }
268 else296 else
269 priv->method_dispatch_queue = g_slist_prepend (priv->method_dispatch_queue,297 {
270 ctx);298 // Queue the request while we wait for Zeitgeist to show up
299 priv->method_dispatch_queue = g_slist_prepend (priv->method_dispatch_queue,
300 ctx);
301 }
271}302}
272303
273/* Used to marshal the async callbacks from GDBus into ones304/* Used to marshal the async callbacks from GDBus into ones
@@ -495,6 +526,9 @@
495 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);526 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
496 g_return_val_if_fail (error == NULL || *error == NULL, NULL);527 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
497528
529 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
530 return NULL;
531
498 priv = ZEITGEIST_LOG_GET_PRIVATE (self);532 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
499 val = g_dbus_proxy_call_finish (priv->log, res, error);533 val = g_dbus_proxy_call_finish (priv->log, res, error);
500534
@@ -592,6 +626,9 @@
592 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);626 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
593 g_return_val_if_fail (error == NULL || *error == NULL, NULL);627 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
594628
629 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
630 return NULL;
631
595 priv = ZEITGEIST_LOG_GET_PRIVATE (self);632 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
596 val = g_dbus_proxy_call_finish (priv->log, res, error);633 val = g_dbus_proxy_call_finish (priv->log, res, error);
597634
@@ -672,6 +709,9 @@
672 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);709 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
673 g_return_val_if_fail (error == NULL || *error == NULL, NULL);710 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
674711
712 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
713 return NULL;
714
675 priv = ZEITGEIST_LOG_GET_PRIVATE (self);715 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
676 val = g_dbus_proxy_call_finish (priv->log, res, error);716 val = g_dbus_proxy_call_finish (priv->log, res, error);
677717
@@ -740,6 +780,9 @@
740 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);780 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
741 g_return_val_if_fail (error == NULL || *error == NULL, NULL);781 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
742782
783 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
784 return NULL;
785
743 priv = ZEITGEIST_LOG_GET_PRIVATE (self);786 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
744 val = g_dbus_proxy_call_finish (priv->log, res, error);787 val = g_dbus_proxy_call_finish (priv->log, res, error);
745788
@@ -850,6 +893,9 @@
850 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);893 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
851 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);894 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
852895
896 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
897 return FALSE;
898
853 priv = ZEITGEIST_LOG_GET_PRIVATE (self);899 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
854 val = g_dbus_proxy_call_finish (priv->log, res, error);900 val = g_dbus_proxy_call_finish (priv->log, res, error);
855901
@@ -927,6 +973,9 @@
927 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);973 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
928 g_return_val_if_fail (error == NULL || *error == NULL, NULL);974 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
929975
976 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
977 return NULL;
978
930 priv = ZEITGEIST_LOG_GET_PRIVATE (self);979 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
931 val = g_dbus_proxy_call_finish (priv->log, res, error);980 val = g_dbus_proxy_call_finish (priv->log, res, error);
932981
@@ -981,6 +1030,9 @@
981 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);1030 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
982 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);1031 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
9831032
1033 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
1034 return FALSE;
1035
984 priv = ZEITGEIST_LOG_GET_PRIVATE (self);1036 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
985 val = g_dbus_proxy_call_finish (priv->log, res, error);1037 val = g_dbus_proxy_call_finish (priv->log, res, error);
9861038
@@ -1027,6 +1079,9 @@
1027 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);1079 g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
1028 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);1080 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
10291081
1082 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
1083 return FALSE;
1084
1030 priv = ZEITGEIST_LOG_GET_PRIVATE (self);1085 priv = ZEITGEIST_LOG_GET_PRIVATE (self);
1031 val = g_dbus_proxy_call_finish (priv->log, res, error);1086 val = g_dbus_proxy_call_finish (priv->log, res, error);
10321087
@@ -1061,6 +1116,7 @@
1061 "but we already have one. Discarding the old and using the "1116 "but we already have one. Discarding the old and using the "
1062 "new one");1117 "new one");
1063 g_object_unref (priv->log);1118 g_object_unref (priv->log);
1119 g_clear_error (&priv->log_error);
1064 priv->log = NULL;1120 priv->log = NULL;
1065 }1121 }
10661122
@@ -1069,9 +1125,10 @@
10691125
1070 if (error != NULL)1126 if (error != NULL)
1071 {1127 {
1128 priv->log_error = g_error_copy (error);
1072 g_critical ("Failed to create proxy for Zeitgeist daemon: %s",1129 g_critical ("Failed to create proxy for Zeitgeist daemon: %s",
1073 error->message);1130 error->message);
1074 goto cleanup;1131 goto process_pending_calls;
1075 }1132 }
10761133
1077 priv->connection = G_DBUS_CONNECTION (g_object_ref (1134 priv->connection = G_DBUS_CONNECTION (g_object_ref (
@@ -1097,12 +1154,14 @@
1097 priv->is_connected = TRUE;1154 priv->is_connected = TRUE;
1098 g_object_notify (G_OBJECT (self), "connected");1155 g_object_notify (G_OBJECT (self), "connected");
10991156
1100 /* Dispatch all queued method calls we got while we didn't have a proxy.1157 process_pending_calls:
1101 * Note that dispatch_method() also frees all the queue members */1158
1102 priv->method_dispatch_queue = g_slist_reverse (priv->method_dispatch_queue);1159 /* Dispatch all queued method calls we got while we didn't have a proxy.
1103 g_slist_foreach (priv->method_dispatch_queue, (GFunc) dispatch_method, NULL);1160 * Note that dispatch_method() also frees all the queue members */
1104 g_slist_free (priv->method_dispatch_queue);1161 priv->method_dispatch_queue = g_slist_reverse (priv->method_dispatch_queue);
1105 priv->method_dispatch_queue = NULL;1162 g_slist_foreach (priv->method_dispatch_queue, (GFunc) dispatch_method, NULL);
1163 g_slist_free (priv->method_dispatch_queue);
1164 priv->method_dispatch_queue = NULL;
11061165
1107 cleanup:1166 cleanup:
1108 g_object_unref (self);1167 g_object_unref (self);

Subscribers

People subscribed via source and target branches