4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
28 #include "user_request.h"
29 #include "communicator.h"
31 struct tcore_user_request_type {
33 struct tcore_user_info ui;
39 enum tcore_request_command command;
42 unsigned int data_len;
45 unsigned int metainfo_len;
47 UserRequestFreeHook free_hook;
48 UserRequestResponseHook response_hook;
49 void *response_hook_user_data;
52 UserRequest *tcore_user_request_new(Communicator *comm, const char *modem_name)
56 ur = calloc(1, sizeof(struct tcore_user_request_type));
63 ur->modem_name = strdup(modem_name);
65 ur->modem_name = NULL;
70 void tcore_user_request_free(UserRequest *ur)
92 dbg("user_request(0x%x) free.", (unsigned int)ur);
97 UserRequest *tcore_user_request_ref(UserRequest *ur)
107 void tcore_user_request_unref(UserRequest *ur)
115 tcore_user_request_free(ur);
120 TReturn tcore_user_request_set_free_hook(UserRequest *ur,
121 UserRequestFreeHook free_hook)
124 return TCORE_RETURN_EINVAL;
126 ur->free_hook = free_hook;
128 return TCORE_RETURN_SUCCESS;
131 TReturn tcore_user_request_set_response_hook(UserRequest *ur,
132 UserRequestResponseHook resp_hook, void *user_data)
135 return TCORE_RETURN_EINVAL;
137 ur->response_hook = resp_hook;
138 ur->response_hook_user_data = user_data;
140 return TCORE_RETURN_SUCCESS;
143 Communicator *tcore_user_request_ref_communicator(UserRequest *ur)
151 char *tcore_user_request_get_modem_name(UserRequest *ur)
159 return strdup(ur->modem_name);
162 TReturn tcore_user_request_set_user_info(UserRequest *ur,
163 const struct tcore_user_info *ui)
166 return TCORE_RETURN_EINVAL;
168 ur->ui.uid = ui->uid;
169 ur->ui.gid = ui->gid;
170 ur->ui.pid = ui->pid;
171 ur->ui.channel_id = ui->channel_id;
172 ur->ui.client_cmd = ui->client_cmd;
173 ur->ui.user_data = ui->user_data;
175 if (ur->ui.appname) {
176 dbg("free old appname (%s)", ur->ui.appname);
177 free(ur->ui.appname);
178 ur->ui.appname = NULL;
182 ur->ui.appname = strdup(ui->appname);
183 dbg("alloc appname(%s, %s)", ur->ui.appname, ui->appname);
186 return TCORE_RETURN_SUCCESS;
189 const struct tcore_user_info *tcore_user_request_ref_user_info(UserRequest *ur)
197 TReturn tcore_user_request_send_response(UserRequest *ur,
198 enum tcore_response_command command,
199 unsigned int data_len, const void *data)
203 return TCORE_RETURN_EINVAL;
206 if (ur->response_hook) {
207 ur->response_hook(ur, command, data_len, data,
208 ur->response_hook_user_data);
212 return tcore_communicator_send_response(ur->comm, ur,
213 command, data_len, data);
216 return TCORE_RETURN_SUCCESS;
219 TReturn tcore_user_request_set_command(UserRequest *ur,
220 enum tcore_request_command command)
223 return TCORE_RETURN_EINVAL;
225 ur->command = command;
227 return TCORE_RETURN_SUCCESS;
230 enum tcore_request_command tcore_user_request_get_command(UserRequest *ur)
238 TReturn tcore_user_request_set_data(UserRequest *ur,
239 unsigned int data_len, const void *data)
242 return TCORE_RETURN_EINVAL;
244 ur->data_len = data_len;
246 if (data_len > 0 && data != NULL) {
247 ur->data = calloc(data_len, 1);
249 return TCORE_RETURN_ENOMEM;
251 memcpy(ur->data, data, data_len);
257 return TCORE_RETURN_SUCCESS;
260 TReturn tcore_user_request_set_metainfo(UserRequest *ur,
261 unsigned int metainfo_len, const void *metainfo)
264 return TCORE_RETURN_EINVAL;
266 if (metainfo_len > 0 && metainfo != NULL) {
267 ur->metainfo = calloc(metainfo_len, 1);
269 return TCORE_RETURN_ENOMEM;
271 ur->metainfo_len = metainfo_len;
272 memcpy(ur->metainfo, metainfo, metainfo_len);
276 ur->metainfo_len = 0;
279 return TCORE_RETURN_SUCCESS;
282 const void *tcore_user_request_ref_data(UserRequest *ur,
283 unsigned int *data_len)
289 *data_len = ur->data_len;
294 const void *tcore_user_request_ref_metainfo(UserRequest *ur,
295 unsigned int *metainfo_len)
301 *metainfo_len = ur->metainfo_len;