Merge lp:~rainct/libzeitgeist/986230 into lp:libzeitgeist
- 986230
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michal Hruby (community) | Needs Fixing | ||
Review via email: mp+102971@code.launchpad.net |
Commit message
Description of the change
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.
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.
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
1 | === modified file 'configure.ac' | |||
2 | --- configure.ac 2012-04-05 10:11:53 +0000 | |||
3 | +++ configure.ac 2012-04-24 15:44:23 +0000 | |||
4 | @@ -69,7 +69,7 @@ | |||
5 | 69 | #################################################################### | 69 | #################################################################### |
6 | 70 | # Check library deps | 70 | # Check library deps |
7 | 71 | #################################################################### | 71 | #################################################################### |
9 | 72 | GLIB_REQUIRED=2.26 | 72 | GLIB_REQUIRED=2.32 |
10 | 73 | PKG_CHECK_MODULES(GLIB2, [glib-2.0 >= $GLIB_REQUIRED ]) | 73 | PKG_CHECK_MODULES(GLIB2, [glib-2.0 >= $GLIB_REQUIRED ]) |
11 | 74 | PKG_CHECK_MODULES(GOBJECT2, [gobject-2.0 >= $GLIB_REQUIRED ]) | 74 | PKG_CHECK_MODULES(GOBJECT2, [gobject-2.0 >= $GLIB_REQUIRED ]) |
12 | 75 | PKG_CHECK_MODULES(GIO2, [gio-2.0 >= $GLIB_REQUIRED ]) | 75 | PKG_CHECK_MODULES(GIO2, [gio-2.0 >= $GLIB_REQUIRED ]) |
13 | 76 | 76 | ||
14 | === modified file 'src/zeitgeist-log.c' | |||
15 | --- src/zeitgeist-log.c 2012-03-26 11:03:34 +0000 | |||
16 | +++ src/zeitgeist-log.c 2012-04-24 15:44:23 +0000 | |||
17 | @@ -57,6 +57,10 @@ | |||
18 | 57 | * If log != NULL it means we have a connection */ | 57 | * If log != NULL it means we have a connection */ |
19 | 58 | GDBusProxy *log; | 58 | GDBusProxy *log; |
20 | 59 | 59 | ||
21 | 60 | /* In case auto-launching the ZG daemon failed, this | ||
22 | 61 | * variable will hold the error. */ | ||
23 | 62 | GError *log_error; | ||
24 | 63 | |||
25 | 60 | /* Hash set of ZeitgeistMonitors we've installed. | 64 | /* Hash set of ZeitgeistMonitors we've installed. |
26 | 61 | * We store a map of (monitor, registration_id) */ | 65 | * We store a map of (monitor, registration_id) */ |
27 | 62 | GHashTable *monitors; | 66 | GHashTable *monitors; |
28 | @@ -124,6 +128,7 @@ | |||
29 | 124 | 128 | ||
30 | 125 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); | 129 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); |
31 | 126 | priv->log = NULL; | 130 | priv->log = NULL; |
32 | 131 | priv->log_error = NULL; | ||
33 | 127 | 132 | ||
34 | 128 | /* Reset hash set of monitors */ | 133 | /* Reset hash set of monitors */ |
35 | 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); |
36 | @@ -251,6 +256,8 @@ | |||
37 | 251 | dispatch_method (MethodDispatchContext *ctx) | 256 | dispatch_method (MethodDispatchContext *ctx) |
38 | 252 | { | 257 | { |
39 | 253 | ZeitgeistLogPrivate *priv; | 258 | ZeitgeistLogPrivate *priv; |
40 | 259 | GSimpleAsyncResult *async_result; | ||
41 | 260 | GError *error_copy; | ||
42 | 254 | 261 | ||
43 | 255 | priv = ZEITGEIST_LOG_GET_PRIVATE (ctx->self); | 262 | priv = ZEITGEIST_LOG_GET_PRIVATE (ctx->self); |
44 | 256 | 263 | ||
45 | @@ -265,9 +272,33 @@ | |||
46 | 265 | dispatch_async_callback, | 272 | dispatch_async_callback, |
47 | 266 | ctx); | 273 | ctx); |
48 | 267 | } | 274 | } |
49 | 275 | else if (priv->log_error) | ||
50 | 276 | { | ||
51 | 277 | // Zeitgeist couldn't be auto-started. We'll run the callback | ||
52 | 278 | // anyway and give it an error. | ||
53 | 279 | if (ctx->cb != NULL) | ||
54 | 280 | { | ||
55 | 281 | async_result = g_simple_async_result_new (G_OBJECT(ctx->self), | ||
56 | 282 | ctx->cb, | ||
57 | 283 | ctx, | ||
58 | 284 | NULL); | ||
59 | 285 | g_simple_async_result_set_check_cancellable (async_result, | ||
60 | 286 | ctx->cancellable); | ||
61 | 287 | error_copy = g_error_copy (priv->log_error); | ||
62 | 288 | g_simple_async_result_take_error (async_result, error_copy); | ||
63 | 289 | g_simple_async_result_complete_in_idle (async_result); | ||
64 | 290 | g_object_unref (async_result); | ||
65 | 291 | } | ||
66 | 292 | |||
67 | 293 | g_object_unref (ctx->self); | ||
68 | 294 | g_free (ctx); | ||
69 | 295 | } | ||
70 | 268 | else | 296 | else |
73 | 269 | priv->method_dispatch_queue = g_slist_prepend (priv->method_dispatch_queue, | 297 | { |
74 | 270 | ctx); | 298 | // Queue the request while we wait for Zeitgeist to show up |
75 | 299 | priv->method_dispatch_queue = g_slist_prepend (priv->method_dispatch_queue, | ||
76 | 300 | ctx); | ||
77 | 301 | } | ||
78 | 271 | } | 302 | } |
79 | 272 | 303 | ||
80 | 273 | /* Used to marshal the async callbacks from GDBus into ones | 304 | /* Used to marshal the async callbacks from GDBus into ones |
81 | @@ -495,6 +526,9 @@ | |||
82 | 495 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL); | 526 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL); |
83 | 496 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); | 527 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
84 | 497 | 528 | ||
85 | 529 | if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) | ||
86 | 530 | return NULL; | ||
87 | 531 | |||
88 | 498 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); | 532 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); |
89 | 499 | val = g_dbus_proxy_call_finish (priv->log, res, error); | 533 | val = g_dbus_proxy_call_finish (priv->log, res, error); |
90 | 500 | 534 | ||
91 | @@ -592,6 +626,9 @@ | |||
92 | 592 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL); | 626 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL); |
93 | 593 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); | 627 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
94 | 594 | 628 | ||
95 | 629 | if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) | ||
96 | 630 | return NULL; | ||
97 | 631 | |||
98 | 595 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); | 632 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); |
99 | 596 | val = g_dbus_proxy_call_finish (priv->log, res, error); | 633 | val = g_dbus_proxy_call_finish (priv->log, res, error); |
100 | 597 | 634 | ||
101 | @@ -672,6 +709,9 @@ | |||
102 | 672 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL); | 709 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL); |
103 | 673 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); | 710 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
104 | 674 | 711 | ||
105 | 712 | if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) | ||
106 | 713 | return NULL; | ||
107 | 714 | |||
108 | 675 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); | 715 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); |
109 | 676 | val = g_dbus_proxy_call_finish (priv->log, res, error); | 716 | val = g_dbus_proxy_call_finish (priv->log, res, error); |
110 | 677 | 717 | ||
111 | @@ -740,6 +780,9 @@ | |||
112 | 740 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL); | 780 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL); |
113 | 741 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); | 781 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
114 | 742 | 782 | ||
115 | 783 | if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) | ||
116 | 784 | return NULL; | ||
117 | 785 | |||
118 | 743 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); | 786 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); |
119 | 744 | val = g_dbus_proxy_call_finish (priv->log, res, error); | 787 | val = g_dbus_proxy_call_finish (priv->log, res, error); |
120 | 745 | 788 | ||
121 | @@ -850,6 +893,9 @@ | |||
122 | 850 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE); | 893 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE); |
123 | 851 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | 894 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
124 | 852 | 895 | ||
125 | 896 | if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) | ||
126 | 897 | return FALSE; | ||
127 | 898 | |||
128 | 853 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); | 899 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); |
129 | 854 | val = g_dbus_proxy_call_finish (priv->log, res, error); | 900 | val = g_dbus_proxy_call_finish (priv->log, res, error); |
130 | 855 | 901 | ||
131 | @@ -927,6 +973,9 @@ | |||
132 | 927 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL); | 973 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL); |
133 | 928 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); | 974 | g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
134 | 929 | 975 | ||
135 | 976 | if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) | ||
136 | 977 | return NULL; | ||
137 | 978 | |||
138 | 930 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); | 979 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); |
139 | 931 | val = g_dbus_proxy_call_finish (priv->log, res, error); | 980 | val = g_dbus_proxy_call_finish (priv->log, res, error); |
140 | 932 | 981 | ||
141 | @@ -981,6 +1030,9 @@ | |||
142 | 981 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE); | 1030 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE); |
143 | 982 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | 1031 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
144 | 983 | 1032 | ||
145 | 1033 | if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) | ||
146 | 1034 | return FALSE; | ||
147 | 1035 | |||
148 | 984 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); | 1036 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); |
149 | 985 | val = g_dbus_proxy_call_finish (priv->log, res, error); | 1037 | val = g_dbus_proxy_call_finish (priv->log, res, error); |
150 | 986 | 1038 | ||
151 | @@ -1027,6 +1079,9 @@ | |||
152 | 1027 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE); | 1079 | g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE); |
153 | 1028 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | 1080 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
154 | 1029 | 1081 | ||
155 | 1082 | if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) | ||
156 | 1083 | return FALSE; | ||
157 | 1084 | |||
158 | 1030 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); | 1085 | priv = ZEITGEIST_LOG_GET_PRIVATE (self); |
159 | 1031 | val = g_dbus_proxy_call_finish (priv->log, res, error); | 1086 | val = g_dbus_proxy_call_finish (priv->log, res, error); |
160 | 1032 | 1087 | ||
161 | @@ -1061,6 +1116,7 @@ | |||
162 | 1061 | "but we already have one. Discarding the old and using the " | 1116 | "but we already have one. Discarding the old and using the " |
163 | 1062 | "new one"); | 1117 | "new one"); |
164 | 1063 | g_object_unref (priv->log); | 1118 | g_object_unref (priv->log); |
165 | 1119 | g_clear_error (&priv->log_error); | ||
166 | 1064 | priv->log = NULL; | 1120 | priv->log = NULL; |
167 | 1065 | } | 1121 | } |
168 | 1066 | 1122 | ||
169 | @@ -1069,9 +1125,10 @@ | |||
170 | 1069 | 1125 | ||
171 | 1070 | if (error != NULL) | 1126 | if (error != NULL) |
172 | 1071 | { | 1127 | { |
173 | 1128 | priv->log_error = g_error_copy (error); | ||
174 | 1072 | g_critical ("Failed to create proxy for Zeitgeist daemon: %s", | 1129 | g_critical ("Failed to create proxy for Zeitgeist daemon: %s", |
175 | 1073 | error->message); | 1130 | error->message); |
177 | 1074 | goto cleanup; | 1131 | goto process_pending_calls; |
178 | 1075 | } | 1132 | } |
179 | 1076 | 1133 | ||
180 | 1077 | priv->connection = G_DBUS_CONNECTION (g_object_ref ( | 1134 | priv->connection = G_DBUS_CONNECTION (g_object_ref ( |
181 | @@ -1097,12 +1154,14 @@ | |||
182 | 1097 | priv->is_connected = TRUE; | 1154 | priv->is_connected = TRUE; |
183 | 1098 | g_object_notify (G_OBJECT (self), "connected"); | 1155 | g_object_notify (G_OBJECT (self), "connected"); |
184 | 1099 | 1156 | ||
191 | 1100 | /* Dispatch all queued method calls we got while we didn't have a proxy. | 1157 | process_pending_calls: |
192 | 1101 | * Note that dispatch_method() also frees all the queue members */ | 1158 | |
193 | 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. |
194 | 1103 | g_slist_foreach (priv->method_dispatch_queue, (GFunc) dispatch_method, NULL); | 1160 | * Note that dispatch_method() also frees all the queue members */ |
195 | 1104 | g_slist_free (priv->method_dispatch_queue); | 1161 | priv->method_dispatch_queue = g_slist_reverse (priv->method_dispatch_queue); |
196 | 1105 | priv->method_dispatch_queue = NULL; | 1162 | g_slist_foreach (priv->method_dispatch_queue, (GFunc) dispatch_method, NULL); |
197 | 1163 | g_slist_free (priv->method_dispatch_queue); | ||
198 | 1164 | priv->method_dispatch_queue = NULL; | ||
199 | 1106 | 1165 | ||
200 | 1107 | cleanup: | 1166 | cleanup: |
201 | 1108 | g_object_unref (self); | 1167 | g_object_unref (self); |
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.