From: Chengyi Zhao Date: Mon, 8 Dec 2014 01:06:46 +0000 (+0800) Subject: Get the type of the current profile for data connection X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5f381af8fb83fa8425c8fa422df21251c09b2597;p=platform%2Fcore%2Fapi%2Fconnection.git Get the type of the current profile for data connection 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 --- diff --git a/include/net_connection_private.h b/include/net_connection_private.h index f2debf5..5d6f524 100644 --- a/include/net_connection_private.h +++ b/include/net_connection_private.h @@ -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); diff --git a/src/connection.c b/src/connection.c index dcca4bd..e9b8175 100644 --- a/src/connection.c +++ b/src/connection.c @@ -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; } diff --git a/src/libnetwork.c b/src/libnetwork.c index 534d664..1e8e3ad 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -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; +}