2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "bluetooth-hid-agent.h"
19 #include "bluetooth-hid-manager.h"
21 static GSList *sender_list;
22 static bt_hid_state_t hid_state;
24 static const char *__bt_hid_state2str(bt_hid_state_t state)
27 case BT_HID_STATE_UNAVAILABLE:
29 case BT_HID_STATE_DISCONNECTED:
30 return "DISCONNECTED";
31 case BT_HID_STATE_CONNECTING:
33 case BT_HID_STATE_CONNECTED:
35 case BT_HID_STATE_DISCONNECTING:
36 return "DISCONNECTING";
42 static gboolean __bt_hid_check_for_callpath(const char *call_sender)
44 GSList *s_list = sender_list;
47 DBG_SECURE("sender is = %s\n", call_sender);
49 if (call_sender == NULL) {
50 ERR("Invalid Parameters");
54 /*check if the call is already registered*/
55 DBG("Checking if the call is already registered");
56 while (s_list != NULL) {
57 sender = s_list->data;
62 if (g_strcmp0(sender, call_sender) == 0) {
63 DBG("sender path and call path match... so return true");
67 s_list = s_list->next;
70 INFO("Sender [%s] is not registered", call_sender);
74 bt_hid_agent_error_t _bt_hid_register_application(gboolean register_flag,
80 return BT_HID_AGENT_ERROR_INVALID_PARAM;
82 if (register_flag == TRUE) {
83 if (__bt_hid_check_for_callpath(sender) == TRUE) {
84 ERR("Already registered [sender:%s]", sender);
85 return BT_HID_AGENT_ERROR_ALREADY_EXIST;
88 INFO("Registered [sender:%s]", sender);
90 /* add the call path to the sender list */
91 sender_name = g_strdup(sender);
92 sender_list = g_slist_append(sender_list, sender_name);
94 /*remove the call from senders list */
95 GSList *s_list = sender_list;
97 while (s_list != NULL) {
98 sender_name = s_list->data;
100 if (sender_name == NULL)
101 return BT_HID_AGENT_ERROR_NOT_AVAILABLE;
103 if (g_strcmp0(sender_name, sender) == 0) {
104 sender_list = g_slist_remove(sender_list, sender_name);
107 if (sender_list == NULL && hid_state == BT_HID_STATE_CONNECTED)
108 _bt_hid_disconnect_profile();
110 INFO("Unregistered [sender:%s]", sender);
112 return BT_HID_AGENT_ERROR_NONE;
114 s_list = s_list->next;
117 return BT_HID_AGENT_ERROR_NOT_AVAILABLE;
120 return BT_HID_AGENT_ERROR_NONE;
123 void _bt_hid_set_profile_state(bt_hid_state_t new_state)
125 INFO_C("state changed [%s] =>[%s]", __bt_hid_state2str(hid_state),
126 __bt_hid_state2str(new_state));
127 hid_state = new_state;
130 case BT_HID_STATE_UNAVAILABLE:
131 case BT_HID_STATE_DISCONNECTED:
133 case BT_HID_STATE_CONNECTED:
134 if (sender_list == NULL)
135 _bt_hid_disconnect_profile();
137 case BT_HID_STATE_CONNECTING:
138 case BT_HID_STATE_DISCONNECTING:
144 bt_hid_state_t _bt_hid_get_profile_state(void)
149 const GSList* _bt_hid_get_sender_list(void)