#include <aul.h>
#include "bluetooth-hid-agent.h"
+#include "bluetooth-hid-manager.h"
static GMainLoop *gmain_loop;
static char *g_obj_path;
static GDBusConnection *gdbus_conn;
static GDBusProxy *profile_gproxy;
-static guint owner_sig_id;
+static guint interface_added_sig_id;
+static guint interface_removed_sig_id;
static guint bluez_device_sig_id;
static guint name_owner_sig_id;
static void __bt_hid_agent_sigterm_handler(int signo);
static GError *__bt_hid_agent_set_error(bt_hid_agent_error_t error);
+/* LCOV_EXCL_START */
static void __on_log_glib(const gchar *log_domain, GLogLevelFlags log_level,
const gchar *msg, gpointer user_data)
{
GVariant *parameters,
gpointer user_data)
{
- char *name_owner = NULL;
- char *old_owner = NULL;
- char *new_owner = NULL;
+ const char *name_owner = NULL;
+ const char *old_owner = NULL;
+ const char *new_owner = NULL;
int ret = 0;
if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
- g_variant_get(parameters, "(sss)", &name_owner, &old_owner, &new_owner);
+ g_variant_get(parameters, "(&s&s&s)", &name_owner, &old_owner, &new_owner);
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;
+ }
}
}
}
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;
FN_END;
}
-void _bt_convert_device_path_to_address(const char *device_path,
- char *device_address)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char *dev_addr;
-
- ret_if(device_path == NULL);
- ret_if(device_address == NULL);
-
- dev_addr = strstr(device_path, "dev_");
- if (dev_addr != NULL) {
- char *pos = NULL;
- dev_addr += 4;
- g_strlcpy(address, dev_addr, sizeof(address));
-
- while ((pos = strchr(address, '_')) != NULL) {
- *pos = ':';
- }
-
- g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
- }
-}
-
static void __bt_hid_device_filter_cb(GDBusConnection *connection,
const gchar *sender_name,
const gchar *object_path,
return;
}
- if (!__bt_hid_agent_get_adapter_path(conn, NULL)) {
+ if (!__bt_hid_agent_get_adapter_path(conn, NULL))
__bt_hid_agent_register();
- }
- owner_sig_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_MANAGER_INTERFACE, NULL, NULL, NULL, 0,
+ interface_added_sig_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_ADDED, NULL, NULL, 0,
+ __bt_hid_agent_filter_cb, NULL, NULL);
+
+ interface_removed_sig_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_REMOVED, NULL, NULL, 0,
__bt_hid_agent_filter_cb, NULL, NULL);
bluez_device_sig_id = g_dbus_connection_signal_subscribe(conn,
}
if (gdbus_conn) {
- if (owner_sig_id > 0)
+ if (interface_added_sig_id > 0)
g_dbus_connection_signal_unsubscribe(gdbus_conn,
- owner_sig_id);
+ interface_added_sig_id);
+
+ if (interface_removed_sig_id > 0)
+ g_dbus_connection_signal_unsubscribe(gdbus_conn,
+ interface_removed_sig_id);
if (bluez_device_sig_id > 0)
g_dbus_connection_signal_unsubscribe(gdbus_conn,
g_dbus_connection_signal_unsubscribe(gdbus_conn,
name_owner_sig_id);
- owner_sig_id = 0;
+ interface_added_sig_id = 0;
+ interface_removed_sig_id = 0;
bluez_device_sig_id = 0;
name_owner_sig_id = 0;
gdbus_conn = NULL;
}
}
+/* LCOV_EXCL_STOP */
-
-
-
-bt_hid_agent_error_t __bt_hid_disconnect_profile(void)
+bt_hid_agent_error_t _bt_hid_disconnect_profile(void)
{
FN_START;
- GDBusProxy *proxy;
+ GDBusProxy *proxy = NULL;
- proxy = __bt_hid_gdbus_get_device_proxy(bt_hid_info.object_path);
+ if (bt_hid_info.object_path)
+ proxy = __bt_hid_gdbus_get_device_proxy(bt_hid_info.object_path);
if (proxy == NULL) {
ERR("Error while getting proxy");
return BT_HID_AGENT_ERROR_INTERNAL;
}
+ /* LCOV_EXCL_START */
g_dbus_proxy_call(proxy, "DisconnectProfile",
g_variant_new("(s)", HID_DEVICE_UUID),
G_DBUS_CALL_FLAGS_NONE, 2000,
FN_END;
return BT_HID_AGENT_ERROR_NONE;
+ /* LCOV_EXCL_STOP */
}
+/* LCOV_EXCL_START */
int main(void)
{
int i;
INFO_C("### Terminating Bluetooth HID agent");
return 0;
}
-
+/* LCOV_EXCL_STOP */