mirror of git://git.sysmocom.de/ofono
gdbus: Add support for setting D-Bus client basic properties
This commit is contained in:
parent
37a3708928
commit
7ba21da7f3
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue