Remove unnecessary logic for request Ids 57/134057/2
authorAtul Rai <a.rai@samsung.com>
Tue, 13 Jun 2017 10:41:36 +0000 (16:11 +0530)
committerAtul Rai <a.rai@samsung.com>
Wed, 14 Jun 2017 10:56:19 +0000 (16:26 +0530)
This patch removes request Id logic for SYNC/ASYNC requests from
BT-API to bt-service, as request Ids are no longer used in new BT
architecture. Instead _bt_save_invocation_context() is used for
saving context for ASYNC requests from BT-API.

Change-Id: I9edc0c6df864ca32e3b368a0c62f5ba97ac5c1fd
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-service-adaptation/services/bt-request-handler.c
bt-service-adaptation/services/bt-service-main.c
bt-service-adaptation/services/bt-service-util.c
bt-service-adaptation/services/include/bt-service-util.h

index 86d12cb..17323d3 100644 (file)
@@ -191,7 +191,8 @@ static gboolean __bt_is_sync_function(int service_function)
                        || service_function == BT_GATT_SERVER_STOP_SERVICE
                        || service_function == BT_GATT_SERVER_DELETE_SERVICE
                        || service_function == BT_START_LE_DISCOVERY
-                       || service_function == BT_STOP_LE_DISCOVERY)
+                       || service_function == BT_STOP_LE_DISCOVERY
+                       || service_function == BT_OBEX_SERVER_ACCEPT_CONNECTION)
                return TRUE;
        else
                return FALSE;
@@ -237,6 +238,7 @@ static void __bt_service_method(GDBusConnection *connection,
                GVariant *param5 = NULL;
                GArray *out_param1 = NULL;
                GVariant *out_var = NULL;
+               GVariant *temp = NULL;
                int result = 0;
                int request_id = -1;
                const char *sender = NULL;
@@ -257,20 +259,6 @@ static void __bt_service_method(GDBusConnection *connection,
                        goto fail;
                }
 
-               if (request_type == BT_ASYNC_REQ
-                               || service_function == BT_OBEX_SERVER_ACCEPT_CONNECTION) {
-                       /* Set the timer */
-                       request_id = _bt_assign_request_id();
-                       BT_DBG("Request ID: %d", request_id);
-
-                       if (request_id < 0) {
-                               BT_ERR("Fail to assign the request id");
-                               result = BLUETOOTH_ERROR_INTERNAL;
-
-                               goto fail;
-                       }
-               }
-
                BT_DBG("SERVICE TYPE [%d] SERVICE FUNC [%d]",
                                service_type, service_function);
                switch (service_type) {
@@ -308,40 +296,33 @@ static void __bt_service_method(GDBusConnection *connection,
                        goto fail;
                }
 
-               if (result != BLUETOOTH_ERROR_NONE) {
+               if (result != BLUETOOTH_ERROR_NONE)
                        goto fail;
-               }
 
-               if ((request_type == BT_ASYNC_REQ ||
-                       service_function == BT_OBEX_SERVER_ACCEPT_CONNECTION) &&
-                       service_function != BT_OPP_PUSH_FILES) {
-                       BT_DBG("INSERT INTO REQ LIST");
-                       _bt_insert_request_list(request_id, service_function,
-                                               NULL, invocation);
-               } else {
-                       /* Return result */
-                       if (service_type == BT_CHECK_PRIVILEGE ||
-                                       service_function != BT_OPP_PUSH_FILES) {
-                               if (!__bt_is_sync_function(service_function)) {
-                                       out_var = g_variant_new_from_data((const GVariantType *)"ay",
-                                                       out_param1->data, out_param1->len,
-                                                       TRUE, NULL, NULL);
-
-                                       GVariant *temp = g_variant_new("(iv)", result, out_var);
-                                       g_dbus_method_invocation_return_value(invocation, temp);
-                               } else {
-                                       /*
-                                        * API expects return value from Bluetooth stack, so just save
-                                        * the invocation and invoke it when we get response from stack.
-                                        */
-                                       BT_INFO("Invocation context will be saved in service_function");
-                               }
-
-                               g_array_free(out_param1, TRUE);
-                               out_param1 = NULL;
-                       }
+               if (service_function == BT_OPP_PUSH_FILES)
+                       goto done;
+
+               if (service_type == BT_CHECK_PRIVILEGE)
+                       goto send_reply;
+
+               if (request_type == BT_ASYNC_REQ ||
+                               __bt_is_sync_function(service_function)) {
+                       BT_INFO("Do not send reply to bt-api over dbus,"
+                               " Invocation context is already saved in service_function");
+                       goto done;
                }
 
+send_reply:
+               out_var = g_variant_new_from_data((const GVariantType *)"ay",
+                               out_param1->data, out_param1->len,
+                               TRUE, NULL, NULL);
+
+               temp = g_variant_new("(iv)", result, out_var);
+               g_dbus_method_invocation_return_value(invocation, temp);
+               g_array_free(out_param1, TRUE);
+               out_param1 = NULL;
+
+done:
                g_variant_unref(param1);
                g_variant_unref(param2);
                g_variant_unref(param3);
@@ -357,15 +338,12 @@ fail:
                                out_param1->data, out_param1->len,
                                TRUE, NULL, NULL);
 
-               GVariant *temp = g_variant_new("(iv)", result, out_var);
+               temp = g_variant_new("(iv)", result, out_var);
                g_dbus_method_invocation_return_value(invocation, temp);
 
                g_array_free(out_param1, TRUE);
                out_param1 = NULL;
 
-               if (request_type == BT_ASYNC_REQ)
-                       _bt_delete_request_id(request_id);
-
                g_variant_unref(param1);
                g_variant_unref(param2);
                g_variant_unref(param3);
index 45926b8..66d7e8b 100644 (file)
@@ -91,25 +91,20 @@ int main(void)
        }
 
        /* Event sender Init */
-        if (_bt_init_service_event_sender() != BLUETOOTH_ERROR_NONE) {
-                BT_ERR("Fail to init event sender");
-                return 0;
-        }
-
-        if (_bt_init_hf_local_term_event_sender() != BLUETOOTH_ERROR_NONE) {
-                BT_ERR("Fail to init core event sender");
-                return 0;
-        }
-
-        if (_bt_service_register() != BLUETOOTH_ERROR_NONE) {
-                BT_ERR("Fail to register service");
-                return 0;
-        }
-
-       _bt_init_request_id();
+       if (_bt_init_service_event_sender() != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("Fail to init event sender");
+               return 0;
+       }
 
-        _bt_init_request_list();
+       if (_bt_init_hf_local_term_event_sender() != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("Fail to init core event sender");
+               return 0;
+       }
 
+       if (_bt_service_register() != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("Fail to register service");
+               return 0;
+       }
 
        /* BT Stack Init */
        if (_bt_stack_init() != BLUETOOTH_ERROR_NONE) {
@@ -119,10 +114,10 @@ int main(void)
 
        g_timeout_add(500, (GSourceFunc)__bt_check_bt_service, NULL);
 
-        if (terminated == TRUE) {
-                __bt_release_service();
-                return 0;
-        }
+       if (terminated == TRUE) {
+               __bt_release_service();
+               return 0;
+       }
 
        main_loop = g_main_loop_new(NULL, FALSE);
 
index cd69ff1..9fad69f 100644 (file)
 #include "bt-service-common.h"
 #include "bt-service-util.h"
 
-static GSList *req_list = NULL;
-
-/* available request id : 0 ~ 244 */
-#define BT_REQUEST_ID_RANGE_MAX 245
-
-static int assigned_id;
-static gboolean req_id_used[BT_REQUEST_ID_RANGE_MAX];
-
-void _bt_init_request_id(void)
-{
-       assigned_id = 0;
-       memset(req_id_used, 0x00, BT_REQUEST_ID_RANGE_MAX);
-}
-
-int _bt_assign_request_id(void)
-{
-       int index;
-
-       index = assigned_id + 1;
-
-       if (index >= BT_REQUEST_ID_RANGE_MAX)
-               index = 0;
-
-       while (req_id_used[index] == TRUE) {
-               if (index == assigned_id) {
-                       /* No available ID */
-                       BT_ERR("All request ID is used");
-                       return -1;
-               }
-
-               index++;
-
-               if (index >= BT_REQUEST_ID_RANGE_MAX)
-                       index = 0;
-       }
-
-       assigned_id = index;
-       req_id_used[index] = TRUE;
-
-       return assigned_id;
-}
-
-void _bt_delete_request_id(int request_id)
-{
-       ret_if(request_id >= BT_REQUEST_ID_RANGE_MAX);
-       ret_if(request_id < 0);
-
-       req_id_used[request_id] = FALSE;
-}
-
-void _bt_init_request_list(void)
-{
-       _bt_clear_request_list();
-}
-
-/* insert request next to head */
-int _bt_insert_request_list(int req_id, int service_function,
-               char *name, GDBusMethodInvocation *context)
-{
-       request_info_t *info;
-
-       info = g_malloc0(sizeof(request_info_t));
-       /* Fix : NULL_RETURNS */
-       retv_if(info == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION);
-
-       info->req_id = req_id;
-       info->service_function = service_function;
-       info->context = context;
-
-       req_list = g_slist_append(req_list, info);
-
-       return BLUETOOTH_ERROR_NONE;
-}
-
-request_info_t *_bt_get_request_info(int req_id)
-{
-       GSList *l;
-       request_info_t *info;
-
-       for (l = req_list; l != NULL; l = g_slist_next(l)) {
-               info = l->data;
-               if (info == NULL)
-                       continue;
-
-               if (info->req_id == req_id)
-                       return info;
-       }
-
-       return NULL;
-}
-
-/* delete request which has the target req_id */
-int _bt_delete_request_list(int req_id)
-{
-       GSList *l;
-       request_info_t *info;
-
-       for (l = req_list; l != NULL; l = g_slist_next(l)) {
-               info = l->data;
-               if (info == NULL)
-                       continue;
-
-               if (info->req_id == req_id) {
-                       req_list = g_slist_remove(req_list, info);
-                       _bt_delete_request_id(info->req_id);
-                       g_free(info);
-                       return BLUETOOTH_ERROR_NONE;
-               }
-       }
-
-       return BLUETOOTH_ERROR_NOT_FOUND;
-}
-
-void _bt_clear_request_list(void)
-{
-       if (req_list) {
-               g_slist_foreach(req_list, (GFunc)g_free, NULL);
-               g_slist_free(req_list);
-               req_list = NULL;
-       }
-}
-
 void _bt_service_convert_uuid_type_to_string(char *str, const unsigned char *uuid)
 {
        ret_if(str == NULL);
index b101802..4836638 100755 (executable)
@@ -36,32 +36,6 @@ static const char BT_SERVICE_BASE_UUID[] = {
        0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb
 };
 
-typedef struct {
-       int req_id;
-       int service_function;
-       char name[BT_NODE_NAME_LEN];
-       GDBusMethodInvocation *context;
-} request_info_t;
-
-
-void _bt_init_request_id(void);
-
-int _bt_assign_request_id(void);
-
-void _bt_delete_request_id(int request_id);
-
-
-void _bt_init_request_list(void);
-
-int _bt_insert_request_list(int req_id, int service_function,
-                       char *name, GDBusMethodInvocation *context);
-
-int _bt_delete_request_list(int req_id);
-
-request_info_t *_bt_get_request_info(int req_id);
-
-void _bt_clear_request_list(void);
-
 void _bt_service_convert_uuid_type_to_string(char *str, const unsigned char *uuid);
 void _bt_service_convert_uuid_string_to_type(unsigned char *uuid, const char *str);