Check already powered during Wi-Fi enable/disable 47/13247/3
authortaesub.kim <taesub.kim@samsung.com>
Mon, 2 Dec 2013 00:17:20 +0000 (09:17 +0900)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Mon, 2 Dec 2013 23:58:03 +0000 (15:58 -0800)
Change-Id: I575fb8de454905341d74d99273b3e0fd54bffefa
Signed-off-by: Taesub Kim <taesub.kim@samsung.com>
include/netdbus.h
packaging/net-config.spec
src/dbus/netdbus.c
src/wifi-power.c

index b6544e0..8f58900 100644 (file)
@@ -32,6 +32,7 @@ extern "C" {
 #define CONNMAN_PATH                                   "/net/connman"
 
 #define CONNMAN_CLOCK_INTERFACE                                CONNMAN_SERVICE ".Clock"
+#define CONNMAN_ERROR_INTERFACE                                CONNMAN_SERVICE ".Error"
 #define CONNMAN_MANAGER_INTERFACE                      CONNMAN_SERVICE ".Manager"
 #define CONNMAN_SERVICE_INTERFACE                      CONNMAN_SERVICE ".Service"
 #define CONNMAN_TECHNOLOGY_INTERFACE                   CONNMAN_SERVICE ".Technology"
@@ -61,8 +62,14 @@ gboolean netconfig_is_ethernet_profile(const char *profile);
 gboolean netconfig_is_bluetooth_profile(const char *profile);
 
 char *netconfig_wifi_get_connected_service_name(DBusMessage *message);
+
+gboolean netconfig_invoke_dbus_method_nonblock(
+               const char *dest, const char *path,
+               const char *interface_name, const char *method, char *param_array[],
+               DBusPendingCallNotifyFunction notify_func);
 DBusMessage *netconfig_invoke_dbus_method(const char *dest, const char *path,
                const char *interface_name, const char *method, char *param_array[]);
+
 gboolean netconfig_dbus_get_basic_params_string(DBusMessage *message,
                char **key, int type, void *value);
 gboolean netconfig_dbus_get_basic_params_array(DBusMessage *message,
index 628c57f..c0e82bd 100644 (file)
@@ -1,6 +1,6 @@
 Name:       net-config
 Summary:    TIZEN Network Configuration Module
-Version:    0.1.90_25
+Version:    0.1.90_26
 Release:    1
 Group:      System/Network
 License:    Apache License Version 2.0
index 9db6c19..928dfde 100644 (file)
@@ -309,6 +309,66 @@ gboolean netconfig_is_bluetooth_profile(const char *profile)
        return g_str_has_prefix(profile, CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX);
 }
 
+gboolean netconfig_invoke_dbus_method_nonblock(
+               const char *dest, const char *path,
+               const char *interface_name, const char *method, char *param_array[],
+               DBusPendingCallNotifyFunction notify_func)
+{
+       dbus_bool_t result;
+       DBusPendingCall *call;
+       DBusMessage *message = NULL;
+       DBusConnection *connection = NULL;
+
+       DBG("[DBUS Async] %s %s %s", interface_name, method, path);
+
+       connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+       if (connection == NULL) {
+               ERR("Failed to get system bus");
+
+               return FALSE;
+       }
+
+       message = dbus_message_new_method_call(dest, path, interface_name, method);
+       if (message == NULL) {
+               ERR("Failed DBus method call");
+
+               dbus_connection_unref(connection);
+
+               return FALSE;
+       }
+
+       if (__netconfig_dbus_append_param(message, param_array) == FALSE) {
+               ERR("Failed to append DBus params");
+
+               dbus_message_unref(message);
+               dbus_connection_unref(connection);
+
+               return FALSE;
+       }
+
+       result = dbus_connection_send_with_reply(connection, message, &call,
+                       NETCONFIG_DBUS_REPLY_TIMEOUT);
+
+       if (result != TRUE || call == NULL) {
+               ERR("dbus_connection_send_with_reply() failed.");
+
+               dbus_message_unref(message);
+               dbus_connection_unref(connection);
+
+               return FALSE;
+       }
+
+       if (notify_func == NULL)
+               dbus_pending_call_cancel(call);
+       else
+               dbus_pending_call_set_notify(call, notify_func, NULL, NULL);
+
+       dbus_message_unref(message);
+       dbus_connection_unref(connection);
+
+       return TRUE;
+}
+
 DBusMessage *netconfig_invoke_dbus_method(const char *dest, const char *path,
                const char *interface_name, const char *method, char *param_array[])
 {
@@ -322,20 +382,25 @@ DBusMessage *netconfig_invoke_dbus_method(const char *dest, const char *path,
        conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
        if (conn == NULL) {
                ERR("Failed to get system bus");
+
                return NULL;
        }
 
        message = dbus_message_new_method_call(dest, path, interface_name, method);
        if (message == NULL) {
                ERR("Error!!! Failed to GetProperties");
+
                dbus_connection_unref(conn);
+
                return NULL;
        }
 
        if (__netconfig_dbus_append_param(message, param_array) == FALSE) {
                ERR("Error!!! __netconfig_dbus_append_param() failed");
+
                dbus_message_unref(message);
                dbus_connection_unref(conn);
+
                return NULL;
        }
 
index 6eb0fea..15ac07c 100644 (file)
 static gboolean power_in_progress = FALSE;
 static gboolean fm_waiting = FALSE;
 
-static gboolean __netconfig_wifi_enable_technology(void)
+static void __netconfig_wifi_technology_reply(DBusPendingCall *call, void *data)
 {
-       DBusMessage *reply = NULL;
-       char param1[] = "string:Powered";
-       char param2[] = "variant:boolean:true";
-       char *param_array[] = {NULL, NULL, NULL};
+       DBusMessage *message;
 
-       param_array[0] = param1;
-       param_array[1] = param2;
+       message = dbus_pending_call_steal_reply(call);
 
-       reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX,
-                       CONNMAN_TECHNOLOGY_INTERFACE, "SetProperty", param_array);
+       if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {
+               ERR("%s", dbus_message_get_error_name(message));
 
-       if (reply == NULL) {
-               ERR("Error! Request failed");
-               return FALSE;
+               if (dbus_message_is_error(message,
+                               CONNMAN_ERROR_INTERFACE ".AlreadyEnabled") == TRUE) {
+                       netconfig_wifi_update_power_state(TRUE);
+                       power_in_progress = FALSE;
+               } else if (dbus_message_is_error(message,
+                               CONNMAN_ERROR_INTERFACE ".AlreadyDisabled") == TRUE) {
+                       netconfig_wifi_update_power_state(FALSE);
+                       power_in_progress = FALSE;
+               }
+       } else {
+               DBG("Successfully requested");
        }
 
-       dbus_message_unref(reply);
+       dbus_message_unref(message);
+       dbus_pending_call_unref(call);
+}
 
-       return TRUE;
+static gboolean __netconfig_wifi_enable_technology(void)
+{
+       gboolean reply = FALSE;
+       char param0[] = "string:Powered";
+       char param1[] = "variant:boolean:true";
+       char *param_array[] = { NULL, NULL, NULL };
+
+       param_array[0] = param0;
+       param_array[1] = param1;
+
+       reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
+                       CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE,
+                       "SetProperty", param_array, __netconfig_wifi_technology_reply);
+
+       if (reply != TRUE)
+               ERR("Fail to enable Wi-Fi");
+
+       return reply;
 }
 
 static gboolean __netconfig_wifi_disable_technology(void)
 {
-       DBusMessage *reply = NULL;
-       char param1[] = "string:Powered";
-       char param2[] = "variant:boolean:false";
-       char *param_array[] = {NULL, NULL, NULL};
+       gboolean reply = FALSE;
+       char param0[] = "string:Powered";
+       char param1[] = "variant:boolean:false";
+       char *param_array[] = { NULL, NULL, NULL };
 
-       param_array[0] = param1;
-       param_array[1] = param2;
+       param_array[0] = param0;
+       param_array[1] = param1;
 
-       reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX,
-                       CONNMAN_TECHNOLOGY_INTERFACE, "SetProperty", param_array);
+       reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
+                       CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE,
+                       "SetProperty", param_array, __netconfig_wifi_technology_reply);
 
-       if (reply == NULL) {
-               ERR("Error! Request failed");
-               return FALSE;
-       }
+       if (reply != TRUE)
+               ERR("Fail to disable Wi-Fi");
 
-       dbus_message_unref(reply);
-
-       return TRUE;
+       return reply;
 }
 
 static gboolean __netconfig_wifi_load_driver(void)