Add bt-driver-insmod.service trigger logic
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-common.c
index af738d5..40f7fd1 100644 (file)
 #include "bt-internal-types.h"
 #include "bluetooth-ipsp-api.h"
 
+#ifndef GATT_DIRECT
+#include "bluetooth-gatt-server-api.h"
+#endif
+
 #include "bt-common.h"
 #include "bt-request-sender.h"
 #include "bt-event-handler.h"
@@ -201,6 +205,25 @@ void _bt_avrcp_event_cb(int event, int result, void *param,
                                        user_data);
 }
 
+#ifndef GATT_DIRECT
+void _bt_gatt_server_event_cb(int event, int result, void *param,
+               void *callback, void *user_data)
+{
+       BT_INFO("__bt_gatt_server_event_cb");
+       gatt_server_event_param_t bt_event = { 0, 0, NULL, NULL };
+       bt_event.event = event;
+       bt_event.result = result;
+       bt_event.param_data = param;
+       if (callback) {
+               BT_INFO("GATT Server event callback is registered");
+               ((gatt_server_cb_func_ptr)callback)(bt_event.event, &bt_event,
+                       user_data);
+       } else {
+               BT_ERR("GATT Server event callback is not registered!!!");
+       }
+}
+#endif
+
 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
                                unsigned int cod)
 {
@@ -692,13 +715,13 @@ static const gchar rfcomm_agent_xml[] =
 "</node>";
 
 static void __new_connection_method(GDBusConnection *connection,
-                                           const gchar *sender,
-                                           const gchar *object_path,
-                                           const gchar *interface_name,
-                                           const gchar *method_name,
-                                           GVariant *parameters,
-                                           GDBusMethodInvocation *invocation,
-                                           gpointer user_data)
+               const gchar *sender,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *method_name,
+               GVariant *parameters,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data)
 {
        BT_DBG("method %s", method_name);
        if (g_strcmp0(method_name, "NewConnection") == 0) {
@@ -1478,8 +1501,6 @@ int _bt_discover_service_uuids(char *address, char *remote_uuid)
                g_variant_get(ret, "(v)", &value);
                uuid_value = (char **)g_variant_get_strv(value, &size);
                BT_DBG("Size items %d", size);
-               g_variant_unref(value);
-               g_variant_unref(ret);
        }
 
        if (uuid_value) {
@@ -1489,8 +1510,8 @@ int _bt_discover_service_uuids(char *address, char *remote_uuid)
                                BT_ERR("_bt_discover_service_uuids Error Parameter are NULL..\n");
                                continue;
                        } else if (g_ascii_strcasecmp(uuid_value[i], remote_uuid) == 0) {
-                                       result = BLUETOOTH_ERROR_NONE;
-                                       goto done;
+                               result = BLUETOOTH_ERROR_NONE;
+                               goto done;
                        }
                }
        }
@@ -1501,6 +1522,12 @@ done:
        if (uuid_value)
                g_free(uuid_value);
 
+       if (value)
+               g_variant_unref(value);
+
+       if (ret)
+               g_variant_unref(ret);
+
        BT_DBG("-");
        return result;
 }
@@ -1913,12 +1940,17 @@ GVariant *_bt_get_managed_objects(void)
                        BT_MANAGER_INTERFACE,
                        NULL, &error);
 
-       if (manager_proxy == NULL && error) {
+       if (error) {
                BT_ERR("Unable to create proxy: %s", error->message);
                g_clear_error(&error);
+               if (manager_proxy)
+                       g_object_unref(manager_proxy);
                return NULL;
        }
 
+       if (!manager_proxy)
+               return NULL;
+
        result = g_dbus_proxy_call_sync(manager_proxy,
                        "GetManagedObjects", NULL,
                        G_DBUS_CALL_FLAGS_NONE, -1,
@@ -2270,15 +2302,21 @@ BT_EXPORT_API int bluetooth_register_callback(bluetooth_cb_func_ptr callback_ptr
                ret = _bt_register_event(BT_RFCOMM_SERVER_EVENT, (void *)callback_ptr, user_data);
                if (ret != BLUETOOTH_ERROR_NONE)
                        goto fail;
+
+#ifdef GATT_NO_RELAY
                ret = _bt_register_event(BT_GATT_BLUEZ_EVENT, (void *)callback_ptr, user_data);
                if (ret != BLUETOOTH_ERROR_NONE)
                        goto fail;
+#endif
                ret = _bt_register_event(BT_TDS_EVENT, (void *)callback_ptr, user_data);
                if (ret != BLUETOOTH_ERROR_NONE)
                        goto fail;
                ret = _bt_register_event(BT_OTP_EVENT, (void *)callback_ptr, user_data);
                if (ret != BLUETOOTH_ERROR_NONE)
                        goto fail;
+               ret = _bt_register_event(BT_HDP_EVENT, (void *)callback_ptr, user_data);
+               if (ret != BLUETOOTH_ERROR_NONE)
+                       goto fail;
        }
 
        _bt_register_name_owner_changed();