diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2012-12-29 13:24:17 -0800 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2012-12-29 14:49:38 -0800 |
commit | f9f6536b2ba73d21a4cfa4a78d845f5840717946 (patch) | |
tree | 2c9270fdff41b2b8d17a0a9a9583383e4e698501 /gdbus/client.c | |
parent | 816c028a94325800476da364c970a8b7a8201003 (diff) | |
download | ofono-f9f6536b2ba73d21a4cfa4a78d845f5840717946.tar.bz2 |
gdbus: Add function to manually refresh properties
Diffstat (limited to 'gdbus/client.c')
-rw-r--r-- | gdbus/client.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/gdbus/client.c b/gdbus/client.c index 4c3bad6e..4d1970bc 100644 --- a/gdbus/client.c +++ b/gdbus/client.c @@ -497,6 +497,89 @@ gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name, return TRUE; } +struct refresh_property_data { + GDBusProxy *proxy; + char *name; +}; + +static void refresh_property_free(gpointer user_data) +{ + struct refresh_property_data *data = user_data; + + g_free(data->name); + g_free(data); +} + +static void refresh_property_reply(DBusPendingCall *call, void *user_data) +{ + struct refresh_property_data *data = user_data; + DBusMessage *reply = dbus_pending_call_steal_reply(call); + DBusError error; + + dbus_error_init(&error); + + if (dbus_set_error_from_message(&error, reply) == FALSE) { + DBusMessageIter iter; + + dbus_message_iter_init(reply, &iter); + + add_property(data->proxy, data->name, &iter); + } else + dbus_error_free(&error); + + dbus_message_unref(reply); +} + +gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name) +{ + struct refresh_property_data *data; + GDBusClient *client; + DBusMessage *msg; + DBusMessageIter iter; + DBusPendingCall *call; + + if (proxy == NULL || name == NULL) + return FALSE; + + client = proxy->client; + if (client == NULL) + return FALSE; + + data = g_try_new0(struct refresh_property_data, 1); + if (data == NULL) + return FALSE; + + data->proxy = proxy; + data->name = g_strdup(name); + + msg = dbus_message_new_method_call(client->service_name, + proxy->obj_path, DBUS_INTERFACE_PROPERTIES, "Get"); + if (msg == NULL) { + refresh_property_free(data); + return FALSE; + } + + dbus_message_iter_init_append(msg, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, + &proxy->interface); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name); + + if (dbus_connection_send_with_reply(client->dbus_conn, msg, + &call, -1) == FALSE) { + dbus_message_unref(msg); + refresh_property_free(data); + return FALSE; + } + + dbus_pending_call_set_notify(call, refresh_property_reply, + data, refresh_property_free); + dbus_pending_call_unref(call); + + dbus_message_unref(msg); + + return TRUE; +} + struct set_property_data { GDBusResultFunction function; void *user_data; |