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 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt)
212 li = kmalloc(sizeof(*li), GFP_KERNEL);
216 li->func = kmalloc(sizeof(struct func_inst_data *) * cnt, GFP_KERNEL);
217 if (li->func == NULL)
220 for (i = 0; i < cnt; ++i) {
221 fi = create_func_inst_data(mb);
234 for (j = 0; j < i; ++j)
235 destroy_func_inst_data(li->func[j]);
247 void destroy_lib_inst_data(struct lib_inst_data *li)
251 put_strung(li->path);
253 for (i = 0; i < li->cnt_func; ++i)
254 destroy_func_inst_data(li->func[i]);
264 /* ============================================================================
266 * ============================================================================
268 struct app_inst_data *create_app_inst_data(struct msg_buf *mb)
270 struct app_inst_data *app_inst;
271 struct app_info_data *app_info;
272 struct func_inst_data *func;
273 struct lib_inst_data *lib;
274 u32 cnt_func, i_func = 0, cnt_lib, i_lib = 0, i;
276 app_info = create_app_info(mb);
277 if (app_info == NULL)
280 if (get_u32(mb, &cnt_func))
283 if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt_func)
286 app_inst = kmalloc(sizeof(*app_inst), GFP_KERNEL);
287 if (app_inst == NULL)
290 app_inst->func = kmalloc(sizeof(struct func_inst_data *) * cnt_func,
292 if (app_inst->func == NULL)
295 for (i_func = 0; i_func < cnt_func; ++i_func) {
296 func = create_func_inst_data(mb);
300 app_inst->func[i_func] = func;
303 if (get_u32(mb, &cnt_lib))
306 if (remained_mb(mb) / MIN_SIZE_LIB_INST < cnt_lib)
309 app_inst->lib = kmalloc(sizeof(struct lib_inst_data *) * cnt_lib,
311 if (app_inst->lib == NULL)
314 for (i_lib = 0; i_lib < cnt_lib; ++i_lib) {
315 lib = create_lib_inst_data(mb);
319 app_inst->lib[i_lib] = lib;
322 app_inst->cnt_func = cnt_func;
323 app_inst->cnt_lib = cnt_lib;
328 for (i = 0; i < i_lib; ++i)
329 destroy_lib_inst_data(app_inst->lib[i]);
330 kfree(app_inst->lib);
333 for (i = 0; i < i_func; ++i)
334 destroy_func_inst_data(app_inst->func[i]);
335 kfree(app_inst->func);
341 destroy_app_info(app_info);
346 void destroy_app_inst_data(struct app_inst_data *ai)
350 for (i = 0; i < ai->cnt_lib; ++i)
351 destroy_lib_inst_data(ai->lib[i]);
354 for (i = 0; i < ai->cnt_func; ++i)
355 destroy_func_inst_data(ai->func[i]);
358 destroy_app_info(ai->app_info);
366 /* ============================================================================
368 * ============================================================================
370 struct us_inst_data *create_us_inst_data(struct msg_buf *mb)
372 struct us_inst_data *ui;
373 struct app_inst_data *ai;
376 if (get_u32(mb, &cnt))
379 if (remained_mb(mb) / MIN_SIZE_APP_INST < cnt)
382 ui = kmalloc(sizeof(struct us_inst_data), GFP_KERNEL);
386 ui->app_inst = kmalloc(sizeof(struct app_inst_data *) * cnt,
388 if (ui->app_inst == NULL)
391 for (i = 0; i < cnt; ++i) {
392 ai = create_app_inst_data(mb);
396 ui->app_inst[i] = ai;
404 for (j = 0; j < i; ++j)
405 destroy_app_inst_data(ui->app_inst[j]);
414 void destroy_us_inst_data(struct us_inst_data *ui)
418 for (i = 0; i < ui->cnt; ++i)
419 destroy_app_inst_data(ui->app_inst[i]);