[IMPROVE] add msg_cmd
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 4 Jul 2013 09:03:56 +0000 (13:03 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 4 Jul 2013 09:03:56 +0000 (13:03 +0400)
parser/Kbuild
parser/msg_buf.c
parser/msg_buf.h
parser/msg_cmd.c [new file with mode: 0644]
parser/msg_cmd.h [new file with mode: 0644]

index f457efe..8ea23a2 100644 (file)
@@ -1,6 +1,7 @@
 EXTRA_CFLAGS := $(extra_cflags)
 
 obj-m := swap_message_parser.o
-swap_message_parser-y := swap_message_parser_module.o \
-                         message_parser.o \
-                         message_handler.o
+swap_message_parser-y := swap_msg_parser.o \
+                         msg_parser.o \
+                         msg_buf.o \
+                         msg_cmd.o
index 2acb3c2..dd5fc62 100644 (file)
@@ -42,6 +42,11 @@ size_t remained_mb(struct msg_buf *mb)
        return mb->end - mb->ptr;
 }
 
+int is_end_mb(struct msg_buf *mb)
+{
+       return mb->ptr == mb->end;
+}
+
 int get_u32(struct msg_buf *mb, u32 *val)
 {
        if (cmp_mb(mb, sizeof(*val)) < 0)
index 77136f8..91e51c8 100644 (file)
@@ -14,6 +14,7 @@ void uninit_mb(struct msg_buf *mb);
 
 int cmp_mb(struct msg_buf *mb, size_t size);
 size_t remained_mb(struct msg_buf *mb);
+int is_end_mb(struct msg_buf *mb);
 
 int get_u32(struct msg_buf *mb, u32 *val);
 int get_u64(struct msg_buf *mb, u64 *val);
diff --git a/parser/msg_cmd.c b/parser/msg_cmd.c
new file mode 100644 (file)
index 0000000..e6db090
--- /dev/null
@@ -0,0 +1,131 @@
+#include <linux/errno.h>
+#include "msg_parser.h"
+#include "msg_buf.h"
+
+int msg_keep_alive(struct msg_buf *mb)
+{
+       if (!is_end_mb(mb))
+               return -EINVAL;
+
+       return 0;
+}
+
+int msg_start(struct msg_buf *mb)
+{
+       int ret = 0;
+       struct app_info_data *app_info;
+       struct conf_data *conf;
+       struct us_inst_data *us_inst;
+
+       app_info = create_app_info(mb);
+       if (app_info == NULL)
+               return -EINVAL;
+
+       conf = create_conf_data(mb);
+       if (conf == NULL) {
+               ret = -EINVAL;
+               goto free_app_info;
+       }
+
+       us_inst = create_us_inst_data(mb);
+       if (us_inst == NULL) {
+               ret = -EINVAL;
+               goto free_conf;
+       }
+
+       if (!is_end_mb(mb)) {
+               ret = -EINVAL;
+               goto free_us_inst;
+       }
+
+       /* TODO implement the processing */
+
+free_us_inst:
+       destroy_us_inst_data(us_inst);
+
+free_conf:
+       destroy_conf_data(conf);
+
+free_app_info:
+       destroy_app_info(app_info);
+
+       return ret;
+}
+
+int msg_stop(struct msg_buf *mb)
+{
+       if (!is_end_mb(mb))
+               return -EINVAL;
+
+       /* TODO implement the processing */
+
+       return 0;
+}
+
+int msg_config(struct msg_buf *mb)
+{
+       int ret = 0;
+       struct conf_data *conf;
+
+       conf = create_conf_data(mb);
+       if (conf == NULL)
+               return -EINVAL;
+
+       if (!is_end_mb(mb)) {
+               ret = -EINVAL;
+               goto free_conf_data;
+       }
+
+       /* TODO implement the processing */
+
+free_conf_data:
+       destroy_conf_data(conf);
+
+       return ret;
+}
+
+int msg_swap_inst_add(struct msg_buf *mb)
+{
+       int ret = 0;
+       struct us_inst_data *us_inst;
+
+       us_inst = create_us_inst_data(mb);
+       if (us_inst == NULL) {
+               return -EINVAL;
+       }
+
+       if (!is_end_mb(mb)) {
+               ret = -EINVAL;
+               goto free_us_inst;
+       }
+
+       /* TODO implement the processing */
+
+free_us_inst:
+       destroy_us_inst_data(us_inst);
+
+       return ret;
+}
+
+int msg_swap_inst_remove(struct msg_buf *mb)
+{
+       int ret = 0;
+       struct us_inst_data *us_inst;
+
+       us_inst = create_us_inst_data(mb);
+       if (us_inst == NULL) {
+               return -EINVAL;
+       }
+
+       if (!is_end_mb(mb)) {
+               ret = -EINVAL;
+               goto free_us_inst;
+       }
+
+       /* TODO implement the processing */
+
+free_us_inst:
+       destroy_us_inst_data(us_inst);
+
+       return ret;
+}
diff --git a/parser/msg_cmd.h b/parser/msg_cmd.h
new file mode 100644 (file)
index 0000000..9d2afc9
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef _MSG_CMD_H
+#define _MSG_CMD_H
+
+struct msg_buf;
+
+int msg_keep_alive(struct msg_buf *mb);
+int msg_start(struct msg_buf *mb);
+int msg_stop(struct msg_buf *mb);
+int msg_config(struct msg_buf *mb);
+int msg_swap_inst_add(struct msg_buf *mb);
+int msg_swap_inst_remove(struct msg_buf *mb);
+
+#endif /* _MSG_CMD_H */