|| 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;
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;
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) {
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);
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);
}
/* 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) {
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);
#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);
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);