2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 //==========================================================================
12 * @file CicoSCMessage.cpp
14 * @brief This file implementation of CicoSCMessage class
16 //==========================================================================
21 #include "CicoSCMessage.h"
24 //==========================================================================
25 // private static variable
26 //==========================================================================
27 unsigned int CicoSCMessage::ms_counter = 0;
29 //--------------------------------------------------------------------------
31 * @brief default constructor
33 //--------------------------------------------------------------------------
34 CicoSCMessage::CicoSCMessage()
36 if (ms_counter == UINT_MAX) {
40 m_generator = json_generator_new();
41 m_root = json_node_new(JSON_NODE_OBJECT);
42 m_rootObj = json_object_new();
43 m_argObj = json_object_new();
44 m_array = json_array_new();
48 //--------------------------------------------------------------------------
52 //--------------------------------------------------------------------------
53 CicoSCMessage::~CicoSCMessage()
55 //ICO_TRA("CicoSCMessage::~CicoSCMessage Enter");
56 json_array_unref(m_array);
57 json_object_unref(m_rootObj);
58 json_object_unref(m_argObj);
59 json_node_free(m_root);
60 g_object_unref(m_generator);
61 //ICO_TRA("CicoSCMessage::~CicoSCMessage Leave");
64 //--------------------------------------------------------------------------
66 * @brief get message id
68 * @return id of message
70 //--------------------------------------------------------------------------
72 CicoSCMessage::getId(void)
77 //--------------------------------------------------------------------------
79 * @brief add root object for char pointer type
81 * @param [in] key key name of object
82 * @param [in] value value of object for char pointer type
84 //--------------------------------------------------------------------------
86 CicoSCMessage::addRootObject(const char * key, const char * value)
88 // ICO_DBG("json_object_set_string_member(%s, %s) called.", key, value);
89 json_object_set_string_member(m_rootObj, key, value);
92 //--------------------------------------------------------------------------
94 * @brief add root object for string type
96 * @param [in] key keyname of object
97 * @param [in] value value of object for string type
99 //--------------------------------------------------------------------------
101 CicoSCMessage::addRootObject(const char * key, const std::string & value)
103 // ICO_DBG("json_object_set_string_member(%s, %s) called.", key, value.c_str());
104 json_object_set_string_member(m_rootObj, key, value.c_str());
107 //--------------------------------------------------------------------------
109 * @brief add root object for integer type
111 * @param [in] key key name of object
112 * @param [in] value value of object for integer type
114 //--------------------------------------------------------------------------
116 CicoSCMessage::addRootObject(const char * key, int value)
118 // ICO_DBG("json_object_set_int_member(%s, %d) called.", key, value);
119 json_object_set_int_member(m_rootObj, key, value);
122 //--------------------------------------------------------------------------
124 * @brief add argument object for char pointer type
126 * @param [in] key key name of object
127 * @param [in] value value of object for char pointer type
129 //--------------------------------------------------------------------------
131 CicoSCMessage::addArgObject(const char * key, const char * value)
133 // ICO_DBG("json_object_set_string_member(%s, %s) called.", key, value);
134 json_object_set_string_member(m_argObj, key, value);
137 //--------------------------------------------------------------------------
139 * @brief add argument object for string type
141 * @param [in] key key name of object
142 * @param [in] value value of object for string type
144 //--------------------------------------------------------------------------
146 CicoSCMessage::addArgObject(const char * key, const std::string & value)
148 // ICO_DBG("json_object_set_string_member(%s, %s) called.", key, value.c_str());
149 json_object_set_string_member(m_argObj, key, value.c_str());
152 //--------------------------------------------------------------------------
154 * @brief add argument object for integer type
156 * @param [in] key key name of object
157 * @param [in] value value of object for integer type
159 //--------------------------------------------------------------------------
161 CicoSCMessage::addArgObject(const char * key, int value)
163 // ICO_DBG("json_object_set_int_member(%s, %d) called.", key, value);
164 json_object_set_int_member(m_argObj, key, value);
167 //--------------------------------------------------------------------------
169 * @brief add argument object for array type
171 * @param [in] key key name of array
173 //--------------------------------------------------------------------------
175 CicoSCMessage::addArgObject(const char * key)
177 // count up reference
178 json_array_ref(m_array);
180 // ICO_DBG("json_object_set_array_member(%s) called.", key);
181 json_object_set_array_member(m_argObj, key, m_array);
184 //--------------------------------------------------------------------------
186 * @brief add array element for char pointer type
188 * @param [in] value value of object for char pointer type
190 //--------------------------------------------------------------------------
192 CicoSCMessage::addElmArray(const char * value)
194 // ICO_DBG("json_array_add_string_element(%s) called.", value);
195 json_array_add_string_element(m_array, value);
198 //--------------------------------------------------------------------------
200 * @brief add array element for string type
202 * @param [in] value value of object for string type
204 //--------------------------------------------------------------------------
206 CicoSCMessage::addElmArray(const std::string & value)
208 // ICO_DBG("json_array_add_string_element(%s) called.", value.c_str());
209 json_array_add_string_element(m_array, value.c_str());
212 //--------------------------------------------------------------------------
214 * @brief get destination handle
216 * @return pointer of destination handle
218 //--------------------------------------------------------------------------
220 CicoSCMessage::getHandle(void)
225 //--------------------------------------------------------------------------
227 * @brief set destination handle
229 * @param [in] handle destination handle
231 //--------------------------------------------------------------------------
233 CicoSCMessage::setHandle(CicoSCUwsHandle* handle)
235 m_uwsHandle = handle;
238 //--------------------------------------------------------------------------
240 * @brief get message data
242 * @return pointer of message data
244 //--------------------------------------------------------------------------
246 CicoSCMessage::getData(void)
248 // count up reference
249 json_object_ref(m_rootObj);
250 json_object_ref(m_argObj);
252 json_object_set_object_member(m_rootObj, "arg", m_argObj);
253 json_node_take_object(m_root, m_rootObj);
254 json_generator_set_root(m_generator, m_root);
256 gchar* data = json_generator_to_data(m_generator, &len);
259 return m_data.c_str();
262 //--------------------------------------------------------------------------
264 * @brief get application id of destination
266 * @return application id
268 //--------------------------------------------------------------------------
270 CicoSCMessage::getSendToAppid(void)
275 //--------------------------------------------------------------------------
277 * @brief set application id of destination
279 //--------------------------------------------------------------------------
281 CicoSCMessage::setSendToAppid(const std::string & appid)
285 // vim:set expandtab ts=4 sw=4: