+static void __rfcomm_client_connection_create_watch(rfcomm_client_conn_info_t *conn_info)
+{
+ GIOChannel *data_io;
+
+ ret_if(NULL == conn_info);
+
+ BT_DBG("+");
+
+ data_io = g_io_channel_unix_new(conn_info->sock_fd);
+ g_io_channel_set_encoding(data_io, NULL, NULL);
+ g_io_channel_set_flags(data_io, G_IO_FLAG_NONBLOCK, NULL);
+ conn_info->watch_id = g_io_add_watch(data_io,
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ __client_data_received_cb, NULL);
+ g_io_channel_unref(data_io);
+
+ BT_DBG("-");
+}
+
+static void __bt_rfcomm_handle_new_client_connection(bluetooth_rfcomm_connection_t *info)
+{
+ rfcomm_client_conn_info_t *conn_info;
+
+ ret_if(NULL == info);
+
+ BT_DBG("+");
+
+ conn_info = g_malloc0(sizeof(rfcomm_client_conn_info_t));
+ conn_info->remote_addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ _bt_convert_addr_type_to_string(
+ conn_info->remote_addr, info->device_addr.addr);
+ conn_info->uuid = g_strdup(info->uuid);
+ conn_info->sock_fd = info->socket_fd;
+
+ BT_DBG("Address:%s, UUID:%s Socket: %d",
+ conn_info->remote_addr, conn_info->uuid, conn_info->sock_fd);
+
+ rfcomm_clients = g_slist_append(rfcomm_clients, conn_info);
+ __rfcomm_client_connection_create_watch(conn_info);
+
+ BT_DBG("-");
+}
+
+static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
+{
+ char *data;
+ int size;
+
+ size = g_variant_get_size(var);
+ if (size > 0) {
+ data = (char *)g_variant_get_data(var);
+ if (data)
+ param = g_array_append_vals(param, data, size);
+
+ }
+}
+
+
+/* TODO_40 : 4.0 merge */
+/* Don't use this function directly. Instead of it, get the out parameter only */
+static void __bt_get_event_info(int service_function, GArray *output,
+ int *event, int *event_type, void **param_data)
+{
+ ret_if(event == NULL);
+
+ BT_DBG("service_function : %s (0x%x)",
+ _bt_convert_service_function_to_string(service_function),
+ service_function);
+ switch (service_function) {
+ case BT_RFCOMM_CLIENT_CONNECT:
+ *event_type = BT_RFCOMM_CLIENT_EVENT;
+ *event = BLUETOOTH_EVENT_RFCOMM_CONNECTED;
+ ret_if(output == NULL);
+ *param_data = &g_array_index(output,
+ bluetooth_rfcomm_connection_t, 0);
+ break;
+ default:
+ BT_ERR("Unknown function");
+ return;
+ }
+}
+
+
+static void __async_req_cb_with_unix_fd_list(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data)
+{
+ int result = BLUETOOTH_ERROR_NONE;
+ int event_type = BT_ADAPTER_EVENT;
+ bt_req_info_t *cb_data = user_data;
+ bluetooth_event_param_t bt_event;
+
+ GError *error = NULL;
+ GVariant *value;
+ GVariant *param1;
+ GArray *out_param1 = NULL;
+ GUnixFDList *out_fd_list = NULL;
+
+ BT_DBG("+");
+
+ memset(&bt_event, 0x00, sizeof(bluetooth_event_param_t));
+
+ value = g_dbus_proxy_call_with_unix_fd_list_finish(proxy, &out_fd_list, res, &error);
+ if (value == NULL) {
+ if (error) {
+ /* dBUS gives error cause */
+ BT_ERR("D-Bus API failure: message[%s]",
+ error->message);
+ g_clear_error(&error);
+ }
+ result = BLUETOOTH_ERROR_TIMEOUT;
+
+ ret_if(cb_data == NULL);
+
+ __bt_get_event_info(cb_data->service_function, NULL,
+ &bt_event.event, &event_type,
+ &bt_event.param_data);
+ goto failed;
+ }
+
+ g_variant_get(value, "(iv)", &result, ¶m1);
+ g_variant_unref(value);
+
+ if (param1) {
+ out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
+ __bt_fill_garray_from_variant(param1, out_param1);
+ g_variant_unref(param1);
+ }
+
+ if (!cb_data)
+ goto done;
+
+ __bt_get_event_info(cb_data->service_function, out_param1,
+ &bt_event.event, &event_type,
+ &bt_event.param_data);
+
+ if (result == BLUETOOTH_ERROR_NONE && out_param1) {
+ if (BT_RFCOMM_CLIENT_CONNECT == cb_data->service_function) {
+ int *fd_list_array;
+ int len = 0;
+ bluetooth_rfcomm_connection_t *conn_info;
+
+ conn_info = (bluetooth_rfcomm_connection_t *)bt_event.param_data;
+ if (!out_fd_list) {
+ BT_ERR("out_fd_list is NULL");
+ goto failed;
+ }
+
+ fd_list_array = g_unix_fd_list_steal_fds(out_fd_list, &len);
+ BT_INFO("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
+ conn_info->socket_fd = fd_list_array[0];
+
+ BT_DBG("conn_info->socket_fd: %d", conn_info->socket_fd);
+ __bt_rfcomm_handle_new_client_connection(conn_info);
+
+ if (cb_data->cb != NULL) {
+ /* Send client connected event */
+ bt_event.result = result;
+ BT_INFO("event_type[%d], result=[%d]", event_type, result);
+ ((bluetooth_cb_func_ptr)cb_data->cb)(
+ bt_event.event, &bt_event, cb_data->user_data);
+ }
+
+ g_free(fd_list_array);
+ g_object_unref(out_fd_list);
+ }
+ goto done;
+ }
+
+failed:
+ if (cb_data->cb == NULL)
+ goto done;
+
+ /* Only if fail case, call the callback function*/
+ bt_event.result = result;
+
+ BT_INFO("event_type[%d], result=[%d]", event_type, result);
+ if (event_type == BT_RFCOMM_CLIENT_EVENT) {
+ ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
+ &bt_event, cb_data->user_data);
+ } else {
+ BT_INFO("Not handled event type : %d", event_type);
+ }
+done:
+ if (out_param1)
+ g_array_free(out_param1, TRUE);
+
+ g_free(cb_data);
+ BT_DBG("-");
+}
+#endif
+