Merge lp:~ted/libindicate/show-hide-signals into lp:libindicate/0.6

Proposed by Ted Gould
Status: Merged
Merged at revision: 405
Proposed branch: lp:~ted/libindicate/show-hide-signals
Merge into: lp:libindicate/0.6
Diff against target: 157 lines (+104/-22)
1 file modified
libindicate/listener.c (+104/-22)
To merge this branch: bzr merge lp:~ted/libindicate/show-hide-signals
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+48395@code.launchpad.net

Description of the change

Change from using cached properties to requesting it. This matches what clients expect and gets better values anyway.

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

This is a dead code path, might get used later, but people can find it in Bazaar

413. By Ted Gould

Attaching bug

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

The code looks good, but I still don't entirely get why the properties from the GDBusProxy aren't good enough..?

review: Approve
Revision history for this message
Ted Gould (ted) wrote :

On Thu, 2011-02-03 at 11:38 +0000, Mikkel Kamstrup Erlandsen wrote:
> The code looks good, but I still don't entirely get why the properties
> from the GDBusProxy aren't good enough..?

I'm not entirely sure either. I need to investigate that more, but this
does put us in a more stable situation. I think they're not getting
updated properly.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libindicate/listener.c'
2--- libindicate/listener.c 2011-02-01 20:04:05 +0000
3+++ libindicate/listener.c 2011-02-03 01:52:09 +0000
4@@ -809,7 +809,9 @@
5 proxy_indicator_added(id, proxyt);
6 }
7
8- g_variant_unref(retval);
9+ if (retval != NULL) {
10+ g_variant_unref(retval);
11+ }
12
13 return;
14 }
15@@ -997,7 +999,9 @@
16 }
17 }
18
19- g_variant_unref(retvalue);
20+ if (retvalue != NULL) {
21+ g_variant_unref(retvalue);
22+ }
23 g_free(get_property_data->property);
24 g_free(get_property_data);
25
26@@ -1217,6 +1221,79 @@
27 return;
28 }
29
30+/* Callback data structure */
31+typedef struct _get_server_prop_data_t get_server_prop_data_t;
32+struct _get_server_prop_data_t {
33+ IndicateListener * listener;
34+ IndicateListenerServer * server;
35+ indicate_listener_get_server_property_cb callback;
36+ indicate_listener_get_server_uint_property_cb callback_uint;
37+ gpointer data;
38+};
39+
40+/* This does the actual work of calling the callbacks. It's split out
41+ so that we can use it in the DBus function callback but also in the
42+ case where we already have the cached value. */
43+static void
44+get_server_property_work (get_server_prop_data_t * prop_t, GVariant * prop)
45+{
46+ if (prop == NULL) {
47+ if (prop_t->callback == NULL) {
48+ prop_t->callback_uint(prop_t->listener, prop_t->server, 0, prop_t->data);
49+ } else {
50+ prop_t->callback(prop_t->listener, prop_t->server, NULL, prop_t->data);
51+ }
52+ return;
53+ }
54+
55+ if (g_variant_is_of_type(prop, G_VARIANT_TYPE_STRING) && prop_t->callback != NULL) {
56+ prop_t->callback(prop_t->listener, prop_t->server, g_variant_get_string(prop, NULL), prop_t->data);
57+ } else if (g_variant_is_of_type(prop, G_VARIANT_TYPE_OBJECT_PATH) && prop_t->callback != NULL) {
58+ prop_t->callback(prop_t->listener, prop_t->server, g_variant_get_string(prop, NULL), prop_t->data);
59+ } else if (g_variant_is_of_type(prop, G_VARIANT_TYPE_UINT32) && prop_t->callback_uint != NULL) {
60+ prop_t->callback_uint(prop_t->listener, prop_t->server, g_variant_get_uint32(prop), prop_t->data);
61+ } else {
62+ g_warning("Really? This can't happen. WTF! %s", g_variant_get_type_string(prop));
63+ }
64+
65+ return;
66+}
67+
68+/* Callback from getting the property off of DBus. Try to complete
69+ the call and then pass it up to the worker, clearing out the
70+ memory allocations caused here. */
71+static void
72+get_server_property_cb (GObject * obj, GAsyncResult * res, gpointer user_data)
73+{
74+ GError * error = NULL;
75+ get_server_prop_data_t * prop_t = (get_server_prop_data_t *)user_data;
76+
77+ GVariant * prop = g_dbus_connection_call_finish(G_DBUS_CONNECTION(obj), res, &error);
78+ if (error != NULL) {
79+ g_warning("Error getting property! %s", error->message);
80+ g_error_free(error);
81+ }
82+
83+ GVariant * unwrap = NULL;
84+ if (prop != NULL) {
85+ unwrap = g_variant_get_child_value(prop, 0);
86+ }
87+
88+ if (unwrap != NULL && g_variant_is_of_type(unwrap, G_VARIANT_TYPE_VARIANT)) {
89+ get_server_property_work(prop_t, g_variant_get_variant(unwrap));
90+ } else {
91+ get_server_property_work(prop_t, NULL);
92+ }
93+
94+ if (prop != NULL) {
95+ g_variant_unref(prop);
96+ }
97+
98+ g_object_unref(G_OBJECT(prop_t->listener));
99+ g_free(prop_t);
100+ return;
101+}
102+
103 /* This is a helper function for all the functions that
104 get properties from the server. They all need to have
105 a callback setup with an intermediary data structure
106@@ -1225,26 +1302,31 @@
107 static void
108 get_server_property (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_property_cb callback, indicate_listener_get_server_uint_property_cb callback_uint, const gchar * property_name, gpointer data)
109 {
110- GVariant * prop = g_dbus_proxy_get_cached_property(server->proxy, property_name);
111-
112- if (prop == NULL) {
113- if (callback == NULL) {
114- callback_uint(listener, server, 0, data);
115- } else {
116- callback(listener, server, NULL, data);
117- }
118- return;
119- }
120-
121- if (g_variant_is_of_type(prop, G_VARIANT_TYPE_STRING) && callback != NULL) {
122- callback(listener, server, g_variant_get_string(prop, NULL), data);
123- } else if (g_variant_is_of_type(prop, G_VARIANT_TYPE_OBJECT_PATH) && callback != NULL) {
124- callback(listener, server, g_variant_get_string(prop, NULL), data);
125- } else if (g_variant_is_of_type(prop, G_VARIANT_TYPE_UINT32) && callback_uint != NULL) {
126- callback_uint(listener, server, g_variant_get_uint32(prop), data);
127- } else {
128- g_warning("Really? This can't happen. WTF! %s", g_variant_get_type_string(prop));
129- }
130+ IndicateListenerPrivate * priv = INDICATE_LISTENER_GET_PRIVATE(listener);
131+ get_server_prop_data_t * prop_t = g_new0(get_server_prop_data_t, 1);
132+
133+ prop_t->listener = listener;
134+ prop_t->server = server;
135+ prop_t->callback = callback;
136+ prop_t->callback_uint = callback_uint;
137+ prop_t->data = data;
138+
139+ g_object_ref(G_OBJECT(listener));
140+
141+ /* If we don't have the property cached, let's go and find
142+ it on the bus. */
143+ g_dbus_connection_call(priv->session_bus,
144+ g_dbus_proxy_get_name(server->proxy),
145+ g_dbus_proxy_get_object_path(server->proxy),
146+ "org.freedesktop.DBus.Properties",
147+ "Get",
148+ g_variant_new("(ss)", INDICATE_DBUS_IFACE, property_name),
149+ G_VARIANT_TYPE("(v)"),
150+ G_DBUS_CALL_FLAGS_NONE,
151+ -1,
152+ NULL,
153+ get_server_property_cb,
154+ prop_t);
155
156 return;
157 }

Subscribers

People subscribed via source and target branches

to all changes: