+ _bt_service_adapter_le_deinit();
+ }
+
+ _bt_obex_server_check_allocation(&value);
+
+ if (value == TRUE) {
+ /* Check if the obex server was terminated abnormally */
+ _bt_obex_server_check_termination(name);
+ }
+
+ _bt_rfcomm_server_check_existence(&value);
+
+ if (value == TRUE) {
+ /* The obex server was terminated abnormally */
+ _bt_rfcomm_server_check_termination(name);
+ }
+
+ /* Reset connection interval */
+ _bt_remove_all_le_conn_param_info(name);
+
+ /* Stop advertising started by terminated process */
+ _bt_stop_advertising_by_terminated_process(name);
+ /* Stop LE Scan */
+ _bt_stop_le_scan(name);
+
+ /* Stop the Proximity reporter service */
+ _bt_proximity_reporter_stop_by_terminated_process(name);
+
+ /* Stop the Transport Discovery service */
+ _bt_tds_stop_by_terminated_process(name);
+
+ g_free(name);
+ g_free(previous);
+ g_free(current);
+ } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
+ const char *path = object_path;
+
+ if (strncmp(path, BT_MEDIA_OBJECT_PATH,
+ strlen(BT_MEDIA_OBJECT_PATH)) == 0)
+ return;
+
+ _bt_handle_property_changed_event(parameters, object_path);
+ } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
+ _bt_handle_adapter_event(parameters, signal_name);
+ } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
+ _bt_handle_input_event(parameters, object_path);
+ } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
+ _bt_handle_network_server_event(parameters, signal_name);
+ } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
+ _bt_handle_headset_event(parameters, object_path);
+ } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
+ _bt_handle_sink_event(parameters, object_path);
+ } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
+ _bt_handle_agent_event(parameters, signal_name);
+ } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
+ _bt_handle_device_event(parameters, signal_name, object_path);
+ } else if (g_strcmp0(interface_name, BT_TDS_PROVIDER_INTERFACE) == 0) {
+ _bt_handle_tds_provider_event(parameters, signal_name, object_path);
+ } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
+ _bt_handle_gatt_event(parameters, signal_name, object_path);
+ }
+
+ return;
+}
+
+static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
+{
+
+ if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
+ char *interface_name = NULL;
+
+ g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
+ retv_if(interface_name == NULL, FALSE);
+
+ if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
+ BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static void __bt_obexd_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ const char *member = signal_name;
+ char *obj_path = NULL;
+ ret_if(member == NULL);
+
+ if (strcasecmp(member, "InterfacesAdded") == 0) {
+ if (__bt_get_object_path(parameters, &obj_path)) {
+ BT_ERR("Fail to get the path");
+ return;
+ }
+ BT_INFO("object_path = [%s]", obj_path);
+
+ /*Handle OPP_SERVER_CONNECTED_EVENT here */
+ /* TODO: MAP? see above */
+ if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
+ strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
+ g_free(obj_path);
+ return;
+ }
+
+ if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
+ BT_DBG("Obex_Server_Session_Transfer connected");
+ _bt_obex_transfer_connected(obj_path);
+ }
+ g_free(obj_path);
+ } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
+ /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
+ /* TODO: MAP? see above */
+ if (__bt_get_object_path(parameters, &obj_path)) {
+ BT_ERR("Fail to get the path");
+ return;
+ }
+ BT_INFO("object_path = [%s]", obj_path);
+
+ if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
+ strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
+ BT_DBG("Call PBAP Disconnected");
+ _bt_obex_pbap_client_disconnect(obj_path);
+ }
+
+ if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
+ strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
+ g_free(obj_path);
+ return;
+ }
+
+ if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
+ BT_DBG("Obex_Server_Session_Transfer disconnected %s",
+ obj_path);
+
+ _bt_obex_transfer_disconnected(obj_path);
+ }
+ g_free(obj_path);
+ } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
+ const char *path = object_path;
+
+ if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
+ strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
+ strncmp(path, BT_SESSION_BASEPATH_CLIENT,
+ strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
+ BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
+ return;
+ }
+
+ _bt_handle_property_changed_event(parameters, path);
+ }
+ BT_DBG("-");
+ return;
+}
+
+static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
+{
+ BT_DBG("+");
+
+ if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
+ char *interface_name = NULL;
+
+ g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
+
+ retv_if(interface_name == NULL, FALSE);
+
+ if (strcasecmp(interface_name,
+ BT_OBEX_TRANSFER_INTERFACE) == 0) {
+ BT_DBG("-");
+ return TRUE;
+ }
+ }
+
+ BT_DBG("-");
+
+ return FALSE;
+}
+
+static void __bt_opc_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ const char *member = signal_name;
+ char *obj_path = NULL;
+ if (strcasecmp(member, "InterfacesAdded") == 0) {
+ BT_DBG("InterfacesAdded");
+ } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
+
+ if (__bt_get_object_path(parameters, &obj_path)) {
+ BT_ERR("Fail to get the path");
+ return;
+ }
+
+ BT_DBG("object_path = %s", obj_path);
+
+ if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
+ strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
+ || strstr(obj_path, "transfer") == NULL) {
+ g_free(obj_path);
+ return;
+ } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
+ strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
+ BT_DBG("Going to call opc disconnected");
+ _bt_opc_disconnected(obj_path);
+ }
+
+ _bt_sending_files();
+ g_free(obj_path);
+ } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
+ char *path = (char *)object_path;
+ BT_INFO("object_path %s", path);
+ if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
+ strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
+ BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
+ return;
+ }
+
+ _bt_opc_property_changed_event(parameters, path);
+ }
+
+ return;
+}
+
+int _bt_opp_client_event_init(void)
+{
+ GError *error = NULL;
+
+ if (opc_obexd_conn == NULL) {
+ opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+
+ if (!opc_obexd_conn) {
+ if (error) {
+ BT_ERR("Unable to connect to dbus: %s", error->message);
+ g_clear_error(&error);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ }
+
+ if (_bt_register_service_event(opc_obexd_conn,
+ BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
+ g_object_unref(opc_obexd_conn);
+ opc_obexd_conn = NULL;
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+void _bt_opp_client_event_deinit(void)
+{
+ if (opc_obexd_conn) {
+ _bt_unregister_service_event(opc_obexd_conn,
+ BT_OPP_CLIENT_EVENT);
+ g_object_unref(opc_obexd_conn);
+ opc_obexd_conn = NULL;
+ }
+}
+
+static void __bt_map_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ BT_DBG("Entered __bt_map_event_filter");
+ const char *member = signal_name;
+
+ if (strcasecmp(member, "InterfacesAdded") == 0) {
+ BT_DBG("------------------------------------ADDED------------------------------------");
+ // currently doing nothing
+ } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
+ BT_DBG("------------------------------------REMOVED------------------------------------");
+ // TODO check if something should be called here?
+ //_bt_map_on_transfer_finished(object_path, error);
+ } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
+ BT_DBG("------------------------------------CLIENT EVENT------------------------------------");
+ _bt_map_property_changed_event(parameters, object_path);
+ }
+
+ return;
+}
+
+int _bt_map_client_event_init(void)
+{
+ GError *error = NULL;
+
+ if (map_obexd_conn == NULL) {
+ map_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+
+ if (!map_obexd_conn) {
+ if (error) {
+ BT_ERR("Unable to connect to dbus: %s", error->message);
+ g_clear_error(&error);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ }
+
+ if (_bt_register_service_event(map_obexd_conn,
+ BT_MAP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
+ g_object_unref(map_obexd_conn);
+ map_obexd_conn = NULL;
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+void _bt_map_client_event_deinit(void)
+{
+ if (map_obexd_conn) {
+ _bt_unregister_service_event(map_obexd_conn,
+ BT_MAP_CLIENT_EVENT);
+ g_object_unref(map_obexd_conn);
+ map_obexd_conn = NULL;
+ }
+}
+
+int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
+{
+ if (conn == NULL)
+ return -1;
+
+ static guint subs_interface_added_id;
+ static guint subs_interface_removed_id;
+ static guint subs_name_owner_id;
+ static guint subs_property_id;
+ static guint subs_adapter_id;
+ static guint subs_gatt_id;
+
+ if (subscribe) {
+ if (subs_interface_added_id == 0) {
+ subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_MANAGER_INTERFACE,
+ BT_INTERFACES_ADDED, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_interface_removed_id == 0) {
+ subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_MANAGER_INTERFACE,
+ BT_INTERFACES_REMOVED, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_name_owner_id == 0) {
+ subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_FREEDESKTOP_INTERFACE,
+ BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_property_id == 0) {
+ subs_property_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_PROPERTIES_INTERFACE,
+ BT_PROPERTIES_CHANGED, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_adapter_id == 0) {
+ subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_ADAPTER_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_gatt_id == 0) {
+ subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_GATT_CHAR_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ } else {
+ if (subs_interface_added_id > 0) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_interface_added_id);
+ subs_interface_added_id = 0;
+ }
+ if (subs_interface_removed_id > 0) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_interface_removed_id);
+ subs_interface_removed_id = 0;
+ }
+ if (subs_name_owner_id > 0) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_name_owner_id);
+ subs_name_owner_id = 0;
+ }
+ if (subs_property_id > 0) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_property_id);
+ subs_property_id = 0;
+ }
+ if (subs_adapter_id > 0) {
+ g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
+ subs_adapter_id = 0;
+ }
+ if (subs_gatt_id > 0) {
+ g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
+ subs_gatt_id = 0;
+ }
+ }
+ return 0;
+}
+
+int _bt_register_device_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
+{
+ if (conn == NULL)
+ return -1;
+
+ static guint subs_device_id = 0;
+
+ if (subscribe) {
+ if (subs_device_id == 0) {
+ subs_device_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_DEVICE_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ } else {
+ if (subs_device_id > 0) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_device_id);
+ subs_device_id = 0;