Merge branch 'tizen' into tizen_5.5
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-proximity.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 "bluetooth-api.h"
19 #include "bt-internal-types.h"
20
21 #include "bt-common.h"
22 #include "bt-request-sender.h"
23 #include "bt-event-handler.h"
24
25 BT_EXPORT_API int bluetooth_proximity_monitor_set_property(const bluetooth_device_address_t *device_address,
26                                                         bluetooth_pxp_poperty_t property, int value)
27 {
28         int result = BLUETOOTH_ERROR_INTERNAL;
29
30         BT_CHECK_PARAMETER(device_address, return);
31         BT_CHECK_ENABLED(return);
32
33         BT_INIT_PARAMS();
34         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
35         BT_DBG("");
36
37         g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
38         g_array_append_vals(in_param2, &property, sizeof(int));
39         g_array_append_vals(in_param3, &value, sizeof(int));
40
41         result = _bt_send_request(BT_BLUEZ_SERVICE, BT_PXP_MONITOR_SET_PROPERTY,
42                 in_param1, in_param2, in_param3, in_param4, &out_param);
43
44         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
45
46         return result;
47 }
48
49 BT_EXPORT_API int bluetooth_proximity_monitor_get_property(const bluetooth_device_address_t *device_address,
50                                                         bluetooth_pxp_poperty_t property, int *value)
51 {
52         int result = BLUETOOTH_ERROR_INTERNAL;
53
54         BT_CHECK_PARAMETER(device_address, return);
55         BT_CHECK_ENABLED(return);
56
57         BT_INIT_PARAMS();
58         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
59         BT_DBG("");
60
61         g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
62         g_array_append_vals(in_param2, &property, sizeof(int));
63
64         result = _bt_send_request(BT_BLUEZ_SERVICE, BT_PXP_MONITOR_GET_PROPERTY,
65                 in_param1, in_param2, in_param3, in_param4, &out_param);
66
67         if (result == BLUETOOTH_ERROR_NONE) {
68                 if (out_param->len > 0) {
69                         *value = g_array_index(out_param,
70                                         int, 0);
71                 } else {
72                         BT_ERR("out_param length is 0!!");
73                 }
74         }
75
76         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
77
78         return result;
79 }
80
81 BT_EXPORT_API int bluetooth_proximity_monitor_get_supported_services(const bluetooth_device_address_t *device_address,
82                                                         int *services_supported)
83 {
84         int result = BLUETOOTH_ERROR_INTERNAL;
85
86         BT_CHECK_PARAMETER(device_address, return);
87         BT_CHECK_ENABLED(return);
88
89         BT_INIT_PARAMS();
90         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
91         BT_DBG("");
92
93         g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
94
95         result = _bt_send_request(BT_BLUEZ_SERVICE, BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES,
96                 in_param1, in_param2, in_param3, in_param4, &out_param);
97
98         if (result == BLUETOOTH_ERROR_NONE) {
99                 if (out_param->len > 0) {
100                         *services_supported = g_array_index(out_param,
101                                         int, 0);
102                 } else {
103                         BT_ERR("out_param length is 0!!");
104                 }
105         }
106
107         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
108
109         return result;
110 }
111
112 BT_EXPORT_API int bluetooth_proximity_reporter_register()
113 {
114         int result = BLUETOOTH_ERROR_INTERNAL;
115
116         BT_CHECK_ENABLED(return);
117
118         BT_INIT_PARAMS();
119         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
120         BT_DBG("");
121
122         result = _bt_send_request(BT_BLUEZ_SERVICE, BT_PXP_REPORTER_REGISTER,
123                 in_param1, in_param2, in_param3, in_param4, &out_param);
124
125         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
126
127         return result;
128 }
129
130 BT_EXPORT_API int bluetooth_proximity_reporter_unregister()
131 {
132         int result = BLUETOOTH_ERROR_INTERNAL;
133
134         BT_CHECK_ENABLED(return);
135
136         BT_INIT_PARAMS();
137         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
138         BT_DBG("");
139
140         result = _bt_send_request(BT_BLUEZ_SERVICE, BT_PXP_REPORTER_UNREGISTER,
141                 in_param1, in_param2, in_param3, in_param4, &out_param);
142
143         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
144
145         return result;
146 }
147
148 BT_EXPORT_API int bluetooth_proximity_reporter_get_property(const bluetooth_device_address_t *device_address,
149                                                         bluetooth_pxp_poperty_t property, int *value)
150 {
151         int result = BLUETOOTH_ERROR_INTERNAL;
152
153         BT_CHECK_PARAMETER(device_address, return);
154         BT_CHECK_ENABLED(return);
155
156         BT_INIT_PARAMS();
157         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
158         BT_DBG("");
159
160         g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
161         g_array_append_vals(in_param2, &property, sizeof(int));
162
163         result = _bt_send_request(BT_BLUEZ_SERVICE, BT_PXP_REPORTER_GET_PROPERTY,
164                 in_param1, in_param2, in_param3, in_param4, &out_param);
165
166         if (result == BLUETOOTH_ERROR_NONE) {
167                 if (out_param->len > 0) {
168                         *value = g_array_index(out_param,
169                                         int, 0);
170                 } else {
171                         BT_ERR("out_param length is 0!!");
172                 }
173         }
174
175         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
176
177         return result;
178 }