tizen 2.3.1 release
[apps/home/b2-clocksetting.git] / src / setting_control_bt.c
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  *  Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include "setting_control_bt.h"
18 #include "setting_debug.h"
19 #include <stdio.h>
20
21 int hf_is_connected()
22 {
23         int ret;
24         int i;
25         GPtrArray *dev_list = NULL;
26         bluetooth_device_info_t *dev;
27         gboolean is_connected = FALSE;
28
29         dev_list = g_ptr_array_new();
30         if (dev_list == NULL) {
31                 printf("Setting - g_ptr_array_new is failed\n");
32                 return FALSE;
33         }
34
35         ret = bluetooth_get_bonded_device_list(&dev_list);
36         if (ret != BLUETOOTH_ERROR_NONE) {
37                 printf("Setting - bluetooth_get_bonded_device_list is failed 0x%X\n", ret);
38                 g_ptr_array_free(dev_list, TRUE);
39                 return FALSE;
40         }
41
42         for (i = 0; i < dev_list->len; i++) {
43                 is_connected = FALSE;
44
45                 dev = g_ptr_array_index(dev_list, i);
46                 if (dev  == NULL) {
47                         printf("Setting - Invalid bluetooth device\n");
48                         break;
49                 }
50
51                 ret = bluetooth_is_device_connected(&dev->device_address,
52                                                                                         BLUETOOTH_HFG_SERVICE, &is_connected);
53                 if (ret == BLUETOOTH_ERROR_NONE && is_connected) {
54                         break;
55                 }
56         }
57
58         g_ptr_array_foreach(dev_list, (GFunc)g_free, NULL);
59         g_ptr_array_free(dev_list, TRUE);
60
61         DBG("Setting - connected? %d", is_connected);
62
63         return is_connected;
64 }