Merge "[REFACTOR] Buffer: move getting next queue element into separate function"
[kernel/swap-modules.git] / parser / msg_parser.c
index b0d1b57..394aae2 100644 (file)
@@ -1,3 +1,28 @@
+/*
+ *  SWAP Parser
+ *  modules/parser/msg_parser.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2013
+ *
+ * 2013         Vyacheslav Cherkashin, Vitaliy Cherepanov: SWAP Parser implement
+ *
+ */
+
+
 #include <linux/slab.h>
 #include "msg_parser.h"
 #include "msg_buf.h"
@@ -68,15 +93,20 @@ struct app_info_data *create_app_info(struct msg_buf *mb)
 
        switch (app_type) {
        case AT_TIZEN_NATIVE_APP:
+       case AT_TIZEN_WEB_APP:
        case AT_COMMON_EXEC:
                ai->tgid = 0;
                break;
        case AT_PID: {
-               u32 tgid;
-               ret = str_to_u32(ta_id, &tgid);
-               if (ret) {
-                       print_err("converting string to PID, str='%s'\n", ta_id);
-                       goto free_ai;
+               u32 tgid = 0;
+
+               if (*ta_id != '\0') {
+                       ret = str_to_u32(ta_id, &tgid);
+                       if (ret) {
+                               print_err("converting string to PID, "
+                                         "str='%s'\n", ta_id);
+                               goto free_ai;
+                       }
                }
 
                ai->tgid = tgid;
@@ -124,13 +154,18 @@ void destroy_app_info(struct app_info_data *ai)
 struct conf_data *create_conf_data(struct msg_buf *mb)
 {
        struct conf_data *conf;
-       u64 uf;
+       u64 use_features0, use_features1;
        u32 stp, dmp;
 
        print_parse_debug("conf_data:\n");
 
        print_parse_debug("features:");
-       if (get_u64(mb, &uf)) {
+       if (get_u64(mb, &use_features0)) {
+               print_err("failed to read use_features\n");
+               return NULL;
+       }
+
+       if (get_u64(mb, &use_features1)) {
                print_err("failed to read use_features\n");
                return NULL;
        }
@@ -153,7 +188,8 @@ struct conf_data *create_conf_data(struct msg_buf *mb)
                return NULL;
        }
 
-       conf->use_features = uf;
+       conf->use_features0 = use_features0;
+       conf->use_features1 = use_features1;
        conf->sys_trace_period = stp;
        conf->data_msg_period = dmp;
 
@@ -165,7 +201,16 @@ void destroy_conf_data(struct conf_data *conf)
        kfree(conf);
 }
 
+static struct conf_data config;
+void save_config(const struct conf_data *conf)
+{
+       memcpy(&config, conf, sizeof(config));
+}
 
+void restore_config(struct conf_data *conf)
+{
+       memcpy(conf, &config, sizeof(*conf));
+}
 
 
 
@@ -178,6 +223,7 @@ struct func_inst_data *create_func_inst_data(struct msg_buf *mb)
        struct func_inst_data *fi;
        u64 addr;
        char *args;
+       char ret_type;
 
        print_parse_debug("func addr:");
        if (get_u64(mb, &addr)) {
@@ -191,17 +237,27 @@ struct func_inst_data *create_func_inst_data(struct msg_buf *mb)
                return NULL;
        }
 
+       print_parse_debug("funct ret type:");
+       if (get_u8(mb, (u8 *)&ret_type)) {
+               print_err("failed to read data function arguments\n");
+               goto free_args;
+       }
+
        fi = kmalloc(sizeof(*fi), GFP_KERNEL);
        if (fi == NULL) {
                print_err("out of memory\n");
-               put_string(args);
-               return NULL;
+               goto free_args;
        }
 
        fi->addr = addr;
        fi->args = args;
+       fi->ret_type = ret_type;
 
        return fi;
+
+free_args:
+       put_string(args);
+       return NULL;
 }
 
 void destroy_func_inst_data(struct func_inst_data *fi)
@@ -234,12 +290,12 @@ struct lib_inst_data *create_lib_inst_data(struct msg_buf *mb)
        print_parse_debug("func count:");
        if (get_u32(mb, &cnt)) {
                print_err("failed to read count of functions\n");
-               return NULL;
+               goto free_path;
        }
 
        if (remained_mb(mb) / MIN_SIZE_FUNC_INST < cnt) {
                print_err("to match count of functions(%u)\n", cnt);
-               return NULL;
+               goto free_path;
        }
 
        li = kmalloc(sizeof(*li), GFP_KERNEL);