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