Add new API : connection_set_default_cellular_service_profile_async() 2.1b_release accepted/tizen_2.1/20130425.040700 submit/tizen_2.1/20130424.230309
authorJaehyun Kim <jeik01.kim@samsung.com>
Tue, 9 Apr 2013 13:11:51 +0000 (22:11 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Tue, 9 Apr 2013 14:03:04 +0000 (23:03 +0900)
Change-Id: I71c996657cc7bfe638dd9021702d7a48be43e2f5

include/net_connection.h
include/net_connection_private.h
packaging/capi-network-connection.spec
src/connection.c
src/libnetwork.c
test/connection_test.c

index a4c2dad..2eb2fd7 100755 (executable)
@@ -198,6 +198,15 @@ typedef void(*connection_type_changed_cb)(connection_type_e type, void* user_dat
 typedef void(*connection_address_changed_cb)(const char* ipv4_address, const char* ipv6_address, void* user_data);
 
 /**
+* @brief Called after connection_set_default_cellular_service_profile_async() is completed.
+* @param[in] result  The result
+* @param[in] user_data The user data passed from connection_open_profile()
+* @pre connection_set_default_cellular_service_profile_async() will invoke this callback function.
+* @see connection_set_default_cellular_service_profile_async()
+*/
+typedef void(*connection_set_default_cb)(connection_error_e result, void* user_data);
+
+/**
  * @brief Gets the type of the current profile for data connection.
  * @param[in] connection  The handle of the connection
  * @param[out] state  The state of network
@@ -471,6 +480,22 @@ int connection_get_default_cellular_service_profile(connection_h connection, con
 int connection_set_default_cellular_service_profile(connection_h connection, connection_cellular_service_type_e type, connection_profile_h profile);
 
 /**
+ * @brief Sets the default profile which provides the given cellular service, asynchronously.
+ * @param[in] connection  The handle of connection
+ * @param[in] type  The type of cellular service.
+ * #CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET and #CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET are only permitted.
+ * @param[in] profile  The handle of profile
+ * @param[in] callback  The callback function to be called
+ * @param[in] user_data The user data passed to the callback function
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval #CONNECTION_ERROR_OPERATION_FAILED  Operation failed
+ */
+int connection_set_default_cellular_service_profile_async(connection_h connection,
+               connection_cellular_service_type_e type, connection_profile_h profile, connection_set_default_cb callback, void* user_data);
+
+/**
 * @brief Called after connection_open_profile() is completed.
 * @param[in] result  The result
 * @param[in] user_data The user data passed from connection_open_profile()
index 577c024..4a1ab41 100644 (file)
@@ -78,7 +78,9 @@ int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_it
 int _connection_libnet_get_current_profile(connection_profile_h *profile);
 int _connection_libnet_open_profile(connection_profile_h profile, connection_opened_cb callback, void *user_data);
 int _connection_libnet_get_cellular_service_profile(connection_cellular_service_type_e type, connection_profile_h *profile);
-int _connection_libnet_set_cellular_service_profile(connection_cellular_service_type_e type, connection_profile_h profile);
+int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile);
+int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
+                       connection_profile_h profile, connection_set_default_cb callback, void* user_data);
 int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data);
 int _connection_libnet_add_route(const char *interface_name, const char *host_address);
 void _connection_libnet_add_to_profile_list(connection_profile_h profile);
index 8fb55f3..1aa0cb5 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-network-connection
 Summary:    Network Connection library in TIZEN C API
-Version:    0.1.3_12
+Version:    0.1.3_13
 Release:    1
 Group:      System/Network
 License:    Apache License Version 2.0
index 42a3afa..f88ed7b 100755 (executable)
@@ -666,7 +666,20 @@ int connection_set_default_cellular_service_profile(connection_h connection,
                return CONNECTION_ERROR_INVALID_PARAMETER;
        }
 
-       return _connection_libnet_set_cellular_service_profile(type, profile);
+       return _connection_libnet_set_cellular_service_profile_sync(type, profile);
+}
+
+int connection_set_default_cellular_service_profile_async(connection_h connection,
+               connection_cellular_service_type_e type, connection_profile_h profile,
+               connection_set_default_cb callback, void* user_data)
+{
+       if (!(__connection_check_handle_validity(connection)) ||
+           profile == NULL || callback == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       return _connection_libnet_set_cellular_service_profile_async(type, profile, callback, user_data);
 }
 
 int connection_close_profile(connection_h connection, connection_profile_h profile,
index eeb53b3..5a488e0 100755 (executable)
@@ -38,13 +38,15 @@ struct _profile_list_s {
 struct _libnet_s {
        connection_opened_cb opened_cb;
        connection_closed_cb closed_cb;
+       connection_set_default_cb set_default_cb;
        void *opened_user_data;
        void *closed_user_data;
+       void *set_default_user_data;
        bool registered;
 };
 
 static struct _profile_list_s profile_iterator = {0, 0, NULL};
-static struct _libnet_s libnet = {NULL, NULL, NULL, NULL, false};
+static struct _libnet_s libnet = {NULL, NULL, NULL, NULL, NULL, NULL, false};
 
 static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
 {
@@ -160,6 +162,23 @@ static void __libnet_closed_cb(connection_error_e result)
        libnet.closed_user_data = NULL;
 }
 
+static void __libnet_set_default_cb(connection_set_default_cb user_cb, void *user_data)
+{
+       if (user_cb) {
+               libnet.set_default_cb = user_cb;
+               libnet.set_default_user_data = user_data;
+       }
+}
+
+static void __libnet_default_cb(connection_error_e result)
+{
+       if (libnet.set_default_cb)
+               libnet.set_default_cb(result, libnet.set_default_user_data);
+
+       libnet.set_default_cb = NULL;
+       libnet.set_default_user_data = NULL;
+}
+
 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
 {
        if (profile_name == NULL)
@@ -272,6 +291,11 @@ static void __libnet_evt_cb(net_event_info_t*  event_cb, void* user_data)
        case NET_EVENT_WIFI_POWER_RSP:
                CONNECTION_LOG(CONNECTION_INFO, "Got wifi power IND\n");
                break;
+       case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
+               result = __libnet_convert_to_cp_error_type(event_cb->Error);
+               CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d\n", result);
+               __libnet_default_cb(result);
+               break;
        case NET_EVENT_WIFI_WPS_RSP:
                CONNECTION_LOG(CONNECTION_INFO, "Got wifi WPS RSP\n");
                /* fall through */
@@ -733,7 +757,7 @@ done:
        return CONNECTION_ERROR_NONE;
 }
 
-int _connection_libnet_set_cellular_service_profile(connection_cellular_service_type_e type, connection_profile_h profile)
+int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
 {
        if (!(_connection_libnet_check_profile_validity(profile))) {
                CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
@@ -754,6 +778,30 @@ int _connection_libnet_set_cellular_service_profile(connection_cellular_service_
        return CONNECTION_ERROR_NONE;
 }
 
+int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
+                       connection_profile_h profile, connection_set_default_cb callback, void* user_data)
+{
+       if (!(_connection_libnet_check_profile_validity(profile))) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       net_profile_info_t *profile_info = profile;
+       connection_cellular_service_type_e service_type;
+
+       service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
+
+       if (service_type != type)
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+
+       if (net_set_default_cellular_service_profile_async(profile_info->ProfileName) != NET_ERR_NONE)
+               return CONNECTION_ERROR_OPERATION_FAILED;
+
+       __libnet_set_default_cb(callback, user_data);
+
+       return CONNECTION_ERROR_NONE;
+}
+
 int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
 {
        if (!(_connection_libnet_check_profile_validity(profile))) {
index d1f1a6c..b160a6f 100644 (file)
@@ -47,7 +47,7 @@ static bool test_get_user_string(const char *msg, char *buf, int buf_size)
                return false;
        }
 
-       buf[buf_size - 1] = '\0';
+       buf[strlen(buf) - 1] = '\0';
 
        return true;
 }
@@ -133,6 +133,14 @@ static void test_connection_closed_callback(connection_error_e result, void* use
                printf("Connection close Failed, err : %d\n", result);
 }
 
+static void test_connection_set_default_callback(connection_error_e result, void* user_data)
+{
+       if (result ==  CONNECTION_ERROR_NONE)
+               printf("Default profile setting Succeeded\n");
+       else
+               printf("Default profile setting Failed, err : %d\n", result);
+}
+
 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
 {
        int rv = 0;
@@ -945,8 +953,17 @@ int test_set_default_cellular_service_type(void)
 {
        connection_profile_h profile;
        connection_cellular_service_type_e type;
+       int input, rv;
+
+       rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
+
+       if (rv == false || (input != 1 && input != 2)) {
+               printf("Invalid input!!\n");
+               return -1;
+       }
 
        printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
+
        if (test_get_user_selected_profile(&profile, true) == false)
                return -1;
 
@@ -955,8 +972,14 @@ int test_set_default_cellular_service_type(void)
                return -1;
        }
 
-       if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
-               return -1;
+       if (input == 1) {
+               if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
+                       return -1;
+       } else {
+               if (connection_set_default_cellular_service_profile_async(connection,
+                               type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
+                       return -1;
+       }
 
        return 1;
 }