[net-config] Refactoring code to register agent. 66/72466/1
authorNiraj Kumar Goit <niraj.g@samsung.com>
Wed, 1 Jun 2016 12:02:41 +0000 (17:32 +0530)
committerNiraj Kumar Goit <niraj.g@samsung.com>
Wed, 1 Jun 2016 12:02:41 +0000 (17:32 +0530)
Description: Use dbus wrapper function to invoke "RegisterAgent" Dbus method.

Change-Id: I16d5951411bea518da825e338909e9c146f148ce
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
src/wifi-agent.c

index 9e12fff..8d0db7b 100755 (executable)
@@ -75,55 +75,21 @@ int connman_register_agent(void)
 {
        GVariant *reply = NULL;
        GVariant *params = NULL;
-       GError *error;
-       GDBusConnection *connection = NULL;
 
-       connection = netdbus_get_connection();
-       if (connection == NULL) {
-               ERR("GDBusconnection is NULL");
-               return -1;
-       }
-
-       do {
-               error = NULL;
-               params = g_variant_new("(o)", NETCONFIG_WIFI_PATH);
-
-               reply = g_dbus_connection_call_sync(
-                               connection,
-                               CONNMAN_SERVICE,
-                               CONNMAN_MANAGER_PATH,
-                               CONNMAN_MANAGER_INTERFACE,
-                               "RegisterAgent",
-                               params,
-                               NULL,
-                               G_DBUS_CALL_FLAGS_NONE,
-                               DBUS_REPLY_TIMEOUT,
-                               netdbus_get_cancellable(),
-                               &error);
-
-               if (reply == NULL) {
-                       if (error != NULL) {
-                               if (g_strcmp0(error->message,
-                                               "GDBus.Error:net.connman.Error.AlreadyExists: Already exists") == 0) {
-                                       g_error_free(error);
-                                       break;
-                               } else {
-                                       ERR("Fail to register agent [%d: %s]",
-                                               error->code, error->message);
-                               }
-
-                               g_error_free(error);
-                       } else
-                               ERR("Fail to register agent");
-               } else
-                       g_variant_unref(reply);
+       params = g_variant_new("(o)", NETCONFIG_WIFI_PATH);
+       reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
+                       CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
+                       "RegisterAgent", params);
 
-               sleep(1);
-       } while (TRUE);
+       if (reply == NULL) {
+                       ERR("Fail to register agent");
+                       return FALSE;
+       } else
+               g_variant_unref(reply);
 
        INFO("Registered to connman agent successfully");
 
-       return 0;
+       return TRUE;
 }
 
 int connman_unregister_agent(void)