dbus: add GVariant support api 77/222777/1
authorsanghyeok.oh <sanghyeok.oh@samsung.com>
Mon, 6 Jan 2020 09:00:19 +0000 (18:00 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Mon, 20 Jan 2020 04:32:15 +0000 (04:32 +0000)
Change-Id: Iac13dfbb5cf6044c9becb225cc6c217ab1483866
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
(cherry picked from commit fbc92ec4b490aa0a2afeb888a5f594c36b9484dc)

src/dbus.c
src/dbus.h

index 0dcb159..9307911 100644 (file)
@@ -64,7 +64,7 @@ static int g_dbus_error_to_errno(int code)
 }
 //LCOV_EXCL_STOP
 
-static GVariant *append_g_variant(const char *sig, char *param[])
+static GVariant *append_g_variant(const char *sig, const char *param[])
 {
        GVariantBuilder builder;
        GVariantBuilder *sub_builder;
@@ -242,66 +242,8 @@ static GDBusProxy *get_proxy_from_proxy_pool(const char *dest,
        return proxy;
 }
 
-int dbus_method_sync(const char *dest, const char *path,
-               const char *interface, const char *method,
-               const char *sig, char *param[])
-{
-       GDBusProxy *proxy;
-       GError *err = NULL;
-       GVariant *output;
-       int result;
-
-#if !GLIB_CHECK_VERSION(2, 35, 0)
-       g_type_init();
-#endif
-
-       pthread_mutex_lock(&dmutex);
-       proxy = get_proxy_from_proxy_pool(dest, path, interface, &err);
-       if (!proxy) {
-//LCOV_EXCL_START System Error
-               pthread_mutex_unlock(&dmutex);
-               _E("fail to get proxy from proxy pool : %s-%s (%d-%s)",
-                               interface, method, err->code, err->message);
-               result = g_dbus_error_to_errno(err->code);
-               g_clear_error(&err);
-               return result;
-//LCOV_EXCL_STOP
-       }
-
-       output = g_dbus_proxy_call_sync(proxy,
-                       method,                       /* method name */
-                       append_g_variant(sig, param), /* parameters */
-                       G_DBUS_CALL_FLAGS_NONE,
-                       DBUS_REPLY_TIMEOUT,           /* timeout */
-                       NULL,                         /* GCancellable */
-                       &err);
-       pthread_mutex_unlock(&dmutex);
-
-       if (!output) {
-//LCOV_EXCL_START System Error
-               if (!err) {
-                       _E("g_dbus_proxy_call_sync error : %s-%s",
-                                       interface, method);
-                       return -EPERM;
-               }
-               _E("g_dbus_proxy_call_sync error : %s-%s (%d-%s)",
-                               interface, method, err->code, err->message);
-               result = g_dbus_error_to_errno(err->code);
-               g_clear_error(&err);
-               return result;
-//LCOV_EXCL_STOP
-       }
-
-       /* get output value */
-       g_variant_get(output, "(i)", &result);
-
-       g_variant_unref(output);
-
-       return result;
-}
-
 int dbus_method_sync_var(const char *dest, const char *path,
-               const char *interface, const char *method, GVariant *var)
+               const char *interface, const char *method, GVariant *param)
 {
        GDBusProxy *proxy;
        GError *err = NULL;
@@ -326,7 +268,7 @@ int dbus_method_sync_var(const char *dest, const char *path,
 //LCOV_EXCL_STOP
        output = g_dbus_proxy_call_sync(proxy,
                        method,                       /* method name */
-                       var, /* parameters */
+                       param, /* parameters */
                        G_DBUS_CALL_FLAGS_NONE,
                        DBUS_REPLY_TIMEOUT,           /* timeout */
                        NULL,                         /* GCancellable */
@@ -356,10 +298,20 @@ int dbus_method_sync_var(const char *dest, const char *path,
        return result;
 }
 
-int dbus_method_sync_with_reply(const char *dest,
+int dbus_method_sync(const char *dest, const char *path,
+               const char *interface, const char *method,
+               const char *sig, const char *param[])
+{
+       return dbus_method_sync_var(dest,
+                               path,
+                               interface,
+                               method,
+                               append_g_variant(sig, param));
+}
+
+int dbus_method_sync_with_reply_var(const char *dest,
                const char *path, const char *interface,
-               const char *method, const char *sig,
-               char *param[], GVariant **info)
+               const char *method, GVariant *param, GVariant **info)
 {
        GDBusProxy *proxy;
        GError *err = NULL;
@@ -385,7 +337,7 @@ int dbus_method_sync_with_reply(const char *dest,
 
        output = g_dbus_proxy_call_sync(proxy,
                        method,                       /* method name */
-                       append_g_variant(sig, param), /* parameters */
+                       param, /* parameters */
                        G_DBUS_CALL_FLAGS_NONE,
                        DBUS_REPLY_TIMEOUT,           /* timeout */
                        NULL,                         /* GCancellable */
@@ -410,6 +362,19 @@ int dbus_method_sync_with_reply(const char *dest,
        return DEVICE_ERROR_NONE;
 }
 
+int dbus_method_sync_with_reply(const char *dest,
+               const char *path, const char *interface,
+               const char *method, const char *sig,
+               const char *param[], GVariant **info)
+{
+       return dbus_method_sync_with_reply_var(dest,
+                               path,
+                               interface,
+                               method,
+                               append_g_variant(sig, param),
+                               info);
+}
+
 static void cb_pending(GDBusProxy *proxy,
                GAsyncResult *res,
                gpointer user_data)
@@ -437,9 +402,9 @@ static void cb_pending(GDBusProxy *proxy,
                g_variant_unref(output);
 }
 
-int dbus_method_async_with_reply(const char *dest, const char *path,
+int dbus_method_async_with_reply_var(const char *dest, const char *path,
                const char *interface, const char *method,
-               const char *sig, char *param[],
+               GVariant *param,
                dbus_pending_cb cb, int timeout, void *data)
 {
        GDBusProxy *proxy;
@@ -477,7 +442,7 @@ int dbus_method_async_with_reply(const char *dest, const char *path,
 
        g_dbus_proxy_call(proxy,
                        method,                          /* method name */
-                       append_g_variant(sig, param),    /* parameters */
+                       param,    /* parameters */
                        G_DBUS_CALL_FLAGS_NONE,
                        DBUS_REPLY_TIMEOUT,              /* timeout */
                        NULL,                            /* GCancellable */
@@ -488,6 +453,21 @@ int dbus_method_async_with_reply(const char *dest, const char *path,
        return 0;
 }
 
+int dbus_method_async_with_reply(const char *dest, const char *path,
+               const char *interface, const char *method,
+               const char *sig, const char *param[],
+               dbus_pending_cb cb, int timeout, void *data)
+{
+       return dbus_method_async_with_reply_var(dest,
+                               path,
+                               interface,
+                               method,
+                               append_g_variant(sig, param),
+                               cb,
+                               timeout,
+                               data);
+}
+
 //LCOV_EXCL_START Not called Callback
 static void haptic_signal_callback(GDBusConnection *conn,
                const gchar *sender,
index 72ad857..c721d3b 100644 (file)
@@ -71,15 +71,18 @@ struct dbus_int {
        int size;
 };
 
+int dbus_method_sync_var(const char *dest, const char *path,
+               const char *interface, const char *method, GVariant *param);
 int dbus_method_sync(const char *dest, const char *path,
                const char *interface, const char *method,
-               const char *sig, char *param[]);
+               const char *sig, const char *param[]);
+int dbus_method_sync_with_reply_var(const char *dest,
+               const char *path, const char *interface,
+               const char *method, GVariant *param, GVariant **info);
 int dbus_method_sync_with_reply(const char *dest,
                const char *path, const char *interface,
                const char *method, const char *sig,
-               char *param[], GVariant **info);
-int dbus_method_sync_var(const char *dest, const char *path,
-       const char *iface, const char *method, GVariant *var);
+               const char *param[], GVariant **info);
 
 /**
  * If result is NULL, err is set.
@@ -87,9 +90,13 @@ int dbus_method_sync_var(const char *dest, const char *path,
  */
 typedef void (*dbus_pending_cb)(void *data, GVariant *result, GError *err);
 
+int dbus_method_async_with_reply_var(const char *dest, const char *path,
+               const char *interface, const char *method,
+               GVariant *param,
+               dbus_pending_cb cb, int timeout, void *data);
 int dbus_method_async_with_reply(const char *dest, const char *path,
                const char *interface, const char *method,
-               const char *sig, char *param[], dbus_pending_cb cb, int timeout, void *data);
+               const char *sig, const char *param[], dbus_pending_cb cb, int timeout, void *data);
 
 void restart_callback(void);