Merge lp:~ted/libindicate/extra-funcs into lp:libindicate/0.6
- extra-funcs
- Merge into trunk
Proposed by
Ted Gould
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~ted/libindicate/extra-funcs |
Merge into: | lp:libindicate/0.6 |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~ted/libindicate/extra-funcs |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Barth | Approve | ||
Review via email: mp+11376@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote : | # |
lp:~ted/libindicate/extra-funcs
updated
Revision history for this message
Ted Gould (ted) wrote : | # |
Merged in another bug fix branch so that it has all kinds of good stuff in it. If you want to test on your system try building a package from this branch:
lp:~ted/libindicate/extra-funcs.ubuntu
The branch has been updated since the code review was requested, so don't use the diff below.
Revision history for this message
David Barth (dbarth) wrote : | # |
Ok, the changes are sound to me. The comments do help understand the code, despite its complexity.
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'libindicate/listener-marshal.list' |
2 | --- libindicate/listener-marshal.list 2009-08-28 20:38:15 +0000 |
3 | +++ libindicate/listener-marshal.list 2009-09-05 04:24:47 +0000 |
4 | @@ -33,3 +33,5 @@ |
5 | VOID:POINTER,POINTER,STRING |
6 | # Local server_added and server_removed |
7 | VOID:POINTER,STRING |
8 | +# Local server_count_changed |
9 | +VOID:POINTER,UINT |
10 | |
11 | === modified file 'libindicate/listener.c' |
12 | --- libindicate/listener.c 2009-09-04 02:58:25 +0000 |
13 | +++ libindicate/listener.c 2009-09-05 16:38:55 +0000 |
14 | @@ -49,6 +49,7 @@ |
15 | INDICATOR_MODIFIED, |
16 | SERVER_ADDED, |
17 | SERVER_REMOVED, |
18 | + SERVER_COUNT_CHANGED, |
19 | LAST_SIGNAL |
20 | }; |
21 | |
22 | @@ -102,6 +103,7 @@ |
23 | static void proxy_indicator_added (DBusGProxy * proxy, guint id, proxy_t * proxyt); |
24 | static void proxy_indicator_removed (DBusGProxy * proxy, guint id, proxy_t * proxyt); |
25 | static void proxy_indicator_modified (DBusGProxy * proxy, guint id, const gchar * property, proxy_t * proxyt); |
26 | +static void proxy_server_count_changed (DBusGProxy * proxy, guint count, proxy_t * proxyt); |
27 | static void proxy_get_indicator_list (DBusGProxy * proxy, GArray * indicators, GError * error, gpointer data); |
28 | static void proxy_get_indicator_type (DBusGProxy * proxy, gchar * type, GError * error, gpointer data); |
29 | static void introspect_this (DBusGProxy * proxy, char * OUT_data, GError * error, gpointer data); |
30 | @@ -159,6 +161,13 @@ |
31 | NULL, NULL, |
32 | _indicate_listener_marshal_VOID__POINTER_STRING, |
33 | G_TYPE_NONE, 2, INDICATE_TYPE_LISTENER_SERVER, G_TYPE_STRING); |
34 | + signals[SERVER_COUNT_CHANGED] = g_signal_new(INDICATE_LISTENER_SIGNAL_SERVER_COUNT_CHANGED, |
35 | + G_TYPE_FROM_CLASS (class), |
36 | + G_SIGNAL_RUN_LAST, |
37 | + G_STRUCT_OFFSET (IndicateListenerClass, server_count_changed), |
38 | + NULL, NULL, |
39 | + _indicate_listener_marshal_VOID__POINTER_UINT, |
40 | + G_TYPE_NONE, 2, INDICATE_TYPE_LISTENER_SERVER, G_TYPE_UINT); |
41 | |
42 | dbus_g_object_register_marshaller(_indicate_listener_marshal_VOID__UINT_STRING, |
43 | G_TYPE_NONE, |
44 | @@ -587,6 +596,10 @@ |
45 | G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID); |
46 | dbus_g_proxy_connect_signal(proxyt->proxy, "IndicatorModified", |
47 | G_CALLBACK(proxy_indicator_modified), proxyt, NULL); |
48 | + dbus_g_proxy_add_signal(proxyt->proxy, "ServerCountChanged", |
49 | + G_TYPE_UINT, G_TYPE_INVALID); |
50 | + dbus_g_proxy_connect_signal(proxyt->proxy, "ServerCountChanged", |
51 | + G_CALLBACK(proxy_server_count_changed), proxyt, NULL); |
52 | |
53 | if (type != NULL) { |
54 | if (proxyt->type != NULL) { |
55 | @@ -663,6 +676,17 @@ |
56 | return; |
57 | } |
58 | |
59 | +/* This function gets called when the dbus count |
60 | + signal comes it. Basically we're just translating |
61 | + it into a local signal with the appropraite parameters |
62 | + and structures. */ |
63 | +static void |
64 | +proxy_server_count_changed (DBusGProxy * proxy, guint count, proxy_t * proxyt) |
65 | +{ |
66 | + g_signal_emit(proxyt->listener, signals[SERVER_COUNT_CHANGED], 0, &proxyt->server, count, TRUE); |
67 | + return; |
68 | +} |
69 | + |
70 | typedef enum _get_property_type get_property_type; |
71 | enum _get_property_type { |
72 | PROPERTY_TYPE_STRING, |
73 | @@ -812,9 +836,14 @@ |
74 | IndicateListener * listener; |
75 | IndicateListenerServer * server; |
76 | indicate_listener_get_server_property_cb cb; |
77 | + indicate_listener_get_server_uint_property_cb cb_uint; |
78 | gpointer data; |
79 | } property_cb_t; |
80 | |
81 | +/* A callback from getting the property off of the server |
82 | + which unravels the property_cb_t structure that was passed |
83 | + as data and calls back the call back that was in it with |
84 | + the appropriate data, also unrolled. */ |
85 | static void |
86 | property_cb (DBusGProxy * proxy, DBusGProxyCall * call, void * data) |
87 | { |
88 | @@ -824,6 +853,9 @@ |
89 | |
90 | GValue property = {0}; |
91 | |
92 | + /* Finish the call and get our value. There might |
93 | + be an error as if someone was using v1 API and |
94 | + not v2. Let's handle that early. */ |
95 | dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_VALUE, &property, G_TYPE_INVALID); |
96 | if (error != NULL) { |
97 | /* g_warning("Unable to get property: %s", error->message); */ |
98 | @@ -832,28 +864,42 @@ |
99 | return; |
100 | } |
101 | |
102 | - if (!G_VALUE_HOLDS_STRING(&property)) { |
103 | - g_warning("Property returned is not a string!"); |
104 | - g_free(propertyt); |
105 | - return; |
106 | - } |
107 | - |
108 | + /* Dup all the values and make them local so that |
109 | + we can free up the data structure to make the |
110 | + rest of the code easier to read. */ |
111 | IndicateListener * listener = propertyt->listener; |
112 | IndicateListenerServer * server = propertyt->server; |
113 | indicate_listener_get_server_property_cb cb = propertyt->cb; |
114 | + indicate_listener_get_server_uint_property_cb cb_uint = propertyt->cb_uint; |
115 | gpointer cb_data = propertyt->data; |
116 | |
117 | g_free(propertyt); |
118 | |
119 | - gchar * propstr = g_value_dup_string(&property); |
120 | - |
121 | - /* g_debug("\tProperty value: %s", propstr); */ |
122 | - |
123 | - return cb(listener, server, propstr, cb_data); |
124 | + if (G_VALUE_HOLDS_STRING(&property) && cb != NULL) { |
125 | + /* If it's got a string, and we have a value for that |
126 | + we'll get the string out and call the call back */ |
127 | + gchar * propstr = g_value_dup_string(&property); |
128 | + return cb(listener, server, propstr, cb_data); |
129 | + } else if (G_VALUE_HOLDS_UINT(&property) && cb_uint != NULL) { |
130 | + /* If it's got a UINT and we have a callback for that |
131 | + let's grab the value and call the callback. */ |
132 | + guint val = g_value_get_uint(&property); |
133 | + return cb_uint(listener, server, val, cb_data); |
134 | + } else { |
135 | + /* WTF!?!?!?! */ |
136 | + g_warning("Property back from server that we didn't understand."); |
137 | + } |
138 | + |
139 | + return; |
140 | } |
141 | |
142 | +/* This is a helper function for all the functions that |
143 | + get properties from the server. They all need to have |
144 | + a callback setup with an intermediary data structure |
145 | + and this function builds and populates that, then uses |
146 | + a custom callback to call their callback */ |
147 | static void |
148 | -get_server_property (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_property_cb callback, const gchar * property_name, gpointer data) |
149 | +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) |
150 | { |
151 | /* g_debug("Setting up callback for property %s on %s", property_name, INDICATE_LISTENER_SERVER_DBUS_NAME(server)); */ |
152 | IndicateListenerPrivate * priv = INDICATE_LISTENER_GET_PRIVATE(listener); |
153 | @@ -902,13 +948,19 @@ |
154 | void |
155 | indicate_listener_server_get_type (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_property_cb callback, gpointer data) |
156 | { |
157 | - return get_server_property(listener, server, callback, "type", data); |
158 | + return get_server_property(listener, server, callback, NULL, "type", data); |
159 | } |
160 | |
161 | void |
162 | indicate_listener_server_get_desktop (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_property_cb callback, gpointer data) |
163 | { |
164 | - return get_server_property(listener, server, callback, "desktop", data); |
165 | + return get_server_property(listener, server, callback, NULL, "desktop", data); |
166 | +} |
167 | + |
168 | +void |
169 | +indicate_listener_server_get_count (IndicateListener * listener, IndicateListenerServer * server, indicate_listener_get_server_uint_property_cb callback, gpointer data) |
170 | +{ |
171 | + return get_server_property(listener, server, NULL, callback, "count", data); |
172 | } |
173 | |
174 | const gchar * |
175 | |
176 | === modified file 'libindicate/listener.h' |
177 | --- libindicate/listener.h 2009-09-01 17:09:56 +0000 |
178 | +++ libindicate/listener.h 2009-09-05 16:38:55 +0000 |
179 | @@ -52,6 +52,7 @@ |
180 | #define INDICATE_LISTENER_SIGNAL_INDICATOR_MODIFIED "indicator-modified" |
181 | #define INDICATE_LISTENER_SIGNAL_SERVER_ADDED "server-added" |
182 | #define INDICATE_LISTENER_SIGNAL_SERVER_REMOVED "server-removed" |
183 | +#define INDICATE_LISTENER_SIGNAL_SERVER_COUNT_CHANGED "server-count-changed" |
184 | |
185 | #define INDICATE_LISTENER_SERVER_DBUS_NAME(server) (indicate_listener_server_get_dbusname(server)) |
186 | #define INDICATE_LISTENER_INDICATOR_ID(indicator) (indicate_listener_indicator_get_id(indicator)) |
187 | @@ -77,6 +78,7 @@ |
188 | @indicator_modified: Slot for IndicateListener::indicator-modified. |
189 | @server_added: Slot for IndicateListener::server-added. |
190 | @server_removed: Slot for IndicateListener::server-removed. |
191 | + @server_count_changed: Slot for IndicateListener::server-count-changed. |
192 | @indicate_listener_reserved1: Reserved for future use |
193 | @indicate_listener_reserved2: Reserved for future use |
194 | @indicate_listener_reserved3: Reserved for future use |
195 | @@ -97,6 +99,7 @@ |
196 | |
197 | void (* server_added) (IndicateListenerServer * server, gchar * type); |
198 | void (* server_removed) (IndicateListenerServer * server, gchar * type); |
199 | + void (* server_count_changed) (IndicateListenerServer * server, guint count); |
200 | |
201 | /* Future Use */ |
202 | void (*indicate_listener_reserved1)(void); |
203 | @@ -110,6 +113,7 @@ |
204 | typedef void (*indicate_listener_get_property_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data); |
205 | typedef void (*indicate_listener_get_property_time_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GTimeVal * propertydata, gpointer data); |
206 | typedef void (*indicate_listener_get_server_property_cb) (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data); |
207 | +typedef void (*indicate_listener_get_server_uint_property_cb) (IndicateListener * listener, IndicateListenerServer * server, guint value, gpointer data); |
208 | |
209 | /* Create a new listener */ |
210 | IndicateListener * indicate_listener_new (void); |
211 | @@ -141,6 +145,10 @@ |
212 | IndicateListenerServer * server, |
213 | indicate_listener_get_server_property_cb callback, |
214 | gpointer data); |
215 | +void indicate_listener_server_get_count (IndicateListener * listener, |
216 | + IndicateListenerServer * server, |
217 | + indicate_listener_get_server_uint_property_cb callback, |
218 | + gpointer data); |
219 | const gchar * indicate_listener_server_get_dbusname (IndicateListenerServer * server); |
220 | guint indicate_listener_indicator_get_id (IndicateListenerIndicator * indicator); |
221 | void indicate_listener_server_show_interest (IndicateListener * listener, |
Functions on getting the count that were forgotten.