*/
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
*/
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
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);
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
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,
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)
{
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)
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 */
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");
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))) {
return false;
}
- buf[buf_size - 1] = '\0';
+ buf[strlen(buf) - 1] = '\0';
return true;
}
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;
{
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;
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;
}