apply updated command json format 68/181468/1
authorJeonghoon Park <jh1979.park@samsung.com>
Thu, 14 Jun 2018 06:21:06 +0000 (15:21 +0900)
committerJeonghoon Park <jh1979.park@samsung.com>
Thu, 14 Jun 2018 06:21:06 +0000 (15:21 +0900)
Change-Id: I368246b8c1756514295f0c9d6afbcbae490cee0e

daemon/src/ttd-parse-cmd.c

index aee0c1f..0234c10 100644 (file)
@@ -21,6 +21,7 @@
 #include "ttd-cmd-type.h"
 #include "ttd-cmd.h"
 
+#define TTD_CMD_KEY_ITEMS "Items"
 #define TTD_CMD_KEY_TYPE "type"
 #define TTD_CMD_KEY_ID "id"
 #define TTD_CMD_KEY_STATE "state"
@@ -236,8 +237,9 @@ static int __parse_cmd_by_type(json_object *obj, ttd_cmd_data *cmd)
 int ttd_parse_json_to_cmd(const char *json_str, GList **cmd_list)
 {
        json_object *root_obj = NULL;
+       json_object *items_obj = NULL;
        ttd_cmd_data *cmd_data = NULL;
-       enum json_type root_type = json_type_null;
+       enum json_type items_type = json_type_null;
        int cmd_length = 0;
        int i;
        GList *list = NULL;
@@ -246,14 +248,20 @@ int ttd_parse_json_to_cmd(const char *json_str, GList **cmd_list)
        retvm_if(!cmd_list, -1, "cmd is NULL");
 
        root_obj = json_tokener_parse(json_str);
-       root_type = json_object_get_type(root_obj);
-       if (root_type != json_type_array) {
-               _E("cmd is not array type");
+       if (!root_obj) {
+               _E("cmd body is not json");
+               return -1;
+       }
+
+       items_obj = json_object_object_get(root_obj, TTD_CMD_KEY_ITEMS);
+       items_type = json_object_get_type(items_obj);
+       if (items_type != json_type_array) {
+               _E("cmd items are not array type");
                json_object_put(root_obj);
                return -1;
        }
 
-       cmd_length = json_object_array_length(root_obj);
+       cmd_length = json_object_array_length(items_obj);
        if (cmd_length <= 0) {
                _E("Nothing in the cmd array");
                json_object_put(root_obj);
@@ -264,26 +272,20 @@ int ttd_parse_json_to_cmd(const char *json_str, GList **cmd_list)
                json_object *obj = NULL;
                json_object *temp_obj = NULL;
                int cmd_type = 0;
-               const char *cmd_state = NULL;
                const char *cmd_id = NULL;
                int ret = 0;
 
-               obj = json_object_array_get_idx(root_obj, i);
+               obj = json_object_array_get_idx(items_obj, i);
                if (!obj) {
                        _E("failed to get object in cmd array");
                        continue;
                }
 
-               temp_obj = json_object_object_get(obj, TTD_CMD_KEY_STATE);
-               cmd_state = json_object_get_string(temp_obj);
-               if (0 != g_strcmp0(TTD_CMD_KEY_STATE_CREATED, cmd_state)) {
-                       _D("passing cmd state - %s", cmd_state);
-                       continue; /* handling only 'created' state */
-               }
-
                temp_obj = json_object_object_get(obj, TTD_CMD_KEY_TYPE);
                cmd_type = json_object_get_int(temp_obj);
+
                cmd_data = ttd_cmd_new();
+               ttd_cmd_set_state(cmd_data, TTD_CMD_STATE_CREATED);
                ttd_cmd_set_type(cmd_data, cmd_type);
                ret = __parse_cmd_by_type(obj, cmd_data);
                if (ret) {