From: taemin.yeom Date: Mon, 8 Mar 2021 08:23:27 +0000 (+0900) Subject: Restore gdbus APIs based on va_list X-Git-Tag: accepted/tizen/unified/20210310.145057^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f2162bc7cb174f59357b416701f84123289f1a4a;p=platform%2Fcore%2Fsystem%2Flibsyscommon.git Restore gdbus APIs based on va_list Change-Id: I9c275d6c652ac4253d3058fa3c022340ca55c6cd Signed-off-by: taemin.yeom --- diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index 2b3fbb5..45b0874 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -1852,6 +1852,110 @@ int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char return 0; } +int dbus_handle_method_sync_pairs(const char *dest, + const char *path, + const char *iface, + const char *method, + int num, + va_list args) +{ + GError *err = NULL; + GVariant * reply = NULL; + char *key, *value; + int ret = 0; + GVariant *var; + GVariantBuilder *builder; + dbus_handle_s *dh = NULL; + + if (!dest || !path || !iface || !method) { + _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); + 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 -1; + } + + 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); + } + + var = g_variant_new("(a{ss})", builder); + g_variant_builder_unref(builder); + + reply = g_dbus_connection_call_sync(dh->conn, + dest, path, iface, method, + var, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); + if (!reply || err) { + _E("failed to g_dbus_connection_call_sync"); + return -1; + } + + if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) + g_variant_get(reply, "(i)", &ret); + else + ret = -ENOMSG; + + g_variant_unref(reply); + + return ret; +} + +int dbus_handle_method_async_pairs(const char *dest, + const char *path, + const char *iface, + const char *method, + int num, + va_list args) +{ + char *key, *value; + GVariant *var; + GVariantBuilder *builder; + dbus_handle_s *dh = NULL; + + if (!dest || !path || !iface || !method) { + _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); + 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 -1; + } + + // 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); + } + + var = g_variant_new("(a{ss})", builder); + g_variant_builder_unref(builder); + + g_dbus_connection_call(dh->conn, + dest, path, iface, method, + var, NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); + + return 0; +} + gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size) { GUnixFDList *fd_list = NULL; @@ -2117,6 +2221,78 @@ err: return ret; } +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_connection_get_sender_pid(GDBusConnection *conn, const char * sender) { GError *err = NULL; diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index 0b831da..c707d19 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -137,6 +137,30 @@ int dbus_handle_method_sync_with_reply_var_timeout (const char *dest, GVariant **reply, int timeout); +int dbus_handle_method_sync_pairs (const char *dest, + const char *path, + const char *interface, + const char *method, + int num, + va_list args); + +int dbus_handle_method_async_pairs (const char *dest, + const char *path, + const char *interface, + const char *method, + int num, + va_list args); + +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); + gint* dbus_handle_get_unix_fd_list (GDBusMethodInvocation *invocation, int *size);