reply = g_dbus_connection_call_finish(conn, res, &err);
if (!reply || err) {
- if (err) {
- _E("no message : [%s]", err->message);
- g_error_free(err);
- } else {
- _E("no message");
- }
+ if (!err)
+ g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Error during g_dbus_connection_call");
if (data && data->func)
data->func(NULL, data->data, err);
if (data && data->func)
data->func(reply, data->data, err);
out:
+ if (err)
+ g_error_free(err);
if (data)
free(data);
}
+int dbus_handle_method_async_pairs_with_reply(const char *dest,
+ const char *path,
+ const char *iface,
+ const char *method,
+ int num,
+ va_list args,
+ dbus_pending_cb cb,
+ int timeout_msec,
+ void *data)
+{
+ dbus_handle_s *dh = NULL;
+ pending_call_data *pdata = NULL;
+ GVariantBuilder *builder;
+ char *key, *value;
+ GVariant *param;
+ int ret = 0;
+
+ if (!dest || !path || !iface || !method) {
+ _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method);
+ return -1;
+ }
+
+ if (timeout_msec < -1) {
+ _E("wrong timeout %d", timeout_msec);
+ return -1;
+ }
+
+ dh = _dbus_handle_get_default_connection();
+ if (!dh) {
+ _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type());
+ return -EPERM;
+ }
+
+ // dict
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}"));
+
+ for (int i = 0 ; i < num ; i = i + 2) {
+ key = va_arg(args, char *);
+ value = va_arg(args, char *);
+ _I("key(%s), value(%s)", key, value);
+ g_variant_builder_add(builder, "{ss}", key, value);
+ }
+
+ param = g_variant_new("(a{ss})", builder);
+ g_variant_builder_unref(builder);
+
+ if (cb) {
+ pdata = (pending_call_data*)malloc(sizeof(pending_call_data));
+ if (!pdata) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ pdata->func = cb;
+ pdata->data = data;
+ }
+ g_dbus_connection_call(dh->conn, dest, path, iface, method,
+ param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout_msec, NULL,
+ (GAsyncReadyCallback)_cb_pending,
+ pdata);
+
+ return ret;
+err:
+ if (param)
+ g_variant_unref(param);
+ return ret;
+}
+
int dbus_handle_method_async_with_reply(const char *dest,
const char *path,
const char *iface,