4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
25 #include <dbus/dbus-glib.h>
26 #include <dbus/dbus.h>
30 #include "bluetooth-api.h"
31 #include "bt-service-common.h"
32 #include "bt-service-util.h"
34 static GSList *req_list = NULL;
36 /* available request id : 0 ~ 244 */
37 #define BT_REQUEST_ID_RANGE_MAX 245
39 static int assigned_id;
40 static gboolean req_id_used[BT_REQUEST_ID_RANGE_MAX];
42 void _bt_init_request_id(void)
45 memset(req_id_used, 0x00, BT_REQUEST_ID_RANGE_MAX);
48 int _bt_assign_request_id(void)
52 index = assigned_id + 1;
54 if (index >= BT_REQUEST_ID_RANGE_MAX)
57 while (req_id_used[index] == TRUE) {
58 if (index == assigned_id) {
60 BT_ERR("All request ID is used");
66 if (index >= BT_REQUEST_ID_RANGE_MAX)
71 req_id_used[index] = TRUE;
76 void _bt_delete_request_id(int request_id)
78 ret_if(request_id >= BT_REQUEST_ID_RANGE_MAX);
79 ret_if(request_id < 0);
81 req_id_used[request_id] = FALSE;
84 void _bt_init_request_list(void)
86 _bt_clear_request_list();
89 /* insert request next to head */
90 int _bt_insert_request_list(int req_id, int service_function,
91 char *name, DBusGMethodInvocation *context)
95 info = g_malloc0(sizeof(request_info_t));
97 info->req_id = req_id;
98 info->service_function = service_function;
99 info->context = context;
101 req_list = g_slist_append(req_list, info);
103 return BLUETOOTH_ERROR_NONE;
106 request_info_t *_bt_get_request_info(int req_id)
109 request_info_t *info;
111 for (l = req_list; l != NULL; l = g_slist_next(l)) {
116 if (info->req_id == req_id)
123 /* delete request which has the target req_id */
124 int _bt_delete_request_list(int req_id)
127 request_info_t *info;
129 for (l = req_list; l != NULL; l = g_slist_next(l)) {
134 if (info->req_id == req_id) {
135 req_list = g_slist_remove(req_list, info);
136 _bt_delete_request_id(info->req_id);
138 return BLUETOOTH_ERROR_NONE;
142 return BLUETOOTH_ERROR_NOT_FOUND;
145 void _bt_clear_request_list(void)
148 g_slist_foreach(req_list, (GFunc)g_free, NULL);
149 g_slist_free(req_list);