tizen 2.3 release
[apps/home/b2-clocksetting.git] / src / setting_control_bt.c
1 /*
2  * Copyright (c) 2010 Samsung Electronics, Inc.
3  * All rights reserved.
4  *
5  * This software is a confidential and proprietary information
6  * of Samsung Electronics, Inc. ("Confidential Information").  You
7  * shall not disclose such Confidential Information and shall use
8  * it only in accordance with the terms of the license agreement
9  * you entered into with Samsung Electronics.
10  */
11 #include "setting_control_bt.h"
12 #include "setting_debug.h"
13 #include <stdio.h>
14
15 int hf_is_connected()
16 {
17         int ret;
18         int i;
19         GPtrArray *dev_list = NULL;
20         bluetooth_device_info_t *dev;
21         gboolean is_connected = FALSE;
22
23         dev_list = g_ptr_array_new();
24         if (dev_list == NULL) {
25                 printf("Setting - g_ptr_array_new is failed\n");
26                 return FALSE;
27         }
28
29         ret = bluetooth_get_bonded_device_list(&dev_list);
30         if (ret != BLUETOOTH_ERROR_NONE) {
31                 printf("Setting - bluetooth_get_bonded_device_list is failed 0x%X\n", ret);
32                 g_ptr_array_free(dev_list, TRUE);
33                 return FALSE;
34         }
35
36         for (i = 0; i < dev_list->len; i++) {
37                 is_connected = FALSE;
38
39                 dev = g_ptr_array_index(dev_list, i);
40                 if (dev  == NULL) {
41                         printf("Setting - Invalid bluetooth device\n");
42                         break;
43                 }
44
45                 ret = bluetooth_is_device_connected(&dev->device_address,
46                                 BLUETOOTH_HFG_SERVICE, &is_connected);
47                 if (ret == BLUETOOTH_ERROR_NONE && is_connected) {
48                         break;
49                 }
50         }
51
52         if (dev_list != NULL) {
53                 g_ptr_array_foreach(dev_list, (GFunc)g_free, NULL);
54                 g_ptr_array_free(dev_list, TRUE);
55         }
56
57         DBG("Setting - connected? %d", is_connected);
58
59         return is_connected;
60 }