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 CicoSCCommand.cpp
14 * @brief This file is implementation of CicoSCCommand class
16 //==========================================================================
21 #include <boost/property_tree/ptree.hpp>
22 #include <boost/property_tree/json_parser.hpp>
23 #include <boost/foreach.hpp>
24 #include <boost/optional.hpp>
26 using namespace boost;
27 using namespace boost::property_tree;
29 #include "CicoSCCommand.h"
31 #include "ico_syc_error.h"
32 #include "ico_syc_msg_cmd_def.h"
33 #include "ico_syc_mrp_resource_private.h"
35 //--------------------------------------------------------------------------
37 * @brief default constructor
39 //--------------------------------------------------------------------------
40 CicoSCCommand::CicoSCCommand()
41 : cmdid(0), appid(""), pid(-1), opt(NULL)
45 //--------------------------------------------------------------------------
49 //--------------------------------------------------------------------------
50 CicoSCCommand::~CicoSCCommand()
55 //--------------------------------------------------------------------------
57 * @brief parse from message, create command
59 * @param [in] message message of interprocess communication
62 * message format(json format)
63 * key name of "appid", "command", "pid" is common command propety.
66 * "appid": (string) application id,
67 * "command": (int) command id,
68 * "pid": (int) process id
74 //--------------------------------------------------------------------------
76 CicoSCCommand::parseMessage(const char *message)
78 // ICO_TRA("CicoSCCommand::parseMessage Enter(%s)", message);
80 stringstream jsonString(message);
82 read_json(jsonString, root);
84 this->appid = getStrValue(root, MSG_PRMKEY_APPID);
85 this->cmdid = getIntValue(root, MSG_PRMKEY_CMD);
86 this->pid = getIntValue(root, MSG_PRMKEY_PID);
88 switch ((this->cmdid & MSG_CMD_TYPE_MASK)) {
89 case MSG_CMD_TYPE_WINCTRL:
90 parseWinCtrlOpt(root);
92 case MSG_CMD_TYPE_INPUTCTRL:
93 parseInputDevCtrlOpt(root);
95 case MSG_CMD_TYPE_USERMGR:
96 parseUserMgrOpt(root);
98 case MSG_CMD_TYPE_RESOURCEMGR:
99 parseResCtrlOpt(root);
101 case MSG_CMD_TYPE_INPUTDEVSETTING:
102 parseInputDevSettingOpt(root);
108 // dump log command variables
111 catch (std::exception const& e)
113 ICO_WRN("catch exception %s", e.what());
114 // ICO_TRA("CicoSCCommand::parseMessage Leave(EINVAL)");
115 return ICO_SYC_EINVAL;
118 // ICO_TRA("CicoSCCommand::parseMessage Leave(EOK)");
122 //--------------------------------------------------------------------------
124 * @brief dump log this class member variables
126 //--------------------------------------------------------------------------
128 CicoSCCommand::dump(void)
130 ICO_INF("Command: cmdid=0x%08x appid=%s pid=%d", cmdid, appid.c_str(), pid);
131 if (NULL != this->opt) {
136 //--------------------------------------------------------------------------
138 * @brief get integer value by key
140 * @param [in] root root object of json object
141 * @param [in] key Key to get the value
143 * @return integer value on success, INT_MAX on error
145 //--------------------------------------------------------------------------
147 CicoSCCommand::getIntValue(const ptree & root, const char* key)
151 intValue = root.get<int>(key);
153 catch (std::exception const& e)
155 //ICO_WRN("catch exception %s", e.what());
161 //--------------------------------------------------------------------------
163 * @brief get string value by key
165 * @param [in] root root object of json object
166 * @param [in] key Key to get the value
168 * @return string value on success, empty string on error
170 //--------------------------------------------------------------------------
172 CicoSCCommand::getStrValue(const ptree & root, const char* key)
174 string strValue = "";
176 strValue = root.get<string>(key);
178 catch (std::exception const& e)
180 //ICO_WRN("catch exception %s", e.what());
184 if (strValue == "null") {
191 //--------------------------------------------------------------------------
193 * @brief query whether the object exists
195 * @param [in] root root object of json object
196 * @param [in] key Key to get the value
198 * @return true on exist, false on not exist
200 //--------------------------------------------------------------------------
202 CicoSCCommand::isExistObject(const ptree & root, const char *key)
205 (void)root.get_child(key);
207 catch (std::exception const& e)
209 //ICO_WRN("catch exception %s", e.what());
216 //--------------------------------------------------------------------------
218 * @brief parse from message, create window control options
220 * @param [in] root root object of json object
223 * message format of window control(json format)
227 * "surface": (int) surface id
228 * "layer": (int) layer id
229 * "node": (int) node id
230 * "zone": (string) display zone name
231 * "anim_name": (string) animation name
232 * "anim_time": (int) animation time
233 * "pos_x": (int) window x position
234 * "pos_y": (int) window y position
235 * "width": (int) window width
236 * "height": (int) window height
237 * "raise": (int) raise flag
238 * "visible": (int) visible flag
239 * "active": (int) active flag
240 * "stride": (int) stride
241 * "format": (int) format
242 * "framerate": (int) frame rate
247 //--------------------------------------------------------------------------
249 CicoSCCommand::parseWinCtrlOpt(const ptree & root)
251 CicoSCCmdWinCtrlOpt* options = new CicoSCCmdWinCtrlOpt();
254 options->surfaceid = getIntValue(root, "arg.surface");
255 options->layerid = getIntValue(root, "arg.layer");
256 options->nodeid = getIntValue(root, "arg.node");
257 options->zone = getStrValue(root, "arg.zone");
258 options->animation = getStrValue(root, "arg.anim_name");
259 options->animationType = getIntValue(root, "arg.anim_type");
260 if (-1 == options->animationType) {
261 options->animationType = 0xff;
263 options->animationTime = getIntValue(root, "arg.anim_time");
264 if (-1 == options->animationTime) {
265 options->animationTime = 0;
267 options->x = getIntValue(root, "arg.pos_x");
268 options->y = getIntValue(root, "arg.pos_y");
269 options->width = getIntValue(root, "arg.width");
270 options->height = getIntValue(root, "arg.height");
271 options->raise = getIntValue(root, "arg.raise");
272 options->visible = getIntValue(root, "arg.visible");
273 options->active = getIntValue(root, "arg.active");
274 options->stride = getIntValue(root, "arg.stride");
275 options->format = getIntValue(root, "arg.format");
276 options->framerate = getIntValue(root, "arg.framerate");
279 //--------------------------------------------------------------------------
281 * @brief parse from message, create input device control options
283 * @param [in] root root object of json object
286 * message format of input device control(json format)
290 * "device": (string) device name
291 * "input_num": (int) input number
292 * "surface": (int) surface id
293 * "deviceno": (int) device number
294 * "alloc_type": (int) allocation type
295 * "keycode": (int) key code
296 * "ev_type": (int) event type
297 * "ev_time": (int) event time
298 * "ev_code": (int) event cord
299 * "ev_value": (int) event value
304 //--------------------------------------------------------------------------
306 CicoSCCommand::parseInputDevCtrlOpt(const ptree & root)
308 CicoSCCmdInputDevCtrlOpt* options = new CicoSCCmdInputDevCtrlOpt();
311 options->device = getStrValue(root, "arg.device");
312 options->input = getIntValue(root, "arg.input_num");
313 options->surfaceid = getIntValue(root, "arg.surface");
314 options->deviceno = getIntValue(root, "arg.deviceno");
315 options->fix = getIntValue(root, "arg.alloc_type");
316 options->keycode = getIntValue(root, "arg.keycode");
317 options->evtype = getIntValue(root, "arg.ev_type");
318 options->evtime = getIntValue(root, "arg.ev_time");
319 options->evcode = getIntValue(root, "arg.ev_code");
320 options->evvalue = getIntValue(root, "arg.ev_value");
323 //--------------------------------------------------------------------------
325 * @brief parse from message, create user manager options
327 * @param [in] root root object of json object
330 * message format of user manager options(json format)
334 * "user": (string) user name
335 * "password": (string) user password
336 * "lastinof": (string) information of application last state
341 //--------------------------------------------------------------------------
343 CicoSCCommand::parseUserMgrOpt(const ptree & root)
345 CicoSCCmdUserMgrOpt* options = new CicoSCCmdUserMgrOpt();
348 options->user = getStrValue(root, "arg.user");
349 options->pass = getStrValue(root, "arg.password");
350 options->lastinfo = getStrValue(root, "arg.lastinfo");
353 //--------------------------------------------------------------------------
355 * @brief parse from message, create resource manage options
357 * @param [in] root root object of json object
360 * message format of resource manage options(json format)
365 * "zone": (string) window zone,
366 * "name": (string) window's surface name,
367 * "id": (string) window id
378 * "zone": (string) sound zone,
379 * "name": (string) sound's stream name,
380 * "id": (string) sound id,
381 * "adjust": (int) sound adjust type
384 * "name": (string) input device name,
385 * "event": (int) input event id
387 * "type": (int) basic or interruption
392 //--------------------------------------------------------------------------
394 CicoSCCommand::parseResCtrlOpt(const ptree & root)
396 CicoSCCmdResCtrlOpt* options = new CicoSCCmdResCtrlOpt();
399 if (true == isExistObject(root, "res.window")) {
400 options->dispres = true;
401 options->dispzone = getStrValue(root, "res.window.zone");
402 options->winname = getStrValue(root, "res.window.name");
403 options->surfaceid = getIntValue(root, "res.window.id");
405 options->ECU = getStrValue(root, "res.window.ECU");
406 if (true == options->ECU.empty()) {
409 options->display = getStrValue(root, "res.window.display");
410 if (true == options->display.empty()) {
413 options->layer = getStrValue(root, "res.window.layer");
414 if (true == options->layer.empty()) {
417 options->layout = getStrValue(root, "res.window.layout");
418 if (true == options->layout.empty()) {
421 options->area = getStrValue(root, "res.window.area");
422 if (true == options->area.empty()) {
425 options->dispatchApp= getStrValue(root, "res.window.dispatchApp");
426 options->role = getStrValue(root, "res.window.role");
427 options->resourceID= getIntValue(root, "res.window.resourceId");
428 options->dispresEx = bEx;
431 if (true == isExistObject(root, "res.sound")) {
432 options->soundres = true;
433 options->soundzone = getStrValue(root, "res.sound.zone");
434 options->soundname = getStrValue(root, "res.sound.name");
435 options->soundid = getIntValue(root, "res.sound.id");
436 options->adjust = getIntValue(root, "res.sound.adjust");
439 if (true == isExistObject(root, "res.input")) {
440 options->inputres = true;
441 options->device = getStrValue(root, "res.input.name");
442 options->input = getIntValue(root, "res.input.event");
445 options->type = getIntValue(root, "res.type");
448 //--------------------------------------------------------------------------
450 * @brief parse from message, create input device setting options
452 * @param [in] root root object of json object
455 * message format of input device setting(json format)
459 * "winname": (string) window name,
460 * "pos_x": (int) position x,
461 * "pos_y": (int) position y,
462 * "width": (int) width,
463 * "height": (int) height,
464 * "hotspot_x": (int) cursor hotspot x,
465 * "hotspot_y": (int) cursor hotspot y,
466 * "cursor_x": (int) cursor position x,
467 * "cursor_y": (int) cursor position y,
468 * "cursor_width": (int) cursor width,
469 * "cursor_height":(int) cursor height,
470 * "attr": (int) attribute
475 //--------------------------------------------------------------------------
477 CicoSCCommand::parseInputDevSettingOpt(const ptree & root)
479 CicoSCCmdInputDevSettingOpt* options = new CicoSCCmdInputDevSettingOpt();
482 if (true == isExistObject(root, "region")) {
483 options->winname = getStrValue(root, "region.winname");
484 options->x = getIntValue(root, "region.pos_x");
485 options->y = getIntValue(root, "region.pos_y");
486 options->width = getIntValue(root, "region.width");
487 options->height = getIntValue(root, "region.height");
488 options->hotspot_x = getIntValue(root, "region.hotspot_x");
489 options->hotspot_y = getIntValue(root, "region.hotspot_y");
490 options->cursor_x = getIntValue(root, "region.cursor_x");
491 options->cursor_y = getIntValue(root, "region.cursor_y");
492 options->cursor_width = getIntValue(root, "region.cursor_width");
493 options->cursor_height = getIntValue(root, "region.cursor_height");
494 options->attr = getIntValue(root, "region.attr");
497 // vim:set expandtab ts=4 sw=4: