* @param[in] error_code The error code
* @param[in] discovery_state The discovery state
* @param[in] user_data The user data passed from the callback registration function
- * @pre Either wifi_direct_start_discovery() or wifi_direct_cancel_discovery() will invoke this callback
- * if you register this callback using wifi_direct_set_discovery_state_changed_cb().
+ * @pre Either wifi_direct_start_discovery() or wifi_direct_cancel_discovery()
+ * will invoke this callback in the thread-default main context of the thread
+ * from which you registered this callback using
+ * wifi_direct_set_discovery_state_changed_cb().
* @see wifi_direct_start_discovery()
* @see wifi_direct_cancel_discovery()
* @see wifi_direct_set_discovery_state_changed_cb()
* @param[in] discovery_state The discovery state
* @param[in] mac_address The MAC address of found peer
* @param[in] user_data The user data passed from the callback registration function
- * @pre Either wifi_direct_start_discovery() or wifi_direct_cancel_discovery() will invoke this callback
- * if you register this callback using wifi_direct_set_discovery_state_changed_cb().
+ * @pre Either wifi_direct_start_discovery() or wifi_direct_cancel_discovery()
+ * will invoke this callback in the thread-default main context of the thread
+ * from which you registered this callback using wifi_direct_set_peer_found_cb()
* @see wifi_direct_start_discovery()
* @see wifi_direct_cancel_discovery()
- * @see wifi_direct_set_discovery_state_changed_cb()
- * @see wifi_direct_unset_discovery_state_changed_cb()
+ * @see wifi_direct_set_peer_found_cb()
+ * @see wifi_direct_unset_peer_found_cb()
*/
typedef void (*wifi_direct_peer_found_cb) (int error_code,
wifi_direct_discovery_state_e discovery_state,
* @param[in] error_code The error code
* @param[in] device_state The device state
* @param[in] user_data The user data passed from the callback registration function
- * @pre Either wifi_direct_activate() or wifi_direct_deactivate() will invoke this callback
- * if you register this callback using wifi_direct_set_device_state_changed_cb().
+ * @pre Either wifi_direct_activate() or wifi_direct_deactivate() will invoke
+ * this callback in the thread-default main context of the thread from which you
+ * registered this callback using wifi_direct_set_device_state_changed_cb().
* @see wifi_direct_activate()
* @see wifi_direct_deactivate()
* @see wifi_direct_set_device_state_changed_cb()
* @param[in] connection_state The connection state
* @param[in] mac_address The MAC address of the connection peer
* @param[in] user_data The user data passed from the callback registration function
- * @pre wifi_direct_create_group(), wifi_direct_destroy_group(), wifi_direct_connect(), wifi_direct_disconnect() or wifi_direct_disconnect_all() will invoke this callback
+ * @pre wifi_direct_create_group(), wifi_direct_destroy_group(),
+ * wifi_direct_connect(), wifi_direct_disconnect() or
+ * wifi_direct_disconnect_all() will invoke this callback in the thread-default
+ * main context of the thread from which you registered this callback using
* if you register this callback using wifi_direct_set_connection_state_changed_cb().
* @see wifi_direct_connect()
* @see wifi_direct_disconnect()
* @param[in] ip_address The IP address of connection peer
* @param[in] interface_address The interface address of connection peer
* @param[in] user_data The user data passed from the callback registration function
+ * @pre This callback will be invoked in the thread-default main context of the
+ * thread from which you registered this callback using
+ * wifi_direct_set_client_ip_address_assigned_cb().
* @see wifi_direct_set_client_ip_address_assigned_cb()
* @see wifi_direct_unset_client_ip_address_assigned_cb()
*/
* @param[in] service_type Specifies the types of service
* @param[in] response_data Received response
* @param[in] user_data User can transfer the user specific data in callback
- * @pre Either wifi_direct_start_service_discovery() or wifi_direct_cancel_service_discovery() will invoke this callback
- * if you register this callback using wifi_direct_set_service_state_changed_cb().
+ * @pre Either wifi_direct_start_service_discovery() or
+ * wifi_direct_cancel_service_discovery() will invoke this callback in the
+ * thread-default main context of thethread from which you registered this
+ * callback using wifi_direct_set_service_state_changed_cb().
* @see wifi_direct_start_discovery()
* @see wifi_direct_cancel_discovery()
* @see wifi_direct_set_discovery_state_changed_cb()
Name: capi-network-wifi-direct
Summary: Network WiFi-Direct Library
-Version: 1.2.68
+Version: 1.2.69
Release: 1
Group: Network & Connectivity/API
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
+BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(gthread-2.0)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(capi-base-common)
#include <stdbool.h>
#include "wifi-direct.h"
-#define SOCK_FD_MIN 3
-#define WIFI_DIRECT_WPA_LEN 64
#define MACSTR_LEN 18
#define MACADDR_LEN 6
#define IPADDR_LEN 4
#define IPSTR_LEN 16
-#define WFD_SOCK_FILE_PATH "/tmp/wfd_client_socket"
-#define WIFIDIRECT_FEATURE "http://tizen.org/feature/network.wifi.direct"
-#define WIFIDIRECT_DISPLAY_FEATURE "http://tizen.org/feature/network.wifi.direct.display"
-#define WIFIDIRECT_SERVICE_DISCOVERY_FEATURE "http://tizen.org/feature/network.wifi.direct.service_discovery"
+#define WIFIDIRECT_FEATURE\
+ "http://tizen.org/feature/network.wifi.direct"
+#define WIFIDIRECT_DISPLAY_FEATURE\
+ "http://tizen.org/feature/network.wifi.direct.display"
+#define WIFIDIRECT_SERVICE_DISCOVERY_FEATURE\
+ "http://tizen.org/feature/network.wifi.direct.service_discovery"
#define CHECK_FEATURE_SUPPORTED(feature_name)\
do {\
bool feature_supported = FALSE;\
- if (!system_info_get_platform_bool(feature_name, &feature_supported)) {\
+ if (!system_info_get_platform_bool(feature_name,\
+ &feature_supported)) {\
if (feature_supported == FALSE) {\
LOGE("%s feature is disabled", feature_name);\
return WIFI_DIRECT_ERROR_NOT_SUPPORTED;\
typedef struct {
bool is_registered;
- int client_id;
- int sync_sockfd;
- int async_sockfd;
- int g_client_info;
- int g_source_id;
- wifi_direct_device_state_changed_cb activation_cb;
- wifi_direct_discovery_state_chagned_cb discover_cb;
- 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;
+ wifi_direct_device_state_changed_cb activation_cb;
void *user_data_for_cb_activation;
+
+ wifi_direct_discovery_state_chagned_cb discover_cb;
void *user_data_for_cb_discover;
+
+ wifi_direct_connection_state_changed_cb connection_cb;
void *user_data_for_cb_connection;
+
+ wifi_direct_client_ip_address_assigned_cb ip_assigned_cb;
void *user_data_for_cb_ip_assigned;
+
+ wifi_direct_peer_found_cb peer_found_cb;
void *user_data_for_cb_peer_found;
- void *user_data_for_cb_device_name;
+
+ wifi_direct_state_changed_cb state_cb;
void *user_data_for_cb_state;
#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
void *user_data_for_cb_service;
#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
- pthread_mutex_t mutex;
} wifi_direct_client_info_s;
extern char *wfd_debug_print(char *file, int line, char *format, ...);
#define WFD_MANAGER_QUARK (g_quark_from_string("wifi-direct-manager"))
-#define wifi_direct_dbus_method_call_sync(interface_name, method, params, error) \
- wifi_direct_dbus_method_call_sync_debug(interface_name, method, params, error, __func__)
+#define wifi_direct_dbus_method_call_sync(interface_name, method, params,\
+ error)\
+ wifi_direct_dbus_method_call_sync_debug(interface_name, method, params,\
+ error, __func__)
-#define DBUS_DEBUG_VARIANT(parameters) \
+#define DBUS_DEBUG_VARIANT(parameters)\
do {\
gchar *parameters_debug_str = NULL;\
if (parameters)\
- parameters_debug_str = g_variant_print(parameters, TRUE);\
- WDC_LOGD("signal params [%s]", parameters_debug_str ? parameters_debug_str : "NULL");\
+ parameters_debug_str = g_variant_print(parameters,\
+ TRUE);\
+ WDC_LOGD("signal params [%s]",\
+ parameters_debug_str ? parameters_debug_str : "NULL");\
g_free(parameters_debug_str);\
} while (0)
* Global Variables
*****************************************************************************/
-wifi_direct_client_info_s g_client_info = {
- .is_registered = FALSE,
- .client_id = -1,
- .sync_sockfd = -1,
- .async_sockfd = -1,
- .activation_cb = NULL,
- .discover_cb = NULL,
- .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,
-#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
-
- .mutex = PTHREAD_MUTEX_INITIALIZER
-};
+static __thread wifi_direct_client_info_s g_client_info = {0, };
/*****************************************************************************
* Local Functions Definition
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_LOGE("Failed to get vconf value [%s]\n",
+ VCONFKEY_WIFI_DIRECT_STATE);
__WDC_LOG_FUNC_END__;
return;
}
/* Initialize callbacks */
g_client_info.activation_cb = NULL;
+ g_client_info.user_data_for_cb_activation = NULL;
+
g_client_info.discover_cb = NULL;
+ g_client_info.user_data_for_cb_discover = NULL;
+
g_client_info.connection_cb = NULL;
+ g_client_info.user_data_for_cb_connection = NULL;
+
g_client_info.ip_assigned_cb = NULL;
+ g_client_info.user_data_for_cb_ip_assigned = NULL;
g_client_info.peer_found_cb = NULL;
- g_client_info.user_data_for_cb_activation = NULL;
- g_client_info.user_data_for_cb_discover = NULL;
- g_client_info.user_data_for_cb_connection = NULL;
- g_client_info.user_data_for_cb_ip_assigned = NULL;
g_client_info.user_data_for_cb_peer_found = NULL;
- g_client_info.user_data_for_cb_device_name = NULL;
#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
g_client_info.service_cb = NULL;
wifi_direct_dbus_deinit();
g_client_info.activation_cb = NULL;
- g_client_info.discover_cb = NULL;
- g_client_info.connection_cb = NULL;
- g_client_info.ip_assigned_cb = NULL;
- g_client_info.peer_found_cb = NULL;
g_client_info.user_data_for_cb_activation = NULL;
+
+ g_client_info.discover_cb = NULL;
g_client_info.user_data_for_cb_discover = NULL;
+
+ g_client_info.connection_cb = NULL;
g_client_info.user_data_for_cb_connection = NULL;
+
+ g_client_info.ip_assigned_cb = NULL;
g_client_info.user_data_for_cb_ip_assigned = NULL;
+
+ g_client_info.peer_found_cb = NULL;
g_client_info.user_data_for_cb_peer_found = NULL;
#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
guint signal_subscribe_id;
} gdbus_connection_data;
-static gdbus_connection_data gdbus_conn = {NULL, 0};
+static __thread gdbus_connection_data gdbus_conn = {NULL, 0};
static struct {
const char *interface;
};
static void _wifi_direct_dbus_signal_cb(GDBusConnection *connection,
- const gchar *sender, const gchar *object_path,
- const gchar *interface, const gchar *signal,
- GVariant *parameters, gpointer user_data)
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface,
+ const gchar *signal,
+ GVariant *parameters,
+ gpointer user_data)
{
int i = 0;
for (i = 0; wifi_direct_dbus_signal_map[i].member != NULL; i++) {
if (!g_strcmp0(signal, wifi_direct_dbus_signal_map[i].member) &&
- !g_strcmp0(interface, wifi_direct_dbus_signal_map[i].interface) &&
+ !g_strcmp0(interface,
+ wifi_direct_dbus_signal_map[i].interface) &&
wifi_direct_dbus_signal_map[i].function != NULL) {
- wifi_direct_dbus_signal_map[i].function(connection, object_path, parameters);
+ wifi_direct_dbus_signal_map[i].function(connection,
+ object_path,
+ parameters);
break;
}
}
params, /* GVariant *params */
NULL, /* reply_type */
G_DBUS_CALL_FLAGS_NONE, /* flags */
- WIFI_DIRECT_DBUS_REPLY_TIMEOUT_SYNC, /* timeout */
+ WIFI_DIRECT_DBUS_REPLY_TIMEOUT_SYNC,
+ /* timeout */
NULL, /* cancellable */
error); /* error */
DBUS_DEBUG_VARIANT(reply);
gboolean wifi_direct_dbus_init(void)
{
GError *Error = NULL;
- GDBusConnection *connection = NULL;
- connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &Error);
- if (connection == NULL) {
+ if (gdbus_conn.signal_subscribe_id > 0) {
+ WDC_LOGI("GDbusConnection already initialized");
+ return TRUE;
+ }
+
+ gdbus_conn.connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &Error);
+ if (gdbus_conn.connection == NULL) {
WDC_LOGE("Failed to get connection, Error[%s]", Error->message);
g_error_free(Error); //LCOV_EXCL_LINE
return FALSE; //LCOV_EXCL_LINE
}
- gdbus_conn.connection = connection;
-
/* subscribe signal handler */
- gdbus_conn.signal_subscribe_id = g_dbus_connection_signal_subscribe(connection,
- WFD_MANAGER_SERVICE, /* bus name */
- NULL, /* interface */
- NULL, /* member */
- WFD_MANAGER_PATH, /* object_path */
- NULL, /* arg0 */
- G_DBUS_SIGNAL_FLAGS_NONE,
- _wifi_direct_dbus_signal_cb,
- NULL,
- NULL);
- WDC_LOGI("Subscribed dbus signals [%d]", gdbus_conn.signal_subscribe_id);
+ gdbus_conn.signal_subscribe_id =
+ g_dbus_connection_signal_subscribe(gdbus_conn.connection,
+ WFD_MANAGER_SERVICE, /* bus name */
+ NULL, /* interface */
+ NULL, /* member */
+ WFD_MANAGER_PATH, /* object_path */
+ NULL, /* arg0 */
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ _wifi_direct_dbus_signal_cb,
+ NULL,
+ NULL);
+ WDC_LOGI("Subscribed dbus signals [%d]",
+ gdbus_conn.signal_subscribe_id);
+
return TRUE;
}
return;
/* unsubscribe signal handler */
- g_dbus_connection_signal_unsubscribe(gdbus_conn.connection, gdbus_conn.signal_subscribe_id);
+ g_dbus_connection_signal_unsubscribe(gdbus_conn.connection,
+ gdbus_conn.signal_subscribe_id);
gdbus_conn.signal_subscribe_id = 0;
/* unref gdbus connection */