Revert BT enable / disable calling method to async call
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-rfcomm-client.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *              http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <glib.h>
19 #include <dlog.h>
20 #include <string.h>
21 #include <fcntl.h>
22
23 #include <gio/gio.h>
24 #include "bluetooth-api.h"
25 #include "bt-internal-types.h"
26
27 #include "bt-service-common.h"
28 #include "bt-service-event.h"
29 #include "bt-service-util.h"
30 #include "bt-service-rfcomm-client.h"
31 #include "bt-service-rfcomm-server.h"
32
33 typedef struct {
34         int req_id;
35         char *channel;
36         char *address;
37         char *uuid;
38         GDBusProxy *rfcomm_proxy;
39 } rfcomm_function_data_t;
40
41 rfcomm_function_data_t *rfcomm_info;
42 GSList *client_list;
43
44 static int __bt_rfcomm_terminate_client(int socket_fd)
45 {
46         return BLUETOOTH_ERROR_NONE;
47 }
48
49
50 int _bt_rfcomm_connect_using_uuid(int request_id,
51                         bluetooth_device_address_t *device_address,
52                         char *remote_uuid)
53 {
54         return BLUETOOTH_ERROR_NONE;
55 }
56
57 /* Range of the Channel : 0 <= channel <= 30 */
58 int _bt_rfcomm_connect_using_channel(int request_id,
59                         bluetooth_device_address_t *device_address,
60                         char *channel)
61 {
62         return BLUETOOTH_ERROR_NONE;
63 }
64
65 /* Be used in RFCOMM client /server */
66 int _bt_rfcomm_disconnect(int socket_fd)
67 {
68         return __bt_rfcomm_terminate_client(socket_fd);
69 }
70
71 /* Be used in RFCOMM client /server */
72 int _bt_rfcomm_write(int socket_fd, char *buf, int length)
73 {
74         return BLUETOOTH_ERROR_NONE;
75 }
76
77 int _bt_rfcomm_cancel_connect(void)
78 {
79         return BLUETOOTH_ERROR_NONE;
80 }
81
82 int _bt_rfcomm_is_connected(gboolean *connected)
83 {
84         BT_CHECK_PARAMETER(connected, return);
85
86         *connected = (client_list == NULL || g_slist_length(client_list) == 0) ?
87                                         FALSE : TRUE;
88
89         return BLUETOOTH_ERROR_NONE;
90 }
91
92 int _bt_rfcomm_is_device_connected(bluetooth_device_address_t *device_address,
93                                         gboolean *connected)
94 {
95         GSList *l;
96         bt_rfcomm_info_t *client_info;
97         char address[BT_ADDRESS_STRING_SIZE] = { 0 };
98
99         BT_CHECK_PARAMETER(device_address, return);
100         BT_CHECK_PARAMETER(connected, return);
101
102         _bt_convert_addr_type_to_string(address, device_address->addr);
103
104         *connected = FALSE;
105
106         for (l = client_list; l != NULL; l = l->next) {
107                 client_info = l->data;
108
109                 if (client_info == NULL)
110                         continue;
111
112                 if (g_strcmp0(address, client_info->address) == 0) {
113                         *connected = TRUE;
114                         return BLUETOOTH_ERROR_NONE;
115                 }
116         }
117
118         return BLUETOOTH_ERROR_NONE;
119 }
120
121 int _bt_rfcomm_client_disconnect_all(void)
122 {
123         GSList *l;
124         bt_rfcomm_info_t *client_info;
125
126         for (l = client_list; l != NULL; l = l->next) {
127                 client_info = l->data;
128
129                 if (client_info == NULL)
130                         continue;
131
132                 _bt_rfcomm_disconnect(client_info->fd);
133         }
134
135         return BLUETOOTH_ERROR_NONE;
136 }
137