resolved the code rule warnings
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-gatt-server.c
index aeb6209..89dca76 100644 (file)
 
 #define NUMBER_OF_FLAGS 10
 
-#define GATT_SERV_INTERFACE             "org.bluez.GattService1"
-#define GATT_CHAR_INTERFACE             "org.bluez.GattCharacteristic1"
-#define GATT_DESC_INTERFACE             "org.bluez.GattDescriptor1"
+#define GATT_SERV_INTERFACE            "org.bluez.GattService1"
+#define GATT_CHAR_INTERFACE            "org.bluez.GattCharacteristic1"
+#define GATT_DESC_INTERFACE            "org.bluez.GattDescriptor1"
 
-#define BT_GATT_SERVICE_NAME    "org.frwk.gatt_service"
-#define GATT_SERV_OBJECT_PATH   "/service"
+#define BT_GATT_SERVICE_NAME   "org.frwk.gatt_service"
+#define GATT_SERV_OBJECT_PATH  "/service"
 
 static GDBusProxy *manager_gproxy = NULL;
 
@@ -70,37 +70,37 @@ static int gatt_char_handle = 20;
 static int gatt_desc_handle = 30;
 
 struct gatt_service_info {
-        gchar *serv_path;
-        guint serv_id;
-        gchar *service_uuid;
-        guint manager_id;
-        guint prop_id;
-        GSList *char_data;
-        gboolean is_svc_registered;
-        gboolean is_svc_primary;
+       gchar *serv_path;
+       guint serv_id;
+       gchar *service_uuid;
+       guint manager_id;
+       guint prop_id;
+       GSList *char_data;
+       gboolean is_svc_registered;
+       gboolean is_svc_primary;
        int service_handle;
 };
 
 struct gatt_char_info {
-        gchar *char_path;
-        guint char_id;
-        gchar *char_uuid;
-        gchar *char_value;
-        gchar *char_flags[NUMBER_OF_FLAGS];
-        int value_length;
-        int flags_length;
+       gchar *char_path;
+       guint char_id;
+       gchar *char_uuid;
+       gchar *char_value;
+       gchar *char_flags[NUMBER_OF_FLAGS];
+       int value_length;
+       int flags_length;
        int char_handle;
-        GSList *desc_data;
+       GSList *desc_data;
 };
 
 struct gatt_desc_info {
-        gchar *desc_path;
-        guint desc_id;
-        gchar *desc_uuid;
-        gchar *desc_value;
-        gchar *desc_flags[NUMBER_OF_FLAGS];
-        int value_length;
-        int flags_length;
+       gchar *desc_path;
+       guint desc_id;
+       gchar *desc_uuid;
+       gchar *desc_value;
+       gchar *desc_flags[NUMBER_OF_FLAGS];
+       int value_length;
+       int flags_length;
        int desc_handle;
 };
 
@@ -108,18 +108,18 @@ struct gatt_desc_info {
  * GATT Server Request type
  */
 typedef enum {
-        BT_HAL_GATT_REQUEST_TYPE_READ = 0x00,       /* Read Requested */
-        BT_HAL_GATT_REQUEST_TYPE_WRITE = 0x01,      /* Write Requested */
-        BT_HAL_GATT_REQUEST_TYPE_EXEC_WRITE = 0x02, /* Exec Write Requested */
+       BT_HAL_GATT_REQUEST_TYPE_READ = 0x00,       /* Read Requested */
+       BT_HAL_GATT_REQUEST_TYPE_WRITE = 0x01,      /* Write Requested */
+       BT_HAL_GATT_REQUEST_TYPE_EXEC_WRITE = 0x02, /* Exec Write Requested */
 } bt_gatt_request_type_e;
 
 struct gatt_req_info {
-        gchar *attr_path;
-        gchar *svc_path;
-        guint  request_id;
-        guint  offset;
-        bt_gatt_request_type_e request_type;  /* Read or Write request */
-        GDBusMethodInvocation *context;
+       gchar *attr_path;
+       gchar *svc_path;
+       guint  request_id;
+       guint  offset;
+       bt_gatt_request_type_e request_type;  /* Read or Write request */
+       GDBusMethodInvocation *context;
 };
 
 struct gatt_server_app {
@@ -140,9 +140,9 @@ static GSList *gatt_client_info_list = NULL;
 
 /* GATT Client Info List Structure */
 struct gatt_client_info_t {
-        int connection_id;                               /* This value will uniquely identify a GATT client-server connection */
-        int instance_id;                                 /* This value unique identifies a GATT server instance */
-        char *addr;                                      /* Remote GATT client address */
+       int connection_id;                               /* This value will uniquely identify a GATT client-server connection */
+       int instance_id;                                 /* This value unique identifies a GATT server instance */
+       char *addr;                                      /* Remote GATT client address */
        GSList *gatt_req_info_list;                              /* List of transactions per Connection*/
 };
 
@@ -200,10 +200,10 @@ static void __bt_hal_register_application_cb(GObject *object,
                                GAsyncResult *res, gpointer user_data);
 
 static void __bt_hal_unregister_application_cb(GObject *object, GAsyncResult *res,
-                gpointer user_data);
+               gpointer user_data);
 
 static GDBusProxy *__bt_gatt_gdbus_get_gatt_manager_proxy(const gchar *service,
-                                const gchar *path, const gchar *interface);
+               const gchar *path, const gchar *interface);
 
 /* Introspection data for the service we are exporting */
 static const gchar service_introspection_xml[] =
@@ -528,9 +528,8 @@ char *__bt_gatt_find_char_path_from_handle(int char_hdl)
                for (l2 = serv_info->char_data; l2 != NULL; l2 = l2->next) {
                        struct gatt_char_info *char_info = l2->data;
 
-                       if (char_info->char_handle == char_hdl) {
+                       if (char_info->char_handle == char_hdl)
                                return char_info->char_path;
-                       }
                }
        }
        ERR("Not found");
@@ -547,9 +546,8 @@ struct gatt_char_info *__bt_gatt_find_char_info_from_handle(int char_hdl)
                for (l2 = serv_info->char_data; l2 != NULL; l2 = l2->next) {
                        struct gatt_char_info *char_info = l2->data;
 
-                       if (char_info->char_handle == char_hdl) {
+                       if (char_info->char_handle == char_hdl)
                                return char_info;
-                       }
                }
        }
        ERR("Not found");
@@ -582,13 +580,13 @@ static struct gatt_service_info *__bt_gatt_find_gatt_service_from_desc(const cha
 }
 
 static void __bt_gatt_manager_method_call(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)
 {
        GSList *l = NULL;
 
@@ -619,7 +617,7 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
 
                for (l = gatt_services; l != NULL; l = l->next) {
                        GVariantBuilder *svc_builder = NULL;
-                        GVariantBuilder *inner_builder = NULL;
+                       GVariantBuilder *inner_builder = NULL;
                        struct gatt_service_info *serv_info = l->data;
                        INFO("GATT Service fetched handle [%d]", serv_info->service_handle);
 
@@ -866,13 +864,13 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
 }
 
 static void __bt_gatt_desc_method_call(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)
 {
 
        if (g_strcmp0(method_name, "ReadValue") == 0) {
@@ -977,8 +975,8 @@ static void __bt_gatt_desc_method_call(GDBusConnection *connection,
                }
 
                len = g_variant_get_size(var);
-                if (len > 0) {
-                        char *data;
+               if (len > 0) {
+                       char *data;
                        data = (char *)g_variant_get_data(var);
                        memcpy(ev.value, data, len);
                        ev.length = len;
@@ -1018,13 +1016,13 @@ static void __bt_gatt_desc_method_call(GDBusConnection *connection,
 }
 
 static void __bt_gatt_char_method_call(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)
 {
        if (g_strcmp0(method_name, "ReadValue") == 0) {
                gchar *addr = NULL;
@@ -1051,10 +1049,10 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                }
 
                if (!event_cb) {
-                        ERR("GATT callback NOT registered");
-                        g_dbus_method_invocation_return_value(invocation, NULL);
-                        return;
-                }
+                       ERR("GATT callback NOT registered");
+                       g_dbus_method_invocation_return_value(invocation, NULL);
+                       return;
+               }
 
                g_variant_get(parameters, "(&suq)", &addr, &req_id, &offset);
                DBG("Request id = %u, Offset = %u", req_id, offset);
@@ -1159,21 +1157,20 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                int char_hdl = -1;
 
                svc_info = __bt_gatt_find_gatt_service_from_char(object_path, &char_hdl);
-               if (svc_info == NULL || event_cb == NULL) {
+               if (svc_info == NULL || event_cb == NULL)
                        return;
-               }
 
                /* Send HAL event */
-                memset(&ev, 0, sizeof(ev));
-                ev.conn_id = -1;  /*TODO Bluez does not provide remote GATT client address, so no conn_id */
-                ev.trans_id = -1; /*TODO Bluez does not provide request id or transacion ID */
-                ev.att_handle = char_hdl;
+               memset(&ev, 0, sizeof(ev));
+               ev.conn_id = -1;  /*TODO Bluez does not provide remote GATT client address, so no conn_id */
+               ev.trans_id = -1; /*TODO Bluez does not provide request id or transacion ID */
+               ev.att_handle = char_hdl;
                ev.notify = true;
 
-                /* Convert address to hex */
-                _bt_hal_convert_addr_string_to_type(ev.bdaddr, "00:00:00:00:00"); /* TODO Bluez Does not provide address of GATT client */
+               /* Convert address to hex */
+               _bt_hal_convert_addr_string_to_type(ev.bdaddr, "00:00:00:00:00"); /* TODO Bluez Does not provide address of GATT client */
 
-                event_cb(HAL_EV_GATT_NOTIFICATION_CHANGE, (void *)&ev, sizeof(ev));
+               event_cb(HAL_EV_GATT_NOTIFICATION_CHANGE, (void *)&ev, sizeof(ev));
 #endif
 
        } else if (g_strcmp0(method_name, "StopNotify") == 0) {
@@ -1184,21 +1181,20 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                int char_hdl = -1;
 
                svc_info = __bt_gatt_find_gatt_service_from_char(object_path, &char_hdl);
-               if (svc_info == NULL || event_cb == NULL) {
+               if (svc_info == NULL || event_cb == NULL)
                        return;
-               }
 
                /* Send HAL event */
-                memset(&ev, 0, sizeof(ev));
-                ev.conn_id = -1;  /*TODO Bluez does not provide remote GATT client address, so no conn_id */
-                ev.trans_id = -1; /*TODO Bluez does not provide request id or transacion ID */
-                ev.att_handle = char_hdl;
+               memset(&ev, 0, sizeof(ev));
+               ev.conn_id = -1;  /*TODO Bluez does not provide remote GATT client address, so no conn_id */
+               ev.trans_id = -1; /*TODO Bluez does not provide request id or transacion ID */
+               ev.att_handle = char_hdl;
                ev.notify = false;
 
-                /* Convert address to hex */
-                _bt_hal_convert_addr_string_to_type(ev.bdaddr, "00:00:00:00:00"); /* TODO Bluez DOes not provide address of GATT client */
+               /* Convert address to hex */
+               _bt_hal_convert_addr_string_to_type(ev.bdaddr, "00:00:00:00:00"); /* TODO Bluez DOes not provide address of GATT client */
 
-                event_cb(HAL_EV_GATT_NOTIFICATION_CHANGE, (void *)&ev, sizeof(ev));
+               event_cb(HAL_EV_GATT_NOTIFICATION_CHANGE, (void *)&ev, sizeof(ev));
 #endif
 
        } else if (g_strcmp0(method_name, "IndicateConfirm") == 0) {
@@ -1230,15 +1226,15 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                }
 
                /* Send HAL event */
-                memset(&ev, 0, sizeof(ev));
-                ev.conn_id = conn_info->connection_id;
-                ev.trans_id = -1; /*TODO Bluez does not provide Transaction ID or request ID */
-                ev.att_handle = char_hdl;
+               memset(&ev, 0, sizeof(ev));
+               ev.conn_id = conn_info->connection_id;
+               ev.trans_id = -1; /*TODO Bluez does not provide Transaction ID or request ID */
+               ev.att_handle = char_hdl;
 
-                /* Convert address to hex */
-                _bt_hal_convert_addr_string_to_type(ev.bdaddr, addr);
+               /* Convert address to hex */
+               _bt_hal_convert_addr_string_to_type(ev.bdaddr, addr);
 
-                event_cb(HAL_EV_GATT_INDICATE_CFM, (void *)&ev, sizeof(ev));
+               event_cb(HAL_EV_GATT_INDICATE_CFM, (void *)&ev, sizeof(ev));
        }
 
        g_dbus_method_invocation_return_value(invocation, NULL);
@@ -1320,32 +1316,32 @@ static void __bt_hal_gatt_free_service_info(struct gatt_service_info *svc_info)
 }
 
 static const GDBusInterfaceVTable desc_interface_vtable = {
-        __bt_gatt_desc_method_call,
-        NULL,
-        NULL,
+       __bt_gatt_desc_method_call,
+       NULL,
+       NULL,
 };
 
 static const GDBusInterfaceVTable char_interface_vtable = {
-        __bt_gatt_char_method_call,
-        NULL,
-        NULL,
+       __bt_gatt_char_method_call,
+       NULL,
+       NULL,
 };
 
 static const GDBusInterfaceVTable serv_interface_vtable = {
-        NULL,
-        NULL,
-        NULL,
+       NULL,
+       NULL,
+       NULL,
 };
 
 static const GDBusInterfaceVTable manager_interface_vtable = {
-        __bt_gatt_manager_method_call,
-        NULL,
-        NULL
+       __bt_gatt_manager_method_call,
+       NULL,
+       NULL
 };
 
 
 static GDBusNodeInfo *__bt_gatt_create_method_node_info(
-                                const gchar *introspection_data)
+               const gchar *introspection_data)
 {
        GError *err = NULL;
        GDBusNodeInfo *node_info = NULL;
@@ -1568,9 +1564,9 @@ void _bt_hal_remove_gatt_server_from_list(int server_if)
                                info->app_path, info->slot);
 
                        /* Only if all services are deleted from the GATT Server, then only Unregister it.
-                          Reason: it is possible, GATT Server app oly wants to disable multi advertising
-                           In above case, only advertising block will be deallocated, Gatt Server will remain
-                           unaffected */
+                       Reason: it is possible, GATT Server app oly wants to disable multi advertising
+                       In above case, only advertising block will be deallocated, Gatt Server will remain
+                       unaffected */
                        if (info->services == NULL) {
                                gatt_server_apps = g_slist_remove(gatt_server_apps, (gpointer)info);
                                INFO("Total gatt server apps still existing after removing above is [%d]",
@@ -1617,28 +1613,28 @@ static bt_status_t gatt_server_close(int server_if, const bt_bdaddr_t *bd_addr,
 
 static void __bt_gatt_close_gdbus_connection(void)
 {
-        GError *err = NULL;
-        DBG("+");
+       GError *err = NULL;
+       DBG("+");
 
-        if (g_conn == NULL)
+       if (g_conn == NULL)
                return;
 
-        if (!g_dbus_connection_flush_sync(g_conn, NULL, &err)) {
-                ERR("Fail to flush the connection: %s", err->message);
-                g_error_free(err);
-                err = NULL;
-        }
+       if (!g_dbus_connection_flush_sync(g_conn, NULL, &err)) {
+               ERR("Fail to flush the connection: %s", err->message);
+               g_error_free(err);
+               err = NULL;
+       }
 
-        if (!g_dbus_connection_close_sync(g_conn, NULL, &err)) {
-                if (err) {
-                        ERR("Fail to close the dbus connection: %s", err->message);
-                        g_error_free(err);
-                }
-        }
+       if (!g_dbus_connection_close_sync(g_conn, NULL, &err)) {
+               if (err) {
+                       ERR("Fail to close the dbus connection: %s", err->message);
+                       g_error_free(err);
+               }
+       }
 
-        g_object_unref(g_conn);
-        g_conn = NULL;
-        DBG("-");
+       g_object_unref(g_conn);
+       g_conn = NULL;
+       DBG("-");
 }
 
 static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
@@ -1812,28 +1808,28 @@ int __bt_hal_add_service_to_dbus(char *app_path, int slot, btgatt_srvc_id_t *srv
 }
 
 static void __bt_hal_unregister_application_cb(GObject *object, GAsyncResult *res,
-                gpointer user_data)
+               gpointer user_data)
 {
        char *app_path = (char*)user_data;
-        INFO("UnregisterApplication is completed app [%s]", app_path);
-        GError *error = NULL;
-        GVariant *result;
-
-        result = g_dbus_proxy_call_finish(manager_gproxy, res, &error);
-
-        if (result == NULL) {
-                /* dBUS-RPC is failed */
-                ERR("Dbus-RPC is failed\n");
-
-                if (error != NULL) {
-                        /* dBUS gives error cause */
-                        ERR("D-Bus API failure: errCode[%x], message[%s]\n",
-                                        error->code, error->message);
-                        g_clear_error(&error);
-                }
-        } else {
-                g_variant_unref(result);
-        }
+       INFO("UnregisterApplication is completed app [%s]", app_path);
+       GError *error = NULL;
+       GVariant *result;
+
+       result = g_dbus_proxy_call_finish(manager_gproxy, res, &error);
+
+       if (result == NULL) {
+               /* dBUS-RPC is failed */
+               ERR("Dbus-RPC is failed\n");
+
+               if (error != NULL) {
+                       /* dBUS gives error cause */
+                       ERR("D-Bus API failure: errCode[%x], message[%s]\n",
+                                       error->code, error->message);
+                       g_clear_error(&error);
+               }
+       } else {
+               g_variant_unref(result);
+       }
        g_free(app_path);
 }
 
@@ -2045,7 +2041,7 @@ static gboolean __bt_is_service_last_in_server_list(int instance, int service_ha
 }
 
 static struct gatt_service_info *__bt_gatt_find_gatt_service_info(int instance,
-                        int service_handle)
+               int service_handle)
 {
        GSList *l;
        GSList *gatt_services = NULL;
@@ -2056,9 +2052,8 @@ static struct gatt_service_info *__bt_gatt_find_gatt_service_info(int instance,
        for (l = gatt_services; l != NULL; l = g_slist_next(l)) {
                struct gatt_service_info *info = l->data;
                INFO("Got one service with handle [%d]", info->service_handle);
-               if (info->service_handle == service_handle) {
+               if (info->service_handle == service_handle)
                        return info;
-               }
        }
        ERR("Gatt service with handle [%d] not found", service_handle);
        return NULL;
@@ -2068,20 +2063,20 @@ static bt_status_t gatt_server_add_characteristic(int slot, int service_handle,
                bt_uuid_t *uuid, int properties,
                int permissions)
 {
-        GError *error = NULL;
-        guint object_id;
-        GDBusNodeInfo *node_info;
-        gchar *path = NULL;
-        GVariantBuilder *builder = NULL;
-        GVariantBuilder *inner_builder = NULL;
-        struct gatt_service_info *serv_info = NULL;
-        struct gatt_char_info *char_info = NULL;
-        GVariantBuilder *builder2 = NULL;
-        GVariantBuilder *builder3 = NULL;
-        GVariant *flags_val = NULL;
-        int i = 0;
-        char *char_flags[NUMBER_OF_FLAGS];
-        int flag_count = 0;
+       GError *error = NULL;
+       guint object_id;
+       GDBusNodeInfo *node_info;
+       gchar *path = NULL;
+       GVariantBuilder *builder = NULL;
+       GVariantBuilder *inner_builder = NULL;
+       struct gatt_service_info *serv_info = NULL;
+       struct gatt_char_info *char_info = NULL;
+       GVariantBuilder *builder2 = NULL;
+       GVariantBuilder *builder3 = NULL;
+       GVariant *flags_val = NULL;
+       int i = 0;
+       char *char_flags[NUMBER_OF_FLAGS];
+       int flag_count = 0;
        hal_gatt_char_added *user_data = NULL;
        int *app_id;
 
@@ -2241,17 +2236,16 @@ static bt_status_t gatt_server_add_descriptor(int slot, int service_handle, bt_u
 #endif
        /* Fetch service data for the GATT server */
        serv_info = __bt_gatt_find_gatt_service_info(slot, service_handle);
-        if (serv_info == NULL)
-                return BT_STATUS_FAIL;
+       if (serv_info == NULL)
+               return BT_STATUS_FAIL;
 
        /* Fetch list of characteristics from the service info */
        l = serv_info->char_data;
 
        /* Fetch last char info from the characteristic list */
        char_info = g_slist_last(l)->data;
-       if (char_info == NULL) {
+       if (char_info == NULL)
                return BT_STATUS_FAIL;
-       }
 
        /* Fetch characteristic path from char info */
        char_path = char_info->char_path;
@@ -2275,7 +2269,7 @@ static bt_status_t gatt_server_add_descriptor(int slot, int service_handle, bt_u
        DBG("gatt descriptor path is [%s]", path);
 
        app_id = g_malloc0(sizeof(int));
-        *app_id = slot;
+       *app_id = slot;
 
        object_id = g_dbus_connection_register_object(g_conn, path,
                        node_info->interfaces[0],
@@ -2383,7 +2377,7 @@ static void __bt_hal_register_application_cb(GObject *object, GAsyncResult *res,
 }
 
 static GDBusProxy *__bt_hal_gatt_gdbus_init_manager_proxy(const gchar *service,
-                                const gchar *path, const gchar *interface)
+               const gchar *path, const gchar *interface)
 {
        GDBusProxy *proxy;
        GError *err = NULL;
@@ -2418,11 +2412,11 @@ static GDBusProxy *__bt_hal_gatt_gdbus_init_manager_proxy(const gchar *service,
 }
 
 static GDBusProxy *__bt_gatt_gdbus_get_gatt_manager_proxy(const gchar *service,
-                                const gchar *path, const gchar *interface)
+               const gchar *path, const gchar *interface)
 {
-        return (manager_gproxy) ? manager_gproxy :
-                        __bt_hal_gatt_gdbus_init_manager_proxy(service,
-                                path, interface);
+       return (manager_gproxy) ? manager_gproxy :
+               __bt_hal_gatt_gdbus_init_manager_proxy(service,
+                               path, interface);
 }
 
 static void __bt_register_application_to_dbus(int slot)
@@ -2462,17 +2456,16 @@ static bt_status_t gatt_server_start_service(int server_if, int service_handle,
        if (serv_info == NULL)
                return BT_STATUS_FAIL;
 
-       if (serv_info->is_svc_registered) {
+       if (serv_info->is_svc_registered)
                DBG("service already registered \n");
-       }
 
        serv_info->is_svc_registered = TRUE;
 
        /* Send Service handle to application */
-        user_data = g_malloc0(sizeof(hal_gatt_service_started));
-        user_data->srvc_hdl = serv_info->service_handle;
-        user_data->instance_data = server_if;
-        g_idle_add(__bt_hal_gatt_service_started_cb, (gpointer)user_data);
+       user_data = g_malloc0(sizeof(hal_gatt_service_started));
+       user_data->srvc_hdl = serv_info->service_handle;
+       user_data->instance_data = server_if;
+       g_idle_add(__bt_hal_gatt_service_started_cb, (gpointer)user_data);
 
        /* If this is nth Service that is started, then register application at this point */
        if (__bt_is_service_last_in_server_list(server_if, service_handle)) {
@@ -2583,9 +2576,8 @@ static bt_status_t gatt_server_delete_service(int server_if, int service_handle)
        /* Remove from GATT Server's list of services */
        _bt_remote_service_from_gatt_server(server_if, service_handle);
 
-       if (gatt_services == NULL) {
+       if (gatt_services == NULL)
                INFO("All GATT Services of all GATT Servers are unregistered");
-       }
 
        if (err == BT_STATUS_SUCCESS) {
                INFO("Send GATT Service deleted Event");
@@ -2603,21 +2595,21 @@ static bt_status_t gatt_server_delete_service(int server_if, int service_handle)
 
 static gboolean __bt_gatt_get_service_state(const char *service_path)
 {
-        struct gatt_service_info *svc_info = NULL;
-        GSList *l = NULL;
+       struct gatt_service_info *svc_info = NULL;
+       GSList *l = NULL;
 
-        for (l= gatt_services; l; l = g_slist_next(l)) {
+       for (l = gatt_services; l; l = g_slist_next(l)) {
 
-                svc_info = (struct gatt_service_info *)l->data;
-                if (svc_info->serv_path == service_path) {
-                        DBG("Return the state of the gatt service %d",
-                                        svc_info->is_svc_registered);
-                        return svc_info->is_svc_registered;
-                }
-        }
+               svc_info = (struct gatt_service_info *)l->data;
+               if (svc_info->serv_path == service_path) {
+                       DBG("Return the state of the gatt service %d",
+                                       svc_info->is_svc_registered);
+                       return svc_info->is_svc_registered;
+               }
+       }
 
-        DBG("gatt service info is NULL");
-        return FALSE;
+       DBG("gatt service info is NULL");
+       return FALSE;
 }
 
 static bt_status_t gatt_server_send_indication(int server_if, int attribute_handle, int conn_id,
@@ -2627,7 +2619,7 @@ static bt_status_t gatt_server_send_indication(int server_if, int attribute_hand
 
        /* For Notifying */
        GVariantBuilder *outer_builder;
-        GVariantBuilder *invalidated_builder;
+       GVariantBuilder *invalidated_builder;
 
        /* For Value update via PropertyChange */
        GVariantBuilder *outer_builder1;
@@ -2813,10 +2805,9 @@ static bt_status_t gatt_server_send_response(int conn_id, int trans_id,
 
        DBG("Reponse Value length [%d]", response->attr_value.len);
        /* DEBUG */
-       for(i=0; i < response->attr_value.len; i++) {
+       for (i = 0; i < response->attr_value.len; i++)
                DBG("Resonse [%d] = [0x%x]", response->attr_value.value[i]);
 
-       }
 
        if (req_info->request_type == BT_HAL_GATT_REQUEST_TYPE_READ) {
                GVariantBuilder *inner_builder = NULL;
@@ -2846,7 +2837,7 @@ static bt_status_t gatt_server_send_response(int conn_id, int trans_id,
 }
 
 static bt_status_t gatt_server_update_att_value(int server_if, int attribute_handle,
-                int value_length, char* att_value)
+               int value_length, char* att_value)
 {
        CHECK_BTGATT_INIT();
 
@@ -2977,7 +2968,7 @@ static bt_status_t gatt_server_multi_adv_enable(int server_if)
        return _bt_hal_enable_advertising(server_if, TRUE, TRUE);
 }
 
-static bt_status_t gatt_server_multi_adv_update(int server_if, int min_interval,int max_interval,int adv_type,
+static bt_status_t gatt_server_multi_adv_update(int server_if, int min_interval, int max_interval, int adv_type,
                int chnl_map, int tx_power, int timeout_s)
 {
        CHECK_BTGATT_INIT();
@@ -3022,17 +3013,17 @@ static bt_status_t gatt_server_get_mtu_size(int conn_id, int *mtu_size)
 
        /* GDBUS Connection Info validate */
        conn = _bt_hal_get_system_gconn();
-        if (conn == NULL) {
-                ERR("Could not get System DBUS Connection");
-                return  BT_STATUS_FAIL;
-        }
+       if (conn == NULL) {
+               ERR("Could not get System DBUS Connection");
+               return  BT_STATUS_FAIL;
+       }
 
        /* Connection Info validate */
        conn_info = __bt_find_remote_gatt_client_info_from_conn(conn_id);
-        if (conn_info == NULL) {
-                ERR("No Connection Inforamtion!!!");
-                return BT_STATUS_FAIL;
-        }
+       if (conn_info == NULL) {
+               ERR("No Connection Inforamtion!!!");
+               return BT_STATUS_FAIL;
+       }
 
 
        object_path = _bt_hal_get_device_object_path(conn_info->addr);