2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 __json_object_to_str(const char *key, struct json_object *value_obj)
25 char *json_string = NULL;
26 struct json_object *main_object = NULL;
29 retv_if(!value_obj, NULL);
31 main_object = json_object_new_object();
32 json_object_object_add(main_object, key, value_obj);
34 json_string = g_strdup(json_object_to_json_string(main_object));
35 json_object_put(main_object);
42 "commandID" : "ID-xxxx"(string),
43 "type" : 0(int, optional),
44 "commandState" : 0(int),
47 "desc" : "xxxx"(string, optional),
48 "data" : "xxxx"(json object, optional)
52 char *ttd_build_json_create_report(
58 const char *json_data)
60 char *json_report = NULL;
61 struct json_object *main_object = NULL;
62 struct json_object *content_object = NULL;
63 struct json_object *tmp_object = NULL;
66 retv_if(!state, NULL);
68 main_object = json_object_new_object();
70 tmp_object = json_object_new_string(id);
71 json_object_object_add(main_object, "commandId", tmp_object);
73 tmp_object = json_object_new_int(type);
74 json_object_object_add(main_object, "type", tmp_object);
76 tmp_object = json_object_new_int(state);
77 json_object_object_add(main_object, "state", tmp_object);
79 content_object = json_object_new_object();
81 tmp_object = json_object_new_int(code);
82 json_object_object_add(content_object, "code", tmp_object);
84 tmp_object = json_object_new_string(desc);
85 json_object_object_add(content_object, "desc", tmp_object);
88 tmp_object = json_tokener_parse(json_data);
90 _W("failed to parse report data - %s", json_data);
91 tmp_object = json_object_new_string(json_data);
93 json_object_object_add(content_object, "data", tmp_object);
96 json_object_object_add(main_object, "content", content_object);
98 json_report = g_strdup(json_object_to_json_string(main_object));
99 json_object_put(main_object);
104 char *ttd_build_json_str_from_string(const char *key, const char *value)
106 struct json_object *value_obj = NULL;
108 retv_if(!value, NULL);
110 value_obj = json_object_new_string(value);
111 return __json_object_to_str(key, value_obj);
114 char *ttd_build_json_str_from_integer(const char *key, long long int value)
116 struct json_object *value_obj = NULL;
118 value_obj = json_object_new_int(value);
119 return __json_object_to_str(key, value_obj);
122 char *ttd_build_json_str_from_boolean(const char *key, int b_value)
124 struct json_object *value_obj = NULL;
126 value_obj = json_object_new_boolean(b_value);
127 return __json_object_to_str(key, value_obj);
130 char *ttd_build_json_str_from_double(const char *key, double value)
132 struct json_object *value_obj = NULL;
134 value_obj = json_object_new_double(value);
135 return __json_object_to_str(key, value_obj);