const char *mac_address, void *user_data);
/**
+ * @brief Called when the state of Wi-FI Direct is changed.
+ * @since_tizen 3.0
+ * @param[in] state The Wi-Fi Direct state
+ * @param[in] user_data The user data passed from the callback registration function
+ * @pre Changes in Wi-Fi Direct state will invoke this callback
+ * if you register this callback using wifi_direct_set_state_changed_cb().
+ * @see wifi_direct_set_state_changed_cb()
+ * @see wifi_direct_unset_state_changed_cb()
+ */
+typedef void (*wifi_direct_state_changed_cb) (wifi_direct_state_e state,
+ void *user_data);
+
+/**
* @brief Initializes Wi-Fi Direct service.
* @since_tizen 2.3
* @privlevel public
int wifi_direct_unset_service_state_changed_cb(void);
/**
+ * @brief Registers the callback called when the state of Wi-Fi Direct is changed.
+ * @since_tizen 3.0
+ * @param[in] cb The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value
+ * @retval #WIFI_DIRECT_ERROR_NONE Successful
+ * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation Failed
+ * @see wifi_direct_unset_state_changed_cb()
+ */
+int wifi_direct_set_state_changed_cb(wifi_direct_state_changed_cb cb, void *user_data);
+
+/**
+ * @brief Unregisters the callback called when the state of Wi-Fi Direct is changed.
+ * @since_tizen 3.0
+ * @return 0 on success, otherwise a negative error value
+ * @retval #WIFI_DIRECT_ERROR_NONE Successful
+ * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation Failed
+ * @see wifi_direct_initialize()
+ * @see wifi_direct_set_state_changed_cb()
+ */
+int wifi_direct_unset_state_changed_cb(void);
+
+/**
* @brief Activates the Wi-Fi Direct service, asynchronous.
* @since_tizen 2.3
* @privlevel public
Name: capi-network-wifi-direct
Summary: Network WiFi-Direct Library
-Version: 1.2.65
+Version: 1.2.66
Release: 1
Group: Network & Connectivity/API
License: Apache-2.0
wifi_direct_connection_state_changed_cb connection_cb;
wifi_direct_client_ip_address_assigned_cb ip_assigned_cb;
wifi_direct_peer_found_cb peer_found_cb;
+ wifi_direct_state_changed_cb state_cb;
void *user_data_for_cb_activation;
void *user_data_for_cb_discover;
void *user_data_for_cb_ip_assigned;
void *user_data_for_cb_peer_found;
void *user_data_for_cb_device_name;
+ void *user_data_for_cb_state;
#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
wifi_direct_service_state_changed_cb service_cb;
/*****************************************************************************
* Global Variables
*****************************************************************************/
+
wifi_direct_client_info_s g_client_info = {
.is_registered = FALSE,
.client_id = -1,
.connection_cb = NULL,
.ip_assigned_cb = NULL,
.peer_found_cb = NULL,
+ .state_cb = NULL,
.user_data_for_cb_activation = NULL,
.user_data_for_cb_discover = NULL,
.user_data_for_cb_connection = NULL,
.user_data_for_cb_ip_assigned = NULL,
.user_data_for_cb_peer_found = NULL,
.user_data_for_cb_device_name = NULL,
+ .user_data_for_cb_state = NULL,
#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
.service_cb = NULL,
.user_data_for_cb_service = NULL,
return ret;
}
+void __wfd_vconf_state_changed_cb(keynode_t *key, void *data)
+{
+ __WDC_LOG_FUNC_START__;
+ int state = 0;
+ int res = 0;
+
+ if (!g_client_info.state_cb) {
+ WDC_LOGI("g_state_cb is NULL!!");
+ __WDC_LOG_FUNC_END__;
+ return; //LCOV_EXCL_LINE
+ }
+
+ res = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &state);
+ if (res < 0) {
+ WDC_LOGE("Failed to get vconf value [%s]\n", VCONFKEY_WIFI_DIRECT_STATE);
+ __WDC_LOG_FUNC_END__;
+ return;
+ }
+
+ if (state == VCONFKEY_WIFI_DIRECT_ACTIVATED) {
+ state = WIFI_DIRECT_STATE_ACTIVATED;
+ } else if (state == VCONFKEY_WIFI_DIRECT_DEACTIVATED) {
+ state = WIFI_DIRECT_STATE_DEACTIVATED;
+ } else if (state == VCONFKEY_WIFI_DIRECT_CONNECTED) {
+ state = WIFI_DIRECT_STATE_CONNECTED;
+ } else if (state == VCONFKEY_WIFI_DIRECT_GROUP_OWNER) {
+ state = WIFI_DIRECT_STATE_GROUP_OWNER;
+ } else if (state == VCONFKEY_WIFI_DIRECT_DISCOVERING) {
+ state = WIFI_DIRECT_STATE_DISCOVERING;
+ } else {
+ WDC_LOGE("This state cannot be set as wifi_direct vconf state[%d]", state);
+ __WDC_LOG_FUNC_END__;
+ return;
+ }
+
+ g_client_info.state_cb(state, g_client_info.user_data_for_cb_state);
+
+ __WDC_LOG_FUNC_END__;
+ return;
+}
+
/* Manage */
void wifi_direct_process_manage_activation(GDBusConnection *connection,
const gchar *object_path, GVariant *parameters)
return WIFI_DIRECT_ERROR_NONE;
}
+int wifi_direct_set_state_changed_cb(wifi_direct_state_changed_cb cb, void *user_data)
+{
+ __WDC_LOG_FUNC_START__;
+ int ret = WIFI_DIRECT_ERROR_NONE;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ if (!cb) {
+ WDC_LOGE("Callback is NULL");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = vconf_notify_key_changed(VCONFKEY_WIFI_DIRECT_STATE,
+ __wfd_vconf_state_changed_cb, NULL);
+ if (ret) {
+ WDC_LOGE("Failed to set vconf notification callback");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ g_client_info.state_cb = cb;
+ g_client_info.user_data_for_cb_state = user_data;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
+int wifi_direct_unset_state_changed_cb(void)
+{
+ __WDC_LOG_FUNC_START__;
+ int ret = WIFI_DIRECT_ERROR_NONE;
+
+ CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+ ret = vconf_ignore_key_changed(VCONFKEY_WIFI_DIRECT_STATE,
+ __wfd_vconf_state_changed_cb);
+ if (ret) {
+ WDC_LOGE("Failed to ignore vconf notification callback");
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+ }
+
+ g_client_info.state_cb = NULL;
+ g_client_info.user_data_for_cb_state = NULL;
+
+ __WDC_LOG_FUNC_END__;
+ return WIFI_DIRECT_ERROR_NONE;
+}
+
int wifi_direct_activate(void)
{
__WDC_LOG_FUNC_START__;
if (val == VCONFKEY_WIFI_DIRECT_ACTIVATED) {
*state = WIFI_DIRECT_STATE_ACTIVATED;
} else if (val == VCONFKEY_WIFI_DIRECT_DEACTIVATED) {
- *state= WIFI_DIRECT_STATE_DEACTIVATED;
+ *state = WIFI_DIRECT_STATE_DEACTIVATED;
} else if (val == VCONFKEY_WIFI_DIRECT_CONNECTED) {
*state = WIFI_DIRECT_STATE_CONNECTED;
} else if (val == VCONFKEY_WIFI_DIRECT_GROUP_OWNER) {
CMD_SET_CONNECTION_CB,
CMD_SET_PEER_FOUND_CB,
CMD_SET_DEVICE_NAME_CB,
+ CMD_SET_STATE_CB,
CMD_UNSET_ACTIVATION_CB,
CMD_UNSET_DISCOVER_CB,
CMD_UNSET_SERVICE_CB,
CMD_UNSET_CONNECTION_CB,
CMD_UNSET_PEER_FOUND_CB,
CMD_UNSET_DEVICE_NAME_CB,
+ CMD_UNSET_STATE_CB,
CMD_GET_NETWORK_IF_NAME,
CMD_GET_SUBNET_MASK,
CMD_GET_GATEWAY_ADDR,
{ CMD_SET_CONNECTION_CB, "CMD_SET_CONNECTION_CB" },
{ CMD_SET_PEER_FOUND_CB, "CMD_SET_PEER_FOUND_CB" },
{ CMD_SET_DEVICE_NAME_CB, "CMD_SET_DEVICE_NAME_CB"},
+ { CMD_SET_STATE_CB, "CMD_SET_STATE_CB"},
{ CMD_UNSET_ACTIVATION_CB, "CMD_UNSET_ACTIVATION_CB" },
{ CMD_UNSET_DISCOVER_CB, "CMD_UNSET_DISCOVER_CB" },
{ CMD_UNSET_CONNECTION_CB, "CMD_UNSET_CONNECTION_CB" },
{ CMD_UNSET_PEER_FOUND_CB, "CMD_UNSET_PEER_FOUND_CB" },
+ { CMD_UNSET_STATE_CB, "CMD_UNSET_STATE_CB" },
{ CMD_GET_NETWORK_IF_NAME, "CMD_GET_NETWORK_IF_NAME" },
{ CMD_GET_SUBNET_MASK, "CMD_GET_SUBNET_MASK" },
{ CMD_GET_GATEWAY_ADDR, "CMD_GET_GATEWAY_ADDR" },
return true; /* continue with the next iteration of the loop */
}
+void _cb_state_changed(wifi_direct_state_e state,
+ void *user_data)
+{
+ printf("State Changed [%s]\n", print_link_state(state));
+ return;
+}
+
int init_wfd_client(struct appdata *ad)
{
int ret;
ret = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad);
printf("wifi_direct_set_peer_found_cb() result=[%d]\n", ret);
+ ret = wifi_direct_set_state_changed_cb(_cb_state_changed, (void*)ad);
+ printf("wifi_direct_set_state_changed_cb() result=[%d]\n", ret);
+
return ret;
}
printf("wifi_direct_unset_peer_found_cb() result=[%d]\n", result);
}
break;
-
+ case CMD_SET_STATE_CB:
+ {
+ result = wifi_direct_set_state_changed_cb(_cb_state_changed, (void*)ad);
+ printf("wifi_direct_set_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
+ case CMD_UNSET_STATE_CB:
+ {
+ result = wifi_direct_unset_state_changed_cb();
+ printf("wifi_direct_unset_state_changed_cb() result=[%d]\n", result);
+ }
+ break;
case CMD_DEINITIALIZE:
result = wifi_direct_deinitialize();
printf("wifi_direct_deinitialize() result=[%d]\n", result);