From a18efc654e0a7e1459ae2d7d823f9991a51db40b Mon Sep 17 00:00:00 2001 From: Deokhyun Kim Date: Fri, 13 Oct 2017 14:57:06 +0900 Subject: [PATCH] Support multiple registration for HID device - hid_device_activate fails when another app is already resistered on background. Change-Id: I16bc2643c4df41c31f28ef77c3f902fe37a21785 Signed-off-by: Deokhyun Kim Signed-off-by: DoHyun Pyun --- hid-agent/bluetooth-hid-agent.c | 27 ++++++++------ hid-agent/bluetooth-hid-agent.h | 6 +--- hid-agent/bluetooth-hid-manager.c | 75 +++++++++++++-------------------------- hid-agent/bluetooth-hid-manager.h | 28 +++++++++++++++ 4 files changed, 70 insertions(+), 66 deletions(-) create mode 100644 hid-agent/bluetooth-hid-manager.h diff --git a/hid-agent/bluetooth-hid-agent.c b/hid-agent/bluetooth-hid-agent.c index 031d16a..542d895 100644 --- a/hid-agent/bluetooth-hid-agent.c +++ b/hid-agent/bluetooth-hid-agent.c @@ -23,6 +23,7 @@ #include #include "bluetooth-hid-agent.h" +#include "bluetooth-hid-manager.h" static GMainLoop *gmain_loop; static char *g_obj_path; @@ -152,11 +153,13 @@ static void __bt_hid_name_owner_changed_cb(GDBusConnection *connection, ret = _bt_hid_register_application(FALSE, name_owner); if (ret == BT_HID_AGENT_ERROR_NONE) { - is_hid_connectable = FALSE; - if (name_owner_sig_id > 0) { - g_dbus_connection_signal_unsubscribe(gdbus_conn, - name_owner_sig_id); - name_owner_sig_id = 0; + if (_bt_hid_get_sender_list() == NULL) { + is_hid_connectable = FALSE; + if (name_owner_sig_id > 0) { + g_dbus_connection_signal_unsubscribe(gdbus_conn, + name_owner_sig_id); + name_owner_sig_id = 0; + } } } } @@ -196,11 +199,13 @@ static void __hid_agent_method(GDBusConnection *connection, ret = _bt_hid_register_application(FALSE, sender); if (ret == BT_HID_AGENT_ERROR_NONE) { - is_hid_connectable = FALSE; - if (name_owner_sig_id > 0) { - g_dbus_connection_signal_unsubscribe(gdbus_conn, - name_owner_sig_id); - name_owner_sig_id = 0; + if (_bt_hid_get_sender_list() == NULL) { + is_hid_connectable = FALSE; + if (name_owner_sig_id > 0) { + g_dbus_connection_signal_unsubscribe(gdbus_conn, + name_owner_sig_id); + name_owner_sig_id = 0; + } } } else { goto fail; @@ -798,7 +803,7 @@ static void __bt_hid_agent_dbus_deinit(void) -bt_hid_agent_error_t __bt_hid_disconnect_profile(void) +bt_hid_agent_error_t _bt_hid_disconnect_profile(void) { FN_START; GDBusProxy *proxy; diff --git a/hid-agent/bluetooth-hid-agent.h b/hid-agent/bluetooth-hid-agent.h index 9a24cb3..8552031 100644 --- a/hid-agent/bluetooth-hid-agent.h +++ b/hid-agent/bluetooth-hid-agent.h @@ -158,10 +158,6 @@ struct sockaddr_remote { uint8_t channel; }; -void _bt_hid_set_profile_state(bt_hid_state_t new_state); -bt_hid_agent_error_t _bt_hid_register_application(gboolean register_flag, - const char *sender_name); - -bt_hid_agent_error_t __bt_hid_disconnect_profile(void); +bt_hid_agent_error_t _bt_hid_disconnect_profile(void); #endif /* __DEF_BT_HID_AGENT_H_ */ diff --git a/hid-agent/bluetooth-hid-manager.c b/hid-agent/bluetooth-hid-manager.c index f101b32..ee53090 100644 --- a/hid-agent/bluetooth-hid-manager.c +++ b/hid-agent/bluetooth-hid-manager.c @@ -16,8 +16,9 @@ */ #include "bluetooth-hid-agent.h" +#include "bluetooth-hid-manager.h" -static char *sender; +static GSList *sender_list; static bt_hid_state_t hid_state; static const char *__bt_hid_state2str(bt_hid_state_t state) @@ -38,16 +39,14 @@ static const char *__bt_hid_state2str(bt_hid_state_t state) return NULL; } -#if 0 static gboolean __bt_hid_check_for_callpath(const char *call_sender) { - GSList *s_list = app_list; + GSList *s_list = sender_list; char *sender; DBG_SECURE("sender is = %s\n", call_sender); if (call_sender == NULL) { - ERR("Invalid Parameters"); return FALSE; } @@ -68,7 +67,7 @@ static gboolean __bt_hid_check_for_callpath(const char *call_sender) s_list = s_list->next; } - ERR("Sender [%s] is not registered", call_sender); + INFO("Sender [%s] is not registered", call_sender); return FALSE; } @@ -80,21 +79,20 @@ bt_hid_agent_error_t _bt_hid_register_application(gboolean register_flag, if (sender == NULL) return BT_HID_AGENT_ERROR_INVALID_PARAM; - DBG(" Requesting [%s]", register_flag ? "Register" : "Unregister"); - DBG(" sender = %s", sender); - - if (register_flag) { - if (__bt_hid_check_for_callpath(sender)) + if (register_flag == TRUE) { + if (__bt_hid_check_for_callpath(sender) == TRUE) { + ERR("Already registered [sender:%s]", sender); return BT_HID_AGENT_ERROR_ALREADY_EXIST; + } - /* add call path to the senders list*/ - sender_name = g_strdup(sender); - app_list = g_slist_append(app_list, sender_name); + INFO("Registered [sender:%s]", sender); - return BT_HID_AGENT_ERROR_NONE; + /* add the call path to the sender list */ + sender_name = g_strdup(sender); + sender_list = g_slist_append(sender_list, sender_name); } else { /*remove the call from senders list */ - GSList *s_list = app_list; + GSList *s_list = sender_list; while (s_list != NULL) { sender_name = s_list->data; @@ -103,11 +101,13 @@ bt_hid_agent_error_t _bt_hid_register_application(gboolean register_flag, return BT_HID_AGENT_ERROR_NOT_AVAILABLE; if (g_strcmp0(sender_name, sender) == 0) { - app_list = g_slist_remove(app_list, sender_name); + sender_list = g_slist_remove(sender_list, sender_name); g_free(sender_name); - if (app_list == NULL && hid_state == BT_HID_STATE_CONNECTED) - __bt_hid_disconnect_profile(); + if (sender_list == NULL && hid_state == BT_HID_STATE_CONNECTED) + _bt_hid_disconnect_profile(); + + INFO("Unregistered [sender:%s]", sender); return BT_HID_AGENT_ERROR_NONE; } @@ -116,41 +116,9 @@ bt_hid_agent_error_t _bt_hid_register_application(gboolean register_flag, return BT_HID_AGENT_ERROR_NOT_AVAILABLE; } -} - -#else -bt_hid_agent_error_t _bt_hid_register_application(gboolean register_flag, - const char *sender_name) -{ - if (sender_name == NULL) - return BT_HID_AGENT_ERROR_INVALID_PARAM; - - if (register_flag == TRUE) { - if (sender != NULL) { - ERR("Already registered [sender:%s]", sender_name); - return BT_HID_AGENT_ERROR_ALREADY_EXIST; - } - - /* set the call path to the sender */ - sender = g_strdup(sender_name); - INFO("Registered [sender:%s]", sender_name); - } else { - if (sender == NULL) - return BT_HID_AGENT_ERROR_NOT_AVAILABLE; - if (strcasecmp(sender, sender_name) != 0) - return BT_HID_AGENT_ERROR_NOT_AVAILABLE; - - /* unset the call path to the sender */ - g_free(sender); - sender = NULL; - if (hid_state == BT_HID_STATE_CONNECTED) - __bt_hid_disconnect_profile(); - INFO("Unregistered [sender:%s]", sender_name); - } return BT_HID_AGENT_ERROR_NONE; } -#endif void _bt_hid_set_profile_state(bt_hid_state_t new_state) { @@ -163,6 +131,8 @@ void _bt_hid_set_profile_state(bt_hid_state_t new_state) case BT_HID_STATE_DISCONNECTED: break; case BT_HID_STATE_CONNECTED: + if (sender_list == NULL) + _bt_hid_disconnect_profile(); break; case BT_HID_STATE_CONNECTING: case BT_HID_STATE_DISCONNECTING: @@ -175,3 +145,8 @@ bt_hid_state_t _bt_hid_get_profile_state(void) { return hid_state; } + +const GSList* _bt_hid_get_sender_list(void) +{ + return sender_list; +} diff --git a/hid-agent/bluetooth-hid-manager.h b/hid-agent/bluetooth-hid-manager.h new file mode 100644 index 0000000..9f76b5d --- /dev/null +++ b/hid-agent/bluetooth-hid-manager.h @@ -0,0 +1,28 @@ +/* + * Bluetooth-hid-agent + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __DEF_BT_HID_MANAGER_H_ +#define __DEF_BT_HID_MANAGER_H_ + +void _bt_hid_set_profile_state(bt_hid_state_t new_state); +bt_hid_agent_error_t _bt_hid_register_application(gboolean register_flag, + const char *sender_name); +const GSList* _bt_hid_get_sender_list(void); + +#endif /* __DEF_BT_HID_MANAGER_H_ */ -- 2.7.4