[NSD] Send dbus unique name in LaunchMdns 93/88293/1
authorSaurav Babu <saurav.babu@samsung.com>
Fri, 16 Sep 2016 06:01:12 +0000 (11:31 +0530)
committerSaurav Babu <saurav.babu@samsung.com>
Fri, 16 Sep 2016 06:01:12 +0000 (11:31 +0530)
This patch removes dbus method UnrefMdns and sends dbus unique name as
parameter in LaunchMdns so that net-config can register NameOwnerChanged
callback for unique name and identify when application exits.

Change-Id: I93827860a89e9e6e99be2b5d9295b642324d6451
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
src/dns-sd/dns-sd.c

index 8df4044..0cb027f 100644 (file)
@@ -38,6 +38,7 @@
 static __thread GSList *dnssd_handle_list = NULL;
 static __thread GSList *resolve_handle_list = NULL;
 static __thread bool g_is_init = false;
+static __thread GDBusConnection *netconfig_bus = NULL;
 
 static const char *dnssd_error_to_string(dnssd_error_e error)
 {
@@ -71,56 +72,11 @@ static bool __dnssd_is_init(void)
 }
 
 //LCOV_EXCL_START
-static int __dnssd_unref_mdns_dbus(void)
-{
-       GDBusConnection *netconfig_bus = NULL;
-       GError *g_error = NULL;
-
-       DNSSD_LOGD("Request to decrease ref count for mdnsd");
-#if !GLIB_CHECK_VERSION(2, 36, 0)
-       g_type_init();
-#endif
-       netconfig_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &g_error);
-       if (netconfig_bus == NULL) {
-               if (g_error != NULL) {
-                       DNSSD_LOGE("Couldn't connect to system bus "
-                                       "error [%d: %s]", g_error->code, g_error->message);
-                       g_error_free(g_error);
-               }
-               return DNSSD_ERROR_OPERATION_FAILED;
-       }
-
-       g_dbus_connection_call_sync(netconfig_bus,
-                       NETCONFIG_SERVICE,
-                       NETCONFIG_NETWORK_PATH,
-                       NETCONFIG_NETWORK_INTERFACE,
-                       NETCONFIG_NETWORK_UNREFMDNS,
-                       NULL,
-                       NULL,
-                       G_DBUS_CALL_FLAGS_NONE,
-                       DBUS_REPLY_TIMEOUT,
-                       NULL,
-                       &g_error);
-
-       if (g_error != NULL) {
-               DNSSD_LOGE("g_dbus_connection_call failed. "
-                               "error [%d: %s]", g_error->code, g_error->message);
-               g_error_free(g_error);
-               return DNSSD_ERROR_OPERATION_FAILED;
-       }
-
-       g_object_unref(netconfig_bus);
-
-       return DNSSD_ERROR_NONE;
-
-}
-//LCOV_EXCL_STOP
-
-//LCOV_EXCL_START
 static int __dnssd_launch_mdns_dbus(void)
 {
-       GDBusConnection *netconfig_bus = NULL;
        GError *g_error = NULL;
+       GVariant *params;
+       const gchar *name;
 
 #if !GLIB_CHECK_VERSION(2, 36, 0)
        g_type_init();
@@ -135,12 +91,15 @@ static int __dnssd_launch_mdns_dbus(void)
                return DNSSD_ERROR_OPERATION_FAILED;
        }
 
+       name = g_dbus_connection_get_unique_name(netconfig_bus);
+       DNSSD_LOGD("Unique DBUS Name %s", name);
+       params = g_variant_new("(s)", name);
        g_dbus_connection_call_sync(netconfig_bus,
                        NETCONFIG_SERVICE,
                        NETCONFIG_NETWORK_PATH,
                        NETCONFIG_NETWORK_INTERFACE,
                        NETCONFIG_NETWORK_LAUNCHMDNS,
-                       NULL,
+                       params,
                        NULL,
                        G_DBUS_CALL_FLAGS_NONE,
                        DBUS_REPLY_TIMEOUT,
@@ -154,8 +113,6 @@ static int __dnssd_launch_mdns_dbus(void)
                return DNSSD_ERROR_OPERATION_FAILED;
        }
 
-       g_object_unref(netconfig_bus);
-
        DNSSD_LOGD("Successfully launched mdnsresponder");
        return DNSSD_ERROR_NONE;
 }
@@ -266,8 +223,8 @@ int dnssd_deinitialize(void)
 
        g_is_init = false;
 
-       if (__dnssd_unref_mdns_dbus() != DNSSD_ERROR_NONE)
-               DNSSD_LOGE("Fail to decrease ref count for mdnsd");
+       g_object_unref(netconfig_bus);
+       netconfig_bus = NULL;
 
        __DNSSD_LOG_FUNC_EXIT__;
        return DNSSD_ERROR_NONE;