Merge lp:~agateau/libindicate/gvalue into lp:libindicate/0.6

Proposed by Aurélien Gâteau
Status: Merged
Merged at revision: not available
Proposed branch: lp:~agateau/libindicate/gvalue
Merge into: lp:libindicate/0.6
Diff against target: 102 lines (+43/-0)
3 files modified
libindicate/listener.c (+28/-0)
libindicate/listener.h (+7/-0)
libindicate/server.c (+8/-0)
To merge this branch: bzr merge lp:~agateau/libindicate/gvalue
Reviewer Review Type Date Requested Status
Ted Gould (community) Needs Information
Review via email: mp+19336@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Aurélien Gâteau (agateau) wrote :

Make it possible to get the GValue for a property.

This is useful to implement a generic way to retrieve all values as indicate_listener_get_property() now fails on a int or bool property.

I also removed the return which prevented the property callback from being called when there is an error (such as a missing property) as it was preventing me using the library in this way:

- ask for property1
- wait for callback
- process property1 value
- ask for property2
...

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

On Mon, 2010-02-15 at 14:48 +0000, Aurélien Gâteau wrote:
> Make it possible to get the GValue for a property.

Oops, can't believe I forgot this.

> I also removed the return which prevented the property callback
> from being called when there is an error (such as a missing
> property) as it was preventing me using the library in this way:
>
> - ask for property1
> - wait for callback
> - process property1 value
> - ask for property2
> ....

I'm worried that this will cause indeterminate results. Do you think
that we should call the callback with "known" values in this case as the
value of GValue * is indeterminate if error is set?

I'm also worried that this might break a lot of applications who have
expected this behavior and don't handle errors in their callback.

  review needs-info

review: Needs Information
lp:~agateau/libindicate/gvalue updated
367. By Aurélien Gâteau

Revert r366: "Call the callback, even if there is an error"

Revision history for this message
Aurélien Gâteau (agateau) wrote :

I reverted the previous revision which could lead to indeterminate results.

lp:~agateau/libindicate/gvalue updated
368. By Aurélien Gâteau

Set GError when a property cannot be found

Revision history for this message
Aurélien Gâteau (agateau) wrote :

Now with more friendly messages than: "Method invoked for GetIndicatorProperty returned FALSE but did not set error" :)

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 2010-02-10 14:44:22 +0000
3+++ libindicate/listener.c 2010-02-16 09:45:26 +0000
4@@ -712,6 +712,7 @@
5
6 typedef enum _get_property_type get_property_type;
7 enum _get_property_type {
8+ PROPERTY_TYPE_VALUE,
9 PROPERTY_TYPE_STRING,
10 PROPERTY_TYPE_TIME,
11 PROPERTY_TYPE_INT,
12@@ -749,6 +750,12 @@
13 }
14
15 switch (get_property_data->type) {
16+ case PROPERTY_TYPE_VALUE: {
17+ /* Just pass the GValue along. */
18+ indicate_listener_get_property_value_cb cb =(indicate_listener_get_property_value_cb)get_property_data->cb;
19+ cb(get_property_data->listener, get_property_data->server, get_property_data->indicator, get_property_data->property, &OUT_value, get_property_data->data);
20+ break;
21+ }
22 case PROPERTY_TYPE_STRING: {
23 /* Just pass the string along. */
24 indicate_listener_get_property_cb cb = (indicate_listener_get_property_cb)get_property_data->cb;
25@@ -807,6 +814,27 @@
26 }
27
28 /**
29+ indicate_listener_get_property_value:
30+ @listener: The #IndicateListener representing the connection
31+ @server: The server that the indicator is on
32+ @indicator: Which indicator is being queried
33+ @property: Name of the property to get
34+ @callback: The callback function to call with the data
35+ @data: Arbitrary data to give the callback
36+
37+ A function to get a property from an indicator on a server
38+ and bring it back locally. This wraps all the hassle of using
39+ the DBus API and makes it pretty easy to get properties.
40+
41+ This function gets the raw gvalue data, without any conversion.
42+*/
43+void
44+indicate_listener_get_property_value (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, indicate_listener_get_property_value_cb callback, gpointer data)
45+{
46+ return get_property_helper(listener, server, indicator, property, G_CALLBACK(callback), data, PROPERTY_TYPE_VALUE);
47+}
48+
49+/**
50 indicate_listener_get_property:
51 @listener: The #IndicateListener representing the connection
52 @server: The server that the indicator is on
53
54=== modified file 'libindicate/listener.h'
55--- libindicate/listener.h 2010-02-04 22:41:43 +0000
56+++ libindicate/listener.h 2010-02-16 09:45:26 +0000
57@@ -111,6 +111,7 @@
58
59 GType indicate_listener_get_type (void) G_GNUC_CONST;
60
61+typedef void (*indicate_listener_get_property_value_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const GValue * propertydata, gpointer data);
62 typedef void (*indicate_listener_get_property_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const gchar * propertydata, gpointer data);
63 typedef void (*indicate_listener_get_property_time_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const GTimeVal * propertydata, gpointer data);
64 typedef void (*indicate_listener_get_property_int_cb) (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gint propertydata, gpointer data);
65@@ -121,6 +122,12 @@
66 /* Create a new listener */
67 IndicateListener * indicate_listener_new (void);
68 IndicateListener * indicate_listener_ref_default (void);
69+void indicate_listener_get_property_value (IndicateListener * listener,
70+ IndicateListenerServer * server,
71+ IndicateListenerIndicator * indicator,
72+ gchar * property,
73+ indicate_listener_get_property_value_cb callback,
74+ gpointer data);
75 void indicate_listener_get_property (IndicateListener * listener,
76 IndicateListenerServer * server,
77 IndicateListenerIndicator * indicator,
78
79=== modified file 'libindicate/server.c'
80--- libindicate/server.c 2010-02-10 14:27:48 +0000
81+++ libindicate/server.c 2010-02-16 09:45:26 +0000
82@@ -52,6 +52,7 @@
83 REMOVE_INTEREST_FAILED,
84 NO_MAX_INDICATORS_SET,
85 MAX_INDICATORS_SET_FAILED,
86+ NO_SUCH_PROPERTY,
87 LAST_ERROR
88 };
89
90@@ -1259,6 +1260,13 @@
91
92 const GValue * ind_property = indicate_indicator_get_property_value(indicator, property);
93 if (ind_property == NULL) {
94+ if (error) {
95+ g_set_error(error,
96+ indicate_server_error_quark(),
97+ NO_SUCH_PROPERTY,
98+ "Indicator %d has no property named '%s'",
99+ id, property);
100+ }
101 return FALSE;
102 }
103

Subscribers

People subscribed via source and target branches