Modify build feature names as Tizen 3.0 build option naming rule
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-gatt-service.c
index 7ec424c..d33e0f3 100644 (file)
@@ -189,7 +189,7 @@ static gchar *app_path = NULL;
 #define GATT_CHAR_INTERFACE            "org.bluez.GattCharacteristic1"
 #define GATT_DESC_INTERFACE            "org.bluez.GattDescriptor1"
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
 #define BT_HPS_OBJECT_PATH "/org/projectx/httpproxy"
 #define BT_HPS_INTERFACE_NAME "org.projectx.httpproxy_service"
 #define PROPERTIES_CHANGED "PropertiesChanged"
@@ -234,7 +234,7 @@ static void __bt_gatt_close_gdbus_connection(void)
        BT_DBG("-");
 }
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
 static int __bt_send_event_to_hps(int event, GVariant *var)
 {
        GError *error = NULL;
@@ -299,7 +299,7 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                                        GDBusMethodInvocation *invocation,
                                        gpointer user_data)
 {
-       GSList *l1;
+       GSList *l1 = NULL;
        int len = 0;
        int i = 0;
 
@@ -322,13 +322,19 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                        GVariantBuilder *svc_builder = NULL;
                        GVariantBuilder *inner_builder = NULL;
 
-                       if (register_pending_cnt > 1) {
+                       if (register_pending_cnt > 1)
                                l1 = g_slist_nth(gatt_services, len - register_pending_cnt);
-                       } else {
+                       else
                                l1 = g_slist_last(gatt_services);
-                       }
+
                        register_pending_cnt--;
 
+                       if (l1 == NULL) {
+                               BT_ERR("gatt service list is NULL");
+                               g_dbus_method_invocation_return_value(invocation, NULL);
+                               return;
+                       }
+
                        struct gatt_service_info *serv_info = l1->data;
                        if (serv_info == NULL) {
                                BT_ERR("service info value is NULL");
@@ -652,7 +658,7 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                if (svc_info != NULL) {
                        read_req.service_handle = g_strdup(svc_info->serv_path);
                        user_info = _bt_get_user_data(BT_COMMON);
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
                        GVariant *param = NULL;
 #endif
 
@@ -671,7 +677,7 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                        BLUETOOTH_ERROR_NONE, &read_req,
                                        user_info->cb, user_info->user_data);
                        }
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
                        param = g_variant_new("(sssyq)",
                                        read_req.att_handle,
                                        read_req.service_handle,
@@ -699,7 +705,7 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                int len = 0;
                struct gatt_service_info *svc_info = NULL;
                struct gatt_req_info *req_info = NULL;
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
                GVariant *param = NULL;
 #endif
 
@@ -756,7 +762,7 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                BLUETOOTH_ERROR_NONE, &value_change,
                                user_info->cb, user_info->user_data);
                }
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
                if (len > 0) {
                        gchar *svc_path;
                        svc_path = g_strdup(svc_info->serv_path);
@@ -1128,9 +1134,8 @@ static struct gatt_req_info *__bt_gatt_find_request_info(guint request_id)
        for (l = gatt_requests; l != NULL; l = l->next) {
                struct gatt_req_info *req_info = l->data;
 
-               if (req_info && req_info->request_id == request_id) {
+               if (req_info && req_info->request_id == request_id)
                        return req_info;
-               }
        }
        BT_ERR("Gatt Request not found");
        return NULL;
@@ -1391,6 +1396,8 @@ void register_application_cb(GObject *object, GAsyncResult *res, gpointer user_d
                                                error->code, error->message);
                        g_clear_error(&error);
                }
+       } else {
+               g_variant_unref(result);
        }
 }
 
@@ -1414,6 +1421,8 @@ void unregister_application_cb(GObject *object, GAsyncResult *res,
                                        error->code, error->message);
                        g_clear_error(&error);
                }
+       } else {
+               g_variant_unref(result);
        }
 }
 
@@ -1783,9 +1792,9 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
        char_info->char_id = object_id;
        char_info->char_uuid = g_strdup(char_uuid);
 
-       for (i = 0; i < flag_count; i++) {
+       for (i = 0; i < flag_count; i++)
                char_info->char_flags[i] = char_flags[i];
-               }
+
 
        char_info->flags_length = flag_count;
 
@@ -1801,9 +1810,8 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
 
        builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
 
-       for (i = 0; i < flag_count; i++) {
+       for (i = 0; i < flag_count; i++)
                g_variant_builder_add(builder2, "s", char_flags[i]);
-       }
 
        flags_val = g_variant_new("as", builder2);
        g_variant_builder_add(inner_builder, "{sv}", "Flags",
@@ -1882,9 +1890,8 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristic_value(
 
        builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
 
-       for (i = 0; i < value_length; i++) {
+       for (i = 0; i < value_length; i++)
                g_variant_builder_add(builder1, "y", char_value[i]);
-       }
 
        char_val = g_variant_new("ay", builder1);
                g_variant_builder_add(inner_builder, "{sv}", "Value", char_val);
@@ -1982,9 +1989,8 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
        desc_info->desc_id = object_id;
        desc_info->desc_uuid = g_strdup(desc_uuid);
 
-       for (i = 0; i < flag_count; i++) {
+       for (i = 0; i < flag_count; i++)
                desc_info->desc_flags[i] = desc_flags[i];
-               }
 
        desc_info->flags_length = flag_count;
 
@@ -2000,9 +2006,8 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
 
        builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
 
-       for (i = 0; i < flag_count; i++) {
+       for (i = 0; i < flag_count; i++)
                g_variant_builder_add(builder2, "s", desc_flags[i]);
-       }
 
        flags_val = g_variant_new("as", builder2);
        g_variant_builder_add(inner_builder, "{sv}", "Flags",
@@ -2074,9 +2079,9 @@ BT_EXPORT_API int bluetooth_gatt_set_descriptor_value(
 
        builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
 
-       for (i = 0; i < value_length; i++) {
+       for (i = 0; i < value_length; i++)
                g_variant_builder_add(builder1, "y", desc_value[i]);
-       }
+
        desc_val = g_variant_new("ay", builder1);
        g_variant_builder_add(inner_builder, "{sv}", "Value", desc_val);
 
@@ -2244,9 +2249,8 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
        invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
 
        inner_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
-       for (i = 0; i < value_length; i++) {
+       for (i = 0; i < value_length; i++)
                g_variant_builder_add(inner_builder, "y", char_value[i]);
-       }
 
        update_value = g_variant_new("ay", inner_builder);
 
@@ -2290,9 +2294,8 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
 
                char_info->char_value = (char *)realloc(char_info->char_value, value_length);
                if (char_info->char_value) {
-                       for (i = 0; i < value_length; i++) {
+                       for (i = 0; i < value_length; i++)
                                char_info->char_value[i] = char_value[i];
-                       }
                }
        }
 
@@ -2426,9 +2429,8 @@ BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
        }
 
        ret = g_dbus_connection_unregister_object(g_conn, svc_info->prop_id);
-       if (ret) {
+       if (ret)
                BT_DBG("Unregistered the service on properties interface");
-       }
 
        /* list remove & free */
        gatt_services = g_slist_remove(gatt_services, svc_info);
@@ -2436,11 +2438,10 @@ BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
 
        new_service = FALSE;
 
-       if (gatt_services == NULL) {
+       if (gatt_services == NULL)
                serv_id = 1;
-       } else if (gatt_services->next == NULL) {
+       else if (gatt_services->next == NULL)
                serv_id--;
-       }
 
        return err;
 }
@@ -2521,10 +2522,13 @@ BT_EXPORT_API int bluetooth_gatt_server_set_notification(const char *char_path,
 
        if (!__bt_gatt_get_service_state(serv_path)) {
                BT_DBG("service not registered for this characteristic \n");
+               g_free(serv_path);
                g_strfreev(line_argv);
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
+       g_free(serv_path);
+
        outer_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
        invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));