Get the type of the current profile for data connection 26/31626/2
authorChengyi Zhao <chengyi1.zhao@archermind.com>
Mon, 8 Dec 2014 01:06:46 +0000 (09:06 +0800)
committerChengyi Zhao <chengyi1.zhao@archermind.com>
Wed, 10 Dec 2014 01:37:22 +0000 (09:37 +0800)
All services are a sorted list of tuples with
service object path and dictionary of service properties,
generally, the first one is a default(or active) service,
and the profile type and the device type are the same.

Change-Id: I0d9146d56dff46798166086e9a316d6fedd29927
Signed-off-by: Chengyi Zhao <chengyi1.zhao@archermind.com>
include/net_connection_private.h
src/connection.c
src/libnetwork.c

index f2debf522a3f9612e3b9dea1038432d0ad742860..5d6f5246cb9b018e9019cce52375354be20e9130 100644 (file)
@@ -96,6 +96,7 @@ net_state_type_t _connection_profile_convert_to_net_state(connection_profile_sta
 
 struct connman_service *_connection_libnet_get_service_h(
                                                connection_profile_h profile);
+int _connection_libnet_get_default_device_type(net_device_t *net_type);
 
 void _connection_inter_mutex_lock(void);
 void _connection_inter_mutex_unlock(void);
index dcca4bd3310a1ab434d5912a7d734ac3b1b35831..e9b817579b11d5b0ad7af90be02054d29936d514 100644 (file)
@@ -26,16 +26,16 @@ static void __connection_cb_state_change_cb(keynode_t *node, void *user_data);
 static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data);
 static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data);
 
-static int __connection_convert_net_state(int status)
+static int __connection_convert_net_type(net_device_t net_type)
 {
-       switch (status) {
-       case VCONFKEY_NETWORK_CELLULAR:
+       switch (net_type) {
+       case NET_DEVICE_CELLULAR:
                return CONNECTION_TYPE_CELLULAR;
-       case VCONFKEY_NETWORK_WIFI:
+       case NET_DEVICE_WIFI:
                return CONNECTION_TYPE_WIFI;
-       case VCONFKEY_NETWORK_ETHERNET:
+       case NET_DEVICE_ETHERNET:
                return CONNECTION_TYPE_ETHERNET;
-       case VCONFKEY_NETWORK_BLUETOOTH:
+       case NET_DEVICE_BLUETOOTH:
                return CONNECTION_TYPE_BT;
        default:
                return CONNECTION_TYPE_DISCONNECTED;
@@ -180,7 +180,7 @@ static void __connection_cb_state_change_cb(keynode_t *node, void *user_data)
                connection_handle_s *local_handle = (connection_handle_s *)list->data;
                if (local_handle->type_changed_callback)
                        local_handle->type_changed_callback(
-                                       __connection_convert_net_state(state),
+                                       __connection_convert_net_type(state),
                                        local_handle->state_changed_user_data);
        }
 }
@@ -302,21 +302,21 @@ EXPORT_API int connection_destroy(connection_h connection)
 
 EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type)
 {
-       int status = 0;
+       net_device_t device_type;
 
        if (type == NULL || !(__connection_check_handle_validity(connection))) {
                CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
                return CONNECTION_ERROR_INVALID_PARAMETER;
        }
 
-       if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status)) {
-               CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status);
-               return CONNECTION_ERROR_OPERATION_FAILED;
-       }
-
-       CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d\n", status);
+       if (_connection_libnet_get_default_device_type(&device_type) ==
+                                               CONNECTION_ERROR_NO_CONNECTION)
+               *type = CONNECTION_TYPE_DISCONNECTED;
+       else
+               *type = __connection_convert_net_type(device_type);
 
-       *type = __connection_convert_net_state(status);
+       CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d\n",
+                                                               device_type);
 
        return CONNECTION_ERROR_NONE;
 }
index 534d66487f5219cb11ed64189e7394465c3b1a96..1e8e3adf9c9e79a5077659553b96f21e9fef19d8 100755 (executable)
@@ -378,6 +378,31 @@ static int __libnet_get_profile_list(net_device_t device_type,
        return CONNECTION_ERROR_NONE;
 }
 
+static int __libnet_get_default_service(
+                               struct connman_service **default_service)
+{
+       GList *services_list;
+       struct connman_service *service;
+       net_state_type_t profile_state;
+
+       services_list = connman_get_services();
+       if (services_list == NULL)
+               return CONNECTION_ERROR_NO_CONNECTION;
+
+       service = (struct connman_service *)services_list->data;
+       profile_state = __libnet_service_state_string2type(
+                                       connman_service_get_state(service));
+
+       if ((profile_state == NET_STATE_TYPE_READY ||
+                               profile_state == NET_STATE_TYPE_ONLINE)) {
+               *default_service = service;
+
+               return CONNECTION_ERROR_NONE;
+       }
+
+       return CONNECTION_ERROR_NO_CONNECTION;
+}
+
 int __libnet_get_connected_count(struct _profile_list_s *profile_list)
 {
        int count = 0;
@@ -906,3 +931,18 @@ struct connman_service *_connection_libnet_get_service_h(
 
        return service;
 }
+
+int _connection_libnet_get_default_device_type(net_device_t *device_type)
+{
+       int rv;
+       struct connman_service *default_service;
+
+       rv = __libnet_get_default_service(&default_service);
+       if (rv == CONNECTION_ERROR_NO_CONNECTION)
+               return CONNECTION_ERROR_NO_CONNECTION;
+
+       *device_type = __libnet_service_type_string2type(
+                               connman_service_get_type(default_service));
+
+       return CONNECTION_ERROR_NONE;
+}