1 #include <linux/slab.h>
2 #include "msg_parser.h"
6 static int str_to_u32(const char* str, u32 *val)
12 for (result = 0 ; *str; ++str) {
13 if (*str < '0' || *str> '9')
16 result = result * 10 + (*str - '0');
28 /* ============================================================================
30 * ============================================================================
32 struct app_info_data *create_app_info(struct msg_buf *mb)
35 struct app_info_data *ai;
37 char *ta_id, *exec_path;
39 ret = get_u32(mb, &app_type);
43 ret = get_string(mb, &ta_id);
47 ret = get_string(mb, &exec_path);
51 ai = kmalloc(sizeof(*ai), GFP_KERNEL);
56 case AT_TIZEN_NATIVE_APP:
62 ret = str_to_u32(ta_id, &pid);
66 ai->at_data = (void *)pid;
74 ai->app_type = (enum APP_TYPE)app_type;
75 ai->exec_path = exec_path;
83 put_strung(exec_path);
91 void destroy_app_info(struct app_info_data *ai)
93 switch (ai->app_type) {
94 case AT_TIZEN_NATIVE_APP:
96 put_strung(ai->at_data);
103 printk("### BUG()\n");
107 put_strung(ai->exec_path);
115 /* ============================================================================
117 * ============================================================================
119 struct conf_data *create_conf_data(struct msg_buf *mb)
121 struct conf_data *conf;
125 if (get_u64(mb, &uf))
128 if (get_u32(mb, &stp))
131 if (get_u32(mb, &dmp))
134 conf = kmalloc(sizeof(*conf), GFP_KERNEL);
138 conf->use_features = uf;
139 conf->sys_trace_period = stp;
140 conf->data_msg_period = dmp;
145 void destroy_conf_data(struct conf_data *conf)
154 /* ============================================================================
156 * ============================================================================
158 struct func_inst_data *create_func_inst_data(struct msg_buf *mb)
160 struct func_inst_data *fi;
164 if (get_u64(mb, &addr))
167 if (get_string(mb, &args))
170 fi = kmalloc(sizeof(*fi), GFP_KERNEL);
182 void destroy_func_inst_data(struct func_inst_data *fi)
184 put_strung(fi->args);
192 /* ============================================================================
194 * ============================================================================
196 struct lib_inst_data *create_lib_inst_data(struct msg_buf *mb)
198 struct lib_inst_data *li;
199 struct func_inst_data *fi;
203 if (get_string(mb, &path))
206 if (get_u32(mb, &cnt))
209 li = kmalloc(sizeof(*li), GFP_KERNEL);
213 li->func = kmalloc(sizeof(struct func_inst_data *) * cnt, GFP_KERNEL);
217 for (i = 0; i < cnt; ++i) {
218 fi = create_func_inst_data(mb);
231 for (i -= 1; i >= 0; --i)
232 destroy_func_inst_data(li->func[i]);
244 void destroy_lib_inst_data(struct lib_inst_data *li)
248 put_strung(li->path);
250 for (i = 0; i < li->cnt_func; ++i)
251 destroy_func_inst_data(li->func[i]);
261 /* ============================================================================
263 * ============================================================================
265 struct app_inst_data *create_app_inst_data(struct msg_buf *mb)
267 struct app_inst_data *app_inst;
268 struct app_info_data *app_info;
269 struct func_inst_data *func;
270 struct lib_inst_data *lib;
271 u32 cnt_func, i_func = 0;
272 u32 cnt_lib, i_lib = 0;
274 app_info = create_app_info(mb);
275 if (app_info == NULL)
278 if (get_u32(mb, &cnt_func))
281 app_inst = kmalloc(sizeof(*app_inst), GFP_KERNEL);
282 if (app_inst == NULL)
285 app_inst->func = kmalloc(sizeof(struct func_inst_data *) * cnt_func,
287 if (app_inst->func == NULL)
290 for (i_func = 0; i_func < cnt_func; ++i_func) {
291 func = create_func_inst_data(mb);
295 app_inst->func[i_func] = func;
298 if (get_u32(mb, &cnt_lib))
301 app_inst->lib = kmalloc(sizeof(struct lib_inst_data *) * cnt_lib,
303 if (app_inst->lib == NULL)
306 for (i_lib = 0; i_lib < cnt_lib; ++i_lib) {
307 lib = create_lib_inst_data(mb);
311 app_inst->lib[i_lib] = lib;
314 app_inst->cnt_func = cnt_func;
315 app_inst->cnt_lib = cnt_lib;
320 for (i_lib -= 1; i_lib >= 0; --i_lib)
321 destroy_lib_inst_data(app_inst->lib[i_lib]);
322 kfree(app_inst->lib);
325 for (i_func -= 1; i_func >= 0; --i_func)
326 destroy_func_inst_data(app_inst->func[i_func]);
327 kfree(app_inst->func);
333 destroy_app_info(app_info);
338 void destroy_app_inst_data(struct app_inst_data *ai)
342 for (i = 0; i < ai->cnt_lib; ++i)
343 destroy_lib_inst_data(ai->lib[i]);
346 for (i = 0; i < ai->cnt_func; ++i)
347 destroy_func_inst_data(ai->func[i]);
350 destroy_app_info(ai->app_info);
358 /* ============================================================================
360 * ============================================================================
362 struct us_inst_data *create_us_inst_data(struct msg_buf *mb)
364 struct us_inst_data *ui;
365 struct app_inst_data *ai;
368 if (get_u32(mb, &cnt))
371 ui = kmalloc(sizeof(struct us_inst_data) * cnt, GFP_KERNEL);
375 ui->app_inst = kmalloc(sizeof(struct app_inst_data *) * cnt,
377 if (ui->app_inst == NULL)
380 for (i = 0; i < cnt; ++i) {
381 ai = create_app_inst_data(mb);
385 ui->app_inst[i] = ai;
393 for (i -= 1; i >= 0; --i)
394 destroy_app_inst_data(ui->app_inst[i]);
403 void destroy_us_inst_data(struct us_inst_data *ui)
407 for (i = 0; i < ui->cnt; ++i)
408 destroy_app_inst_data(ui->app_inst[i]);