summaryrefslogtreecommitdiff
path: root/gdbus
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2012-12-14 15:19:53 +0100
committerMarcel Holtmann <marcel@holtmann.org>2012-12-19 03:49:11 +0100
commitebae80d0e56a216a6f50e5792d42dd721889f621 (patch)
tree1044f406f4d3bca593c250d24a1a0fe20bc596c7 /gdbus
parent43e6eaabc6085b331a6850627615c49ab71dd0d4 (diff)
downloadconnman-ebae80d0e56a216a6f50e5792d42dd721889f621.tar.gz
connman-ebae80d0e56a216a6f50e5792d42dd721889f621.tar.bz2
connman-ebae80d0e56a216a6f50e5792d42dd721889f621.zip
gdbus: Add support for setting D-Bus client basic properties
Diffstat (limited to 'gdbus')
-rw-r--r--gdbus/client.c92
-rw-r--r--gdbus/gdbus.h7
2 files changed, 99 insertions, 0 deletions
diff --git a/gdbus/client.c b/gdbus/client.c
index 7def1f57..c489c601 100644
--- a/gdbus/client.c
+++ b/gdbus/client.c
@@ -262,6 +262,98 @@ gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
return TRUE;
}
+struct set_property_data {
+ GDBusResultFunction function;
+ void *user_data;
+ GDBusDestroyFunction destroy;
+};
+
+static void set_property_reply(DBusPendingCall *call, void *user_data)
+{
+ struct set_property_data *data = user_data;
+ DBusMessage *reply = dbus_pending_call_steal_reply(call);
+ DBusError error;
+
+ dbus_error_init(&error);
+
+ dbus_set_error_from_message(&error, reply);
+
+ if (data->function)
+ data->function(&error, data->user_data);
+
+ if (data->destroy)
+ data->destroy(data->user_data);
+
+ dbus_error_free(&error);
+
+ dbus_message_unref(reply);
+}
+
+gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
+ const char *name, int type, const void *value,
+ GDBusResultFunction function, void *user_data,
+ GDBusDestroyFunction destroy)
+{
+ struct set_property_data *data;
+ GDBusClient *client;
+ DBusMessage *msg;
+ DBusMessageIter iter, variant;
+ DBusPendingCall *call;
+ char type_as_str[2];
+
+ if (proxy == NULL || name == NULL || value == NULL)
+ return FALSE;
+
+ if (dbus_type_is_basic(type) == FALSE)
+ return FALSE;
+
+ client = proxy->client;
+ if (client == NULL)
+ return FALSE;
+
+ data = g_try_new0(struct set_property_data, 1);
+ if (data == NULL)
+ return FALSE;
+
+ data->function = function;
+ data->user_data = user_data;
+ data->destroy = destroy;
+
+ msg = dbus_message_new_method_call(client->service_name,
+ proxy->obj_path, DBUS_INTERFACE_PROPERTIES, "Set");
+ if (msg == NULL) {
+ g_free(data);
+ return FALSE;
+ }
+
+ type_as_str[0] = (char) type;
+ type_as_str[1] = '\0';
+
+ 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);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+ type_as_str, &variant);
+ dbus_message_iter_append_basic(&variant, type, value);
+ dbus_message_iter_close_container(&iter, &variant);
+
+ if (dbus_connection_send_with_reply(client->dbus_conn, msg,
+ &call, -1) == FALSE) {
+ dbus_message_unref(msg);
+ g_free(data);
+ return FALSE;
+ }
+
+ dbus_pending_call_set_notify(call, set_property_reply, data, g_free);
+ dbus_pending_call_unref(call);
+
+ dbus_message_unref(msg);
+
+ return TRUE;
+}
+
static void add_property(GDBusProxy *proxy, const char *name,
DBusMessageIter *iter)
{
diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index a0ca173a..fa978db6 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -279,6 +279,13 @@ const char *g_dbus_proxy_get_interface(GDBusProxy *proxy);
gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
DBusMessageIter *iter);
+typedef void (* GDBusResultFunction) (const DBusError *error, void *user_data);
+
+gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
+ const char *name, int type, const void *value,
+ GDBusResultFunction function, void *user_data,
+ GDBusDestroyFunction destroy);
+
typedef struct GDBusClient GDBusClient;
GDBusClient *g_dbus_client_new(DBusConnection *connection,