Modified to get wifi state 52/58152/1 submit/tizen/20160211.015108
authorhyunuktak <hyunuk.tak@samsung.com>
Thu, 28 Jan 2016 02:49:39 +0000 (11:49 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Thu, 28 Jan 2016 02:49:43 +0000 (11:49 +0900)
Change-Id: I34d33343d3ff86fd0045735cb7e49987d7a4d619
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
include/wifi/network-wifi-intf.h
packaging/libnet-client.spec
src/include/network-dbus-request.h
src/include/network-internal.h
src/network-dbus-request.c
src/network-wifi-intf.c

index 18709c7284d467a4b231ace2b418209f06c888c4..49fc88043751caa3c2a0f8e096c8919c609bbd86 100755 (executable)
@@ -143,7 +143,7 @@ struct wps_scan_bss_info_t {
  *****************************************************************************/
 
 /**
- * @fn   int net_get_wifi_state(net_wifi_state_t *current_state, net_profile_name_t *profile_name)
+ * @fn   int net_get_wifi_state(net_wifi_state_t *current_state)
  *
  * This function requests current state of wifi.
  *
@@ -158,7 +158,7 @@ struct wps_scan_bss_info_t {
  * @return       NET_ERR_NONE on success, negative values for errors
  */
 
-int net_get_wifi_state(net_wifi_state_t *current_state, net_profile_name_t *profile_name);
+int net_get_wifi_state(net_wifi_state_t *current_state);
 
 /**
  * @fn   int net_wifi_set_background_scan_mode(net_wifi_background_scan_mode_t scan_mode)
index 3dc8b20b263dfd6ff6c8269c14885b25344ed5d8..8c0fad0e6e2e01c7f63dbbeb53814a878956050a 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          libnet-client
 Summary:       Network Client library (Shared library)
-Version:       1.1.44
+Version:       1.1.45
 Release:       1
 Group:         System/Network
 License:       Flora-1.1
index a4599b69cdb8aa772ba7710bd6d6c0a5d834310c..997dabbc0545c4b8755d78752afd566652812936 100755 (executable)
@@ -104,6 +104,7 @@ int _net_dbus_open_connection(const char* profile_name);
 int _net_dbus_close_connection(const char* profile_name);
 int _net_dbus_get_network_status(net_device_t device_type, net_cm_network_status_t* network_status);
 int _net_dbus_get_tech_status(net_device_t device_type, net_tech_info_t* tech_status);
+int _net_dbus_get_wifi_state(char **wifi_state);
 int _net_dbus_connect_service(const net_wifi_connect_service_info_t* wifi_connection_info);
 int _net_dbus_set_profile_ipv4(net_profile_info_t* prof_info, char* profile_name);
 int _net_dbus_set_profile_ipv6(net_profile_info_t* prof_info, char* profile_name);
index a530345c8038b10f682cd7c84730281b0da5c446..cbe1ba0a5e350e2470400262f0224679b960f751 100755 (executable)
@@ -171,8 +171,14 @@ extern "C" {
                } \
        } while(0)
 
-#define __NETWORK_FUNC_ENTER__ /* NETWORK_LOG(NETWORK_LOW, "Entering (%s)", __func__)*/
-#define __NETWORK_FUNC_EXIT__  /* NETWORK_LOG(NETWORK_LOW, "Quit (%s)", __func__)*/
+#define NERWORK_LOG_RED "\033[0;31m"
+#define NERWORK_LOG_GREEN "\033[0;32m"
+#define NERWORK_LOG_BROWN "\033[0;33m"
+#define NERWORK_LOG_BLUE "\033[0;34m"
+#define NERWORK_LOG_END "\033[0;m"
+#define __NETWORK_FUNC_ENTER__ NETWORK_LOG(NETWORK_LOW, NERWORK_LOG_GREEN"Entering (%s)" NERWORK_LOG_END, __func__);
+#define __NETWORK_FUNC_EXIT__  NETWORK_LOG(NETWORK_LOW, NERWORK_LOG_RED"Quit (%s)" NERWORK_LOG_END, __func__);
+
 
 /*****************************************************************************
  *     Global Enums
index 5960addf275d357c83b38f56d039a4b04bd94260..038746ee605d470591e4802e2d190e679eb166a2 100755 (executable)
@@ -915,6 +915,38 @@ done:
        return Error;
 }
 
+int _net_dbus_get_wifi_state(char **wifi_state)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_t Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+       const char *method = "GetWifiState";
+
+       if(NULL == wifi_state) {
+                       NETWORK_LOG(NETWORK_ERROR,"Invalid Parameter\n");
+                       __NETWORK_FUNC_EXIT__;
+                       return NET_ERR_INVALID_PARAM;
+       }
+
+       message = _net_invoke_dbus_method(
+                       NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
+                       NETCONFIG_WIFI_INTERFACE, method, NULL, &Error);
+
+       if (message == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to get wifi state\n");
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
+
+       g_variant_get(message, "(s)", wifi_state);
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+
+       return Error;
+}
+
 int _net_dbus_get_statistics(net_device_t device_type, net_statistics_type_e statistics_type, unsigned long long *size)
 {
        net_err_t Error = NET_ERR_NONE;
index d6cf7e9506ad7fc1765a30de0753a7a869c43bf2..d9c291d2a4a0ed2e69ac151e54ff063c9374738f 100755 (executable)
@@ -71,74 +71,49 @@ static int __net_check_profile_privilege()
 /*****************************************************************************
  *     Local Functions Definition
  *****************************************************************************/
-static net_wifi_state_t __net_get_wifi_service_state(char *profile_name, net_err_t *net_error)
+static net_wifi_state_t __net_get_wifi_connection_state(net_err_t *net_error)
 {
-       int i = 0, profile_count = 0;
        net_err_t Error = NET_ERR_NONE;
-       net_wifi_state_t wifi_state = NetworkInfo.wifi_state;
-       net_profile_info_t *temp = NULL, *profile_info = NULL;
+       char *wifi_state = NULL;
+       net_wifi_state_t current_state = NetworkInfo.wifi_state;
 
        __NETWORK_FUNC_ENTER__;
-       Error = _net_get_profile_list(NET_DEVICE_WIFI, &profile_info, &profile_count);
+       Error = _net_dbus_get_wifi_state(&wifi_state);
 
        if (Error != NET_ERR_NONE) {
-               NETWORK_LOG(NETWORK_ERROR, "Failed to get service list[%s]",
+               NETWORK_LOG(NETWORK_ERROR, "Failed to get wifi state[%s]",
                                _net_print_error(Error));
 
-               NET_MEMFREE(profile_info);
                *net_error = Error;
 
                __NETWORK_FUNC_EXIT__;
-               return wifi_state;
+               return current_state;
        }
 
-       if (profile_count == 0) {
-               wifi_state = WIFI_ON;
-               NET_MEMFREE(profile_info);
-               *net_error = Error;
-
-               __NETWORK_FUNC_EXIT__;
-               return wifi_state;
-       }
-
-       /* Assign 'profile_info' to 'temp' to free memory at the end */
-       temp = profile_info;
-       for (i = 0; i < profile_count; i++) {
-               switch (profile_info->ProfileState) {
-               case NET_STATE_TYPE_ASSOCIATION:
-                       wifi_state = WIFI_ASSOCIATION;
-                       g_strlcpy(profile_name, profile_info->ProfileName,
-                                       sizeof(profile_info->ProfileName));
-                       break;
-               case NET_STATE_TYPE_CONFIGURATION:
-                       wifi_state = WIFI_CONFIGURATION;
-                       g_strlcpy(profile_name, profile_info->ProfileName,
-                                       sizeof(profile_info->ProfileName));
-                       break;
-               case NET_STATE_TYPE_READY:
-               case NET_STATE_TYPE_ONLINE:
-                       wifi_state = WIFI_CONNECTED;
-                       g_strlcpy(profile_name, profile_info->ProfileName,
-                                       sizeof(profile_info->ProfileName));
-                       break;
-               case NET_STATE_TYPE_UNKNOWN:
-               case NET_STATE_TYPE_IDLE:
-               case NET_STATE_TYPE_FAILURE:
-               case NET_STATE_TYPE_DISCONNECT:
-                       break;
-               }
-               profile_info++;
+       if (g_strcmp0(wifi_state, "unknown") == 0) {
+               current_state = WIFI_UNKNOWN;
+       } else if (g_strcmp0(wifi_state, "deactivated") == 0) {
+               current_state = WIFI_OFF;
+       } else if (g_strcmp0(wifi_state, "disconnected") == 0) {
+               current_state = WIFI_ON;
+       } else if (g_strcmp0(wifi_state, "association") == 0) {
+               current_state = WIFI_ASSOCIATION;
+       } else if (g_strcmp0(wifi_state, "configuration") == 0) {
+               current_state = WIFI_CONFIGURATION;
+       } else if (g_strcmp0(wifi_state, "connected") == 0) {
+               current_state = WIFI_CONNECTED;
        }
 
-       if (wifi_state == WIFI_CONNECTED &&
+       g_free(wifi_state);
+
+       if (current_state == WIFI_CONNECTED &&
            request_table[NETWORK_REQUEST_TYPE_CLOSE_CONNECTION].flag == TRUE)
-               wifi_state = WIFI_DISCONNECTING;
+               current_state = WIFI_DISCONNECTING;
 
-       NET_MEMFREE(temp);
        *net_error = Error;
 
        __NETWORK_FUNC_EXIT__;
-       return wifi_state;
+       return current_state;
 }
 
 /*****************************************************************************
@@ -703,11 +678,10 @@ EXPORT_API int net_wifi_cancel_wps(void)
 /*****************************************************************************
  *     ConnMan Wi-Fi Client Interface Sync Function Definition
  *****************************************************************************/
-EXPORT_API int net_get_wifi_state(net_wifi_state_t *current_state, net_profile_name_t *profile_name)
+EXPORT_API int net_get_wifi_state(net_wifi_state_t *current_state)
 {
        __NETWORK_FUNC_ENTER__;
 
-       net_wifi_state_t wifi_state;
        net_err_t Error = NET_ERR_NONE;
 
        if (NetworkInfo.ref_count < 1) {
@@ -716,22 +690,7 @@ EXPORT_API int net_get_wifi_state(net_wifi_state_t *current_state, net_profile_n
                return NET_ERR_APP_NOT_REGISTERED;
        }
 
-       if (profile_name == NULL) {
-               NETWORK_LOG(NETWORK_ERROR, "profile_name is NULL");
-               return NET_ERR_INVALID_PARAM;
-       }
-
-       memset(profile_name, 0, sizeof(net_profile_name_t));
-
-       wifi_state = _net_get_wifi_state(&Error);
-
-       if (wifi_state == WIFI_OFF) {
-               *current_state = WIFI_OFF;
-               __NETWORK_FUNC_EXIT__;
-               return NET_ERR_NONE;
-       }
-
-       *current_state = __net_get_wifi_service_state(profile_name->ProfileName, &Error);
+       *current_state = __net_get_wifi_connection_state(&Error);
 
        __NETWORK_FUNC_EXIT__;
        return Error;