capi: Add ref count in comp-manager when initializing app
authorSaurav Babu <saurav.babu@samsung.com>
Thu, 5 Apr 2018 12:13:17 +0000 (17:43 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:49 +0000 (19:38 +0900)
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
capi/src/companion_dbus.c
capi/src/companion_gdbus.xml
capi/src/companion_private.h

index 9127a7b..0b0907a 100644 (file)
@@ -257,8 +257,10 @@ static void __request_result_cb(Group *object, gchar *cmd, gchar *arg, gint ret,
 
 static int _enabler_proxy_init(comp_manager_s *handle)
 {
-       int ret = COMP_ERROR_NONE;
        GError *error = NULL;
+       const gchar *name;
+       int ret;
+
        handle->enabler_proxy = enabler_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
                                                   G_DBUS_PROXY_FLAGS_NONE, COMP_DBUS_SERVICE,
                                                   COMP_DBUS_ENABLER_PATH, NULL, &error);
@@ -271,6 +273,30 @@ static int _enabler_proxy_init(comp_manager_s *handle)
                return COMP_ERROR_IO_ERROR;
                /* LCOV_EXCL_STOP */
        }
+
+       handle->system_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (NULL == handle->system_bus) {
+               /* LCOV_EXCL_START */
+               if (error != NULL) {
+                       _ERR("Failed to connect to system bus [%s]", error->message);
+                       g_error_free(error);
+               }
+               return COMP_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
+
+       name = g_dbus_connection_get_unique_name(handle->system_bus);
+       _DBG("Unique dbus name %s", name);
+
+       enabler_call_add_ref_sync(handle->enabler_proxy, name, &ret, NULL, &error);
+       if (error) {
+               /* LCOV_EXCL_START */
+               _ERR("Failed to add reference [%s]", error->message);
+               g_error_free(error);
+               return COMP_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
+
        return ret;
 }
 
@@ -358,9 +384,9 @@ static void _group_proxy_deinit(comp_manager_s *handle)
 
 static void _enabler_proxy_deinit(comp_manager_s *handle)
 {
-       int ret;
+       g_object_unref(handle->system_bus);
+       handle->system_bus = NULL;
 
-       enabler_call_disable_sync(handle->enabler_proxy, &ret, NULL, NULL);
        g_object_unref(handle->enabler_proxy);
        handle->enabler_proxy = NULL;
 }
index 34705c4..f4ebd9a 100644 (file)
@@ -6,7 +6,8 @@
 
 <node>
        <interface name="org.tizen.companion.enabler">
-               <method name="disable">
+               <method name="AddRef">
+                       <arg type="s" name="name" direction="in"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
        </interface>
index 350a98c..37e2047 100644 (file)
@@ -152,6 +152,7 @@ typedef struct _comp_manager_s {
 
        Group *group_proxy; /**< To receive signal from companion-manager */
        Enabler *enabler_proxy; /**< Enbler proxy */
+       GDBusConnection *system_bus; /**< GDBus System Bus */
 
        group_found_cb_t group_found_cb; /**< When it called after finding a every single group */
        group_find_finish_cb_t group_find_finish_cb; /**< When it called the group finging time is up */