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 CicoSCSystemConfig.cpp
14 * @brief This file implementation of CicoSCSystemConfig class
16 /*========================================================================*/
18 #include "CicoSCSystemConfig.h"
19 #include "CicoSCConf.h"
21 //==========================================================================
22 // private static variable
23 //==========================================================================
24 CicoSCSystemConfig* CicoSCSystemConfig::ms_myInstance = NULL;
26 //--------------------------------------------------------------------------
28 * @brief default constructor
30 //--------------------------------------------------------------------------
31 CicoSCSystemConfig::CicoSCSystemConfig()
33 m_typeTable[""] = ICO_NODETYPE_CENTER;
34 m_typeTable["center"] = ICO_NODETYPE_CENTER;
35 m_typeTable["meter"] = ICO_NODETYPE_METER;
36 m_typeTable["remote"] = ICO_NODETYPE_REMOTE;
37 m_typeTable["passenger"] = ICO_NODETYPE_PASSENGER;
38 m_typeTable["rear"] = ICO_NODETYPE_REAR;
39 m_typeTable["rearleft"] = ICO_NODETYPE_REARLEFT;
40 m_typeTable["rearright"] = ICO_NODETYPE_REARRIGHT;
42 m_displayTypeTable[""] = ICO_DISPLAYTYPE_CENTER;
43 m_displayTypeTable["center"] = ICO_DISPLAYTYPE_CENTER;
44 m_displayTypeTable["meter"] = ICO_DISPLAYTYPE_METER;
45 m_displayTypeTable["remote"] = ICO_DISPLAYTYPE_REMOTE;
46 m_displayTypeTable["passenger"] = ICO_DISPLAYTYPE_PASSENGER;
47 m_displayTypeTable["rear"] = ICO_DISPLAYTYPE_REAR;
48 m_displayTypeTable["rearleft"] = ICO_DISPLAYTYPE_REARLEFT;
49 m_displayTypeTable["rearright"] = ICO_DISPLAYTYPE_REARRIGHT;
52 m_categoryTalbe[""] = ICO_POLICY_ALWAYS;
53 m_categoryTalbe["always"] = ICO_POLICY_ALWAYS;
54 m_categoryTalbe["run"] = ICO_POLICY_RUNNING;
55 m_categoryTalbe["park"] = ICO_POLICY_PARKED;
56 m_categoryTalbe["shift_park"] = ICO_POLICY_SHIFT_PARKING;
57 m_categoryTalbe["shift_back"] = ICO_POLICY_SHIFT_REVERSES;
58 m_categoryTalbe["shift_rev"] = ICO_POLICY_SHIFT_REVERSES;
59 m_categoryTalbe["blinker_left"] = ICO_POLICY_BLINKER_LEFT;
60 m_categoryTalbe["blinker_right"] = ICO_POLICY_BLINKER_RIGHT;
63 m_privilegeTable["almighty"] = ICO_PRIVILEGE_ALMIGHTY;
64 m_privilegeTable["system"] = ICO_PRIVILEGE_SYSTEM;
65 m_privilegeTable["system.audio"] = ICO_PRIVILEGE_SYSTEM_AUDIO;
66 m_privilegeTable["system.visible"] = ICO_PRIVILEGE_SYSTEM_VISIBLE;
67 m_privilegeTable["maker"] = ICO_PRIVILEGE_MAKER;
68 m_privilegeTable["certificate"] = ICO_PRIVILEGE_CERTIFICATE;
69 m_privilegeTable["none"] = ICO_PRIVILEGE_NONE;
70 m_privilegeTable[""] = ICO_PRIVILEGE_NONE;
71 m_resourceConf = NULL;
75 //--------------------------------------------------------------------------
79 //--------------------------------------------------------------------------
80 CicoSCSystemConfig::~CicoSCSystemConfig()
85 //--------------------------------------------------------------------------
87 * @brief Get instance of CicoSCSystemConfig
89 * @return pointer of CicoSCSystemConfig object
91 //--------------------------------------------------------------------------
93 CicoSCSystemConfig::getInstance(void)
95 if (NULL == ms_myInstance) {
96 ms_myInstance = new CicoSCSystemConfig();
101 //--------------------------------------------------------------------------
103 * @brief Get instance of CicoSCSystemConfig
105 * @param [in] confFile config file name
106 * @return 0 on success, other on error
108 //--------------------------------------------------------------------------
110 CicoSCSystemConfig::load(const string & confFile)
113 read_xml(confFile, root);
115 createNodeConfList(root);
116 createDisplayConfList(root);
117 createSoundConfList(root);
118 createPortConf(root);
119 createCategoryConf(root);
120 createAppKindConf(root);
121 createInputDevList(root);
122 createDefaultConf(root);
124 createResourceConf(root);
125 createUserConf(root);
130 //--------------------------------------------------------------------------
136 //--------------------------------------------------------------------------
137 const vector<CicoSCNodeConf*>&
138 CicoSCSystemConfig::getNodeConfList(void) const
140 return m_nodeConfList;
143 //--------------------------------------------------------------------------
149 //--------------------------------------------------------------------------
150 const vector<CicoSCDisplayConf*>&
151 CicoSCSystemConfig::getDisplayConfList(void) const
153 return m_displayConfList;
156 //--------------------------------------------------------------------------
162 //--------------------------------------------------------------------------
163 const vector<CicoSCSoundConf*>&
164 CicoSCSystemConfig::getSoundConfList(void) const
166 return m_soundConfList;
169 //--------------------------------------------------------------------------
175 //--------------------------------------------------------------------------
176 const vector<CicoSCInputDevConf*> &
177 CicoSCSystemConfig::getInputDevConfList(void) const
179 return m_inputDevConfList;
182 //--------------------------------------------------------------------------
188 //--------------------------------------------------------------------------
189 const vector<CicoSCCategoryConf*> &
190 CicoSCSystemConfig::getCategoryConfList(void) const
192 return m_categoryConfList;
195 //--------------------------------------------------------------------------
201 //--------------------------------------------------------------------------
202 const vector<CicoSCAppKindConf*> &
203 CicoSCSystemConfig::getAppKindConfList(void) const
205 return m_appKindConfList;
208 //--------------------------------------------------------------------------
214 //--------------------------------------------------------------------------
216 CicoSCSystemConfig::createNodeConfList(const ptree & root)
219 // if (root.not_found() == root.find("systemconfig")) {
220 // ICO_ERR("nodes element not found");
223 ptree nodes = root.get_child("systemconfig.nodes");
225 BOOST_FOREACH (const ptree::value_type& child, nodes) {
226 if (0 != strcmp(child.first.data(),"node")) {
227 ICO_ERR("unknown element(%s)", child.first.data());
229 optional<int> id = optional<int>(-1);
230 optional<string> name;
231 optional<string> type;
232 optional<string> address;
234 id = child.second.get_optional<int>("<xmlattr>.id");
235 if (false == id.is_initialized()) {
236 ICO_ERR("node.id attr not found");
239 name = child.second.get_optional<string>("<xmlattr>.name");
240 if (false == name.is_initialized()) {
241 ICO_ERR("node.name attr not found");
244 type = child.second.get_optional<string>("type");
245 if (false == type.is_initialized()) {
246 ICO_ERR("node.type element not found");
249 address = child.second.get_optional<string>("ipaddress");
250 if (false == address.is_initialized()) {
251 ICO_ERR("node.address element not found");
255 CicoSCNodeConf* nodeConf = new CicoSCNodeConf;
256 nodeConf->id = id.get();
257 nodeConf->name = name.get();
258 nodeConf->type = m_typeTable[type.get()];
259 nodeConf->address = address.get();
260 m_nodeConfList.push_back(nodeConf);
262 nodeConf->dumpConf();
266 //--------------------------------------------------------------------------
272 //--------------------------------------------------------------------------
274 CicoSCSystemConfig::createDisplayConfList(const ptree & root)
277 // if (root.not_found() != root.find("systemconfi.displays")) {
278 // ICO_ERR("displays element not found");
282 ptree displays = root.get_child("systemconfig.displays");
283 BOOST_FOREACH (const ptree::value_type& child, displays) {
284 optional<int> id = optional<int>(-1);
285 optional<string> name;
286 optional<string> node;
287 optional<int> no = optional<int>(-1);
288 optional<string> wayland;
289 optional<string> type;
290 optional<int> width = optional<int>(-1);
291 optional<int> height = optional<int>(-1);
292 optional<int> inch = optional<int>(-1);
294 id = child.second.get_optional<int>("<xmlattr>.id");
295 if (false == id.is_initialized()) {
296 ICO_ERR("display.id attr not found");
299 name = child.second.get_optional<string>("<xmlattr>.name");
300 if (false == name.is_initialized()) {
301 ICO_ERR("display.name attr not found");
304 node = child.second.get_optional<string>("node");
305 if (false == node.is_initialized()) {
306 ICO_ERR("display.node attr not found");
309 no = child.second.get_optional<int>("no");
310 if (false == no.is_initialized()) {
311 ICO_ERR("display.no element not found");
314 wayland = child.second.get_optional<string>("wayland");
315 if (false == wayland.is_initialized()) {
316 ICO_ERR("display.wayland element not found");
319 type = child.second.get_optional<string>("type");
320 if (false == type.is_initialized()) {
321 ICO_ERR("display.type element not found");
324 width = child.second.get_optional<int>("width");
325 if (false == width.is_initialized()) {
326 ICO_ERR("display.width element not found");
329 height = child.second.get_optional<int>("height");
330 if (false == height.is_initialized()) {
331 ICO_ERR("display.height element not found");
334 inch = child.second.get_optional<int>("inch");
335 if (false == inch.is_initialized()) {
336 ICO_ERR("display.inch element not found");
340 CicoSCDisplayConf* displayConf = new CicoSCDisplayConf();
341 displayConf->id = id.get();
342 displayConf->name = name.get();
343 displayConf->node = getNodeIdbyName(node.get());
344 displayConf->no = no.get();
345 displayConf->type = m_displayTypeTable[type.get()];
346 displayConf->width = width.get();
347 displayConf->height = height.get();
348 displayConf->inch = inch.get();
350 displayConf->dumpConf();
352 createLayerConf(child, displayConf);
353 createDisplayZoneConf(child, displayConf);
355 // TODO overlap to zoneid
356 vector<CicoSCDisplayZoneConf*>::iterator itr;
357 itr = displayConf->zoneConfList.begin();
358 for (; itr != displayConf->zoneConfList.end(); ++itr) {
361 m_displayConfList.push_back(displayConf);
365 //--------------------------------------------------------------------------
371 //--------------------------------------------------------------------------
373 CicoSCSystemConfig::createLayerConf(const ptree::value_type & child,
374 CicoSCDisplayConf* displayConf)
376 ptree layers = child.second.get_child("layers");
377 BOOST_FOREACH (const ptree::value_type& layer, layers) {
378 optional<int> id = optional<int>(-1);
379 optional<string> name;
380 optional<int> type = optional<int>(-1);
381 optional<bool> overlap = optional<bool>(false);
383 id = layer.second.get_optional<int>("<xmlattr>.id");
384 if (false == id.is_initialized()) {
385 ICO_ERR("disply.layer.id attr not found");
388 name = layer.second.get_optional<string>("<xmlattr>.name");
389 if (false == name.is_initialized()) {
390 ICO_ERR("disply.layer.name attr not found");
393 type = layer.second.get_optional<int>("type");
394 if (false == type.is_initialized()) {
395 ICO_ERR("disply.layer.type element not found");
398 overlap = layer.second.get_optional<bool>("menuoverlap");
399 if (false == overlap.is_initialized()) {
400 ICO_ERR("disply.layer.overlap element not found");
404 CicoSCLayerConf* layerConf = new CicoSCLayerConf();
405 layerConf->id = id.get();
406 layerConf->name = name.get();
407 layerConf->type = type.get();
408 layerConf->menuoverlap = overlap.get();
410 displayConf->layerConfList.push_back(layerConf);
412 layerConf->dumpConf();
416 //--------------------------------------------------------------------------
422 //--------------------------------------------------------------------------
424 CicoSCSystemConfig::createDisplayZoneConf(const ptree::value_type & child,
425 CicoSCDisplayConf* displayConf)
427 ptree zones = child.second.get_child("zones");
428 BOOST_FOREACH (const ptree::value_type& zone, zones) {
429 optional<int> id = optional<int>(-1);
430 optional<string> name;
435 optional<string> overlap;
437 id = zone.second.get_optional<int>("<xmlattr>.id");
438 if (false == id.is_initialized()) {
439 ICO_WRN("zone.id.attr not found");
442 name = zone.second.get_optional<string>("<xmlattr>.name");
443 if (false == name.is_initialized()) {
444 ICO_WRN("zone.name.attr not found");
447 x = zone.second.get_optional<string>("geometry.<xmlattr>.x");
448 if (false == x.is_initialized()) {
449 ICO_WRN("zone.geometry.x attr not found");
452 y = zone.second.get_optional<string>("geometry.<xmlattr>.y");
453 if (false == y.is_initialized()) {
454 ICO_WRN("zone.geometry.y attr not found");
457 w = zone.second.get_optional<string>("geometry.<xmlattr>.w");
458 if (false == w.is_initialized()) {
459 ICO_WRN("zone.geometry.w attr not found");
462 h = zone.second.get_optional<string>("geometry.<xmlattr>.h");
463 if (false == h.is_initialized()) {
464 ICO_WRN("zone.geometry.h attr not found");
467 overlap = zone.second.get_optional<string>("overlap");
468 if (false == overlap.is_initialized()) {
469 ICO_WRN("zone.overlap element not found");
470 overlap = optional<string>("");
473 CicoSCDisplayZoneConf* zoneConf = new CicoSCDisplayZoneConf();
474 zoneConf->id = id.get();
475 zoneConf->name = name.get();
476 zoneConf->fullname = displayConf->name + "." + name.get();
477 zoneConf->x = calcGeometryExpr(x.get(), displayConf);
478 zoneConf->y = calcGeometryExpr(y.get(), displayConf);
479 zoneConf->w = calcGeometryExpr(w.get(), displayConf);
480 zoneConf->h = calcGeometryExpr(h.get(), displayConf);
481 zoneConf->overlapStr = overlap.get();
482 displayConf->zoneConfList.push_back(zoneConf);
484 zoneConf->dumpConf();
488 //--------------------------------------------------------------------------
494 //--------------------------------------------------------------------------
496 CicoSCSystemConfig::createSoundConfList(const ptree & root)
499 ptree sounds = root.get_child("systemconfig.sounds");
500 BOOST_FOREACH (const ptree::value_type& child, sounds) {
501 optional<int> id = optional<int>(-1);
502 optional<string> name;
503 optional<int> no = optional<int>(-1);
505 id = child.second.get_optional<int>("<xmlattr>.id");
506 if (false == id.is_initialized()) {
510 name = child.second.get_optional<string>("<xmlattr>.name");
511 if (false == name.is_initialized()) {
515 no = child.second.get_optional<int>("no");
516 if (false == no.is_initialized()) {
520 CicoSCSoundConf* soundConf = new CicoSCSoundConf();
521 soundConf->id = id.get();
522 soundConf->name = name.get();
523 soundConf->no = no.get();
525 soundConf->dumpConf();
527 createSoundZoneConf(child, soundConf);
529 m_soundConfList.push_back(soundConf);
533 //--------------------------------------------------------------------------
539 //--------------------------------------------------------------------------
541 CicoSCSystemConfig::createSoundZoneConf(const ptree::value_type & child,
542 CicoSCSoundConf* soundConf)
547 ptree zones = child.second.get_child("zones");
548 BOOST_FOREACH (const ptree::value_type& zone, zones) {
549 optional<int> id = optional<int>(-1);
550 optional<string> name;
552 id = zone.second.get_optional<int>("<xmlattr>.id");
553 if (false == id.is_initialized()) {
556 name = zone.second.get_optional<string>("<xmlattr>.name");
557 if (false == name.is_initialized()) {
561 CicoSCSoundZoneConf* zoneConf = new CicoSCSoundZoneConf();
562 zoneConf->id = id.get();
563 zoneConf->name = name.get();
564 zoneConf->fullname = soundConf->name + "." + name.get();
565 soundConf->zoneConfList.push_back(zoneConf);
567 zoneConf->dumpConf();
571 //--------------------------------------------------------------------------
577 //--------------------------------------------------------------------------
579 CicoSCSystemConfig::createPortConf(const ptree & root)
582 ptree ports = root.get_child("systemconfig.ports");
583 BOOST_FOREACH (const ptree::value_type& child, ports) {
584 optional<int> id = optional<int>(-1);
585 optional<string> name;
587 id = child.second.get_optional<int>("<xmlattr>.id");
588 if (false == id.is_initialized()) {
591 name = child.second.get_optional<string>("<xmlattr>.name");
592 if (false == name.is_initialized()) {
599 m_sysconPort = atoi(child.second.data().c_str());
602 m_soundPluginPort = atoi(child.second.data().c_str());
610 //--------------------------------------------------------------------------
616 //--------------------------------------------------------------------------
618 CicoSCSystemConfig::createCategoryConf(const ptree & root)
621 ptree categorys = root.get_child("systemconfig.categorys");
622 BOOST_FOREACH (const ptree::value_type& child, categorys) {
623 optional<int> id = optional<int>(-1);
624 optional<string> name;
625 optional<string> type;
626 optional<string> view;
627 optional<string> sound;
628 optional<string> input;
629 optional<int> priority = optional<int>(-1);
630 optional<int> r_ctrl = optional<int>(-1);
632 id = child.second.get_optional<int>("<xmlattr>.id");
633 if (false == id.is_initialized()) {
636 name = child.second.get_optional<string>("<xmlattr>.name");
637 if (false == name.is_initialized()) {
640 type = child.second.get_optional<string>("type");
641 if (false == type.is_initialized()) {
644 view = child.second.get_optional<string>("view");
645 if (false == view.is_initialized()) {
648 sound = child.second.get_optional<string>("sound");
649 if (false == sound.is_initialized()) {
652 input= child.second.get_optional<string>("input");
653 if (false == sound.is_initialized()) {
656 priority = child.second.get_optional<int>("priority");
657 if (false == priority.is_initialized()) {
660 r_ctrl = child.second.get_optional<int>("r_ctrl");
661 if (false == r_ctrl.is_initialized()) {
665 CicoSCCategoryConf* categoryConf = new CicoSCCategoryConf();
666 categoryConf->id = id.get();
667 categoryConf->name = name.get();
668 categoryConf->type = type.get();
669 categoryConf->view = m_categoryTalbe[view.get()];
670 categoryConf->sound = m_categoryTalbe[sound.get()];
671 categoryConf->input = m_categoryTalbe[input.get()];
672 categoryConf->priority = priority.get();
673 categoryConf->rctrl = r_ctrl.get();
674 m_categoryConfList.push_back(categoryConf);
675 categoryConf->dumpConf();
679 //--------------------------------------------------------------------------
685 //--------------------------------------------------------------------------
687 CicoSCSystemConfig::createAppKindConf(const ptree & root)
690 ptree appkinds = root.get_child("systemconfig.appkinds");
691 BOOST_FOREACH (const ptree::value_type& child, appkinds) {
692 optional<int> id = optional<int>(-1);
693 optional<string> name;
694 optional<string> privilege;
695 optional<int> priority = optional<int>(-1);
697 id = child.second.get_optional<int>("<xmlattr>.id");
698 if (false == id.is_initialized()) {
702 name = child.second.get_optional<string>("<xmlattr>.name");
703 if (false == name.is_initialized()) {
707 privilege = child.second.get_optional<string>("privilege");
708 if (false == name.is_initialized()) {
712 priority = child.second.get_optional<int>("priority");
713 if (false == priority.is_initialized()) {
717 CicoSCAppKindConf* appKindConf = new CicoSCAppKindConf();
718 appKindConf->id = id.get();
719 appKindConf->name = name.get();
720 appKindConf->privilege = m_privilegeTable[privilege.get()];
721 appKindConf->priority = priority.get();
722 m_appKindConfList.push_back(appKindConf);
723 appKindConf->dumpConf();
727 //--------------------------------------------------------------------------
733 //--------------------------------------------------------------------------
735 CicoSCSystemConfig::createInputDevList(const ptree & root)
738 ptree inputs = root.get_child("systemconfig.inputs");
739 BOOST_FOREACH (const ptree::value_type& child, inputs) {
740 optional<int> id = optional<int>(-1);
741 optional<string> name;
743 id = child.second.get_optional<int>("<xmlattr>.id");
744 if (false == id.is_initialized()) {
748 name = child.second.get_optional<string>("<xmlattr>.name");
749 if (false == name.is_initialized()) {
753 CicoSCInputDevConf* inputDevConf = new CicoSCInputDevConf();
754 inputDevConf->id = id.get();
755 inputDevConf->name = name.get();
756 inputDevConf->dumpConf();
758 createSwitchList(child, inputDevConf);
759 m_inputDevConfList.push_back(inputDevConf);
763 //--------------------------------------------------------------------------
769 //--------------------------------------------------------------------------
771 CicoSCSystemConfig::createSwitchList(const ptree::value_type & child,
772 CicoSCInputDevConf* inputDevConf)
774 ptree switchs = child.second.get_child("switchs");
775 BOOST_FOREACH (const ptree::value_type& zone, switchs) {
776 optional<int> id = optional<int>(-1);
777 optional<string> name;
778 optional<string> appid;
780 id = zone.second.get_optional<int>("<xmlattr>.id");
781 if (false == id.is_initialized()) {
785 name = zone.second.get_optional<string>("<xmlattr>.name");
786 if (false == name.is_initialized()) {
790 appid = zone.second.get_optional<string>("<xmlattr>.appid");
791 if (false == appid.is_initialized()) {
795 CicoSCSwitchConf* switchConf = new CicoSCSwitchConf();
796 switchConf->id = id.get();
797 switchConf->name = name.get();
798 switchConf->appid = appid.get();
799 switchConf->dumpConf();
800 inputDevConf->switchConfList.push_back(switchConf);
804 //--------------------------------------------------------------------------
810 //--------------------------------------------------------------------------
812 CicoSCSystemConfig::createDefaultConf(const ptree & root)
815 ptree defaults = root.get_child("systemconfig.default");
817 optional<string> node;
818 optional<string> appkind;
819 optional<string> category;
820 optional<string> display;
821 optional<string> layer;
822 optional<string> displayzone;
823 optional<string> sound;
824 optional<string> soundzone;
825 optional<string> inputdev;
826 optional<string> inputsw;
828 node = defaults.get_optional<string>("node");
829 if (false == node.is_initialized()) {
830 ICO_WRN("default.node element not found");
833 appkind = defaults.get_optional<string>("appkind");
834 if (false == appkind.is_initialized()) {
835 ICO_WRN("default.appkind element not found");
838 category = defaults.get_optional<string>("category");
839 if (false == category.is_initialized()) {
840 ICO_WRN("default.category element not found");
843 display = defaults.get_optional<string>("display");
844 if (false == display.is_initialized()) {
845 ICO_WRN("default.display element not found");
848 layer = defaults.get_optional<string>("layer");
849 if (false == layer.is_initialized()) {
850 ICO_WRN("default.layer element not found");
853 displayzone = defaults.get_optional<string>("displayzone");
854 if (false == displayzone.is_initialized()) {
855 ICO_WRN("default.displayzone element not found");
858 sound = defaults.get_optional<string>("sound");
859 if (false == sound.is_initialized()) {
860 ICO_WRN("default.sound element not found");
863 soundzone = defaults.get_optional<string>("soundzone");
864 if (false == soundzone.is_initialized()) {
865 ICO_WRN("default.soundzone element not found");
868 inputdev = defaults.get_optional<string>("inputdev");
869 if (false == inputdev.is_initialized()) {
870 ICO_WRN("default.inputdev element not found");
873 inputsw = defaults.get_optional<string>("inputsw");
874 if (false == inputsw.is_initialized()) {
875 ICO_WRN("default.inputdsw element not found");
878 m_defaultConf = new CicoSCDefaultConf();
880 m_defaultConf->node = getNodeIdbyName(node.get());
881 m_defaultConf->appkind = getAppKindIdbyName(appkind.get());
882 m_defaultConf->category = getCategoryIdbyName(category.get());
883 m_defaultConf->display = getDisplayIdbyName(display.get());
884 m_defaultConf->layer = getLayerIdfbyName(display.get(), layer.get());
885 m_defaultConf->displayzone = getDizplayZoneIdbyName(display.get(),
887 m_defaultConf->sound = getSoundIdbyName(sound.get());
888 m_defaultConf->soundzone = getSoundZoneIdbyName(sound.get(),
890 m_defaultConf->inputdev = getInputDevIdbyName(inputdev.get());
891 m_defaultConf->inputsw = getSwitchIdbyName(inputdev.get(),
895 #define ICO_SYC_TOP_EVN (char*)"SYSCON_TOPDIR"
896 #define ICO_SYC_TOP_DIR (char*)"/usr/apps/org.tizen.ico.system-controller"
897 /* decide top directory in all configurations */
898 char *topdir = getenv(ICO_SYC_TOP_EVN);
899 if (NULL == topdir) {
900 topdir = ICO_SYC_TOP_DIR;
902 m_defaultConf->topdir = topdir;
905 #define ICO_SYC_CONFIG_ENV (char*)"SYSCON_CONFDIR"
906 #define ICO_SYC_CONFIG_DIR (char*)"res/config"
907 /* decide top directory in configuration file's */
908 char *confdir = getenv(ICO_SYC_CONFIG_ENV);
909 if (NULL != confdir) {
910 m_defaultConf->confdir = confdir;
913 m_defaultConf->confdir = m_defaultConf->topdir;
914 m_defaultConf->confdir.append("/");
915 m_defaultConf->confdir.append(ICO_SYC_CONFIG_DIR);
918 m_defaultConf->dumpConf();
921 //--------------------------------------------------------------------------
927 //--------------------------------------------------------------------------
929 CicoSCSystemConfig::createLogConf(const ptree & root)
933 ptree logNode = root.get_child("systemconfig.log");
934 int loglevel = logNode.get<int>("loglevel");
935 bool logflush = logNode.get<bool>("logflush");
937 m_loglevel = loglevel;
938 m_logflush = logflush;
941 //--------------------------------------------------------------------------
943 * @brief resource config class object create
947 //--------------------------------------------------------------------------
948 void getArray(ptree& t, vector<int>& vec);
949 static const char* g_resource_cpu = "systemconfig.resource_cpu_control";
951 CicoSCSystemConfig::createResourceConf(const ptree & root)
953 m_resourceConf = new CicoSCResourceConf;
954 ptree rc = root.get_child(g_resource_cpu);
956 optional<string> opts = rc.get_optional<string>("do_it");
957 if (true == opts.is_initialized()) {
958 string v = opts.get();
959 if (0 == v.compare("yes")) {
963 m_resourceConf->m_bDoIt = b;
969 optional<string> opts2 = rc.get_optional<string>("ctrl_dir_path");
970 if (true == opts2.is_initialized()) {
974 dirnm = "/sys/fs/cgroup/cpu,cpuacct/SCprivate";
976 m_resourceConf->m_cpuCGRPPath = dirnm;
978 opts = rc.get_optional<string>("sampling_wait");
979 if (true == opts.is_initialized()) {
980 m_resourceConf->m_sampling = atoi(opts.get().c_str());
983 opts = rc.get_optional<string>("log");
984 if (true == opts.is_initialized()) {
985 string v = opts.get();
986 if (0 == v.compare("true")) {
987 m_resourceConf->m_bLog = true;
991 opts = rc.get_optional<string>("retry_cnt");
992 if (true == opts.is_initialized()) {
993 m_resourceConf->m_retryCnt = atoi(opts.get().c_str());
996 opts = rc.get_optional<string>("low_limit_value");
997 if (true == opts.is_initialized()) {
998 m_resourceConf->m_lowLimitVal = atoi(opts.get().c_str());
1001 opts = rc.get_optional<string>("high_limit_value");
1002 if (true == opts.is_initialized()) {
1003 m_resourceConf->m_highLimitVal = atoi(opts.get().c_str());
1006 BOOST_FOREACH(ptree::value_type& child, rc) {
1007 optional<int> id = optional<int>(-1);
1008 optional<string> name;
1009 id = child.second.get_optional<int>("<xmlattr>.id");
1010 if (false == id.is_initialized()) {
1013 name = child.second.get_optional<string>("<xmlattr>.name");
1014 if (false == name.is_initialized()) {
1017 ptree pth = child.second.get_child("hight_array");
1018 ptree ptl = child.second.get_child("low_array");
1020 CicoSCCpuResourceGrp* obj = new CicoSCCpuResourceGrp;
1021 obj->m_id = id.get();
1023 obj->m_grpNm = name.get();
1024 getArray(pth, obj->m_hight);
1025 getArray(ptl, obj->m_low);
1026 m_resourceConf->m_cpuCtrl.push_back(obj);
1028 m_resourceConf->dumpConf();
1031 //--------------------------------------------------------------------------
1033 * @brief user config class object create
1037 //--------------------------------------------------------------------------
1038 static const char* g_login_user_conf = "systemconfig.login_user";
1040 CicoSCSystemConfig::createUserConf(const ptree & root)
1042 m_userConf = new CicoSCUserConf;
1043 ptree rc = root.get_child(g_login_user_conf);
1044 optional<string> opts = rc.get_optional<string>("parent_dir");
1045 if (true == opts.is_initialized()) {
1046 string v = opts.get();
1048 m_userConf->m_parent_dir = v;
1051 m_userConf->dumpConf();
1054 //--------------------------------------------------------------------------
1060 //--------------------------------------------------------------------------
1062 CicoSCSystemConfig::calcGeometryExpr(const string & expr,
1063 CicoSCDisplayConf* conf)
1072 for (i = 0; ; i++) {
1073 if (expr[i] == ' ') continue;
1074 if ((expr[i] == 0) || (expr[i] == '+') || (expr[i] == '-') ||
1075 (expr[i] == '*') || (expr[i] == '-') || (expr[i] == '/')) {
1078 if ((strcasecmp(word, "dispw") == 0) ||
1079 (strcasecmp(word, "width") == 0)) {
1082 else if ((strcasecmp(word, "disph") == 0) ||
1083 (strcasecmp(word, "heigh") == 0)) {
1084 wval = conf->height;
1087 wval = strtol(word, (char **)0, 0);
1093 switch (sign % 10) {
1094 case 0: /* assign */
1113 if (expr[i] == '+') sign = 1;
1114 else if (expr[i] == '-') sign = 2;
1115 else if (expr[i] == '*') sign = 3;
1116 else if (expr[i] == '/') sign = 4;
1120 if ((sign > 0) && (expr[i] == '-')) {
1124 if (expr[i] == '+') sign = 1;
1125 else if (expr[i] == '-') sign = 2;
1126 else if (expr[i] == '*') sign = 3;
1127 else if (expr[i] == '/') sign = 4;
1131 if (expr[i] == 0) break;
1134 if (j < ((int)sizeof(word)-1)) {
1135 word[j++] = expr[i];
1142 //--------------------------------------------------------------------------
1148 //--------------------------------------------------------------------------
1149 const CicoSCNodeConf*
1150 CicoSCSystemConfig::findNodeConfbyName(const string & name)
1152 vector<CicoSCNodeConf*>::iterator itr;
1153 itr = m_nodeConfList.begin();
1154 for (; itr != m_nodeConfList.end(); ++itr) {
1155 const CicoSCNodeConf* conf = const_cast<CicoSCNodeConf*>(*itr);
1156 if (name == conf->name) {
1164 //--------------------------------------------------------------------------
1170 //--------------------------------------------------------------------------
1171 const CicoSCDisplayConf*
1172 CicoSCSystemConfig::findDisplayConfbyName(const string & name)
1174 vector<CicoSCDisplayConf*>::iterator itr;
1175 itr = m_displayConfList.begin();
1176 for (; itr != m_displayConfList.end(); ++itr) {
1177 const CicoSCDisplayConf* conf = NULL;
1178 conf = const_cast<CicoSCDisplayConf*>(*itr);
1179 if (name == conf->name) {
1187 //--------------------------------------------------------------------------
1193 //--------------------------------------------------------------------------
1194 const CicoSCLayerConf*
1195 CicoSCSystemConfig::findLayerConfbyName(const string & displayName,
1196 const string & layerName)
1198 const CicoSCDisplayConf* displayConf = NULL;
1199 displayConf = findDisplayConfbyName(displayName);
1200 if (NULL == displayConf) {
1204 vector<CicoSCLayerConf*>::const_iterator itr;
1205 itr = displayConf->layerConfList.begin();
1206 for (; itr != displayConf->layerConfList.end(); ++itr) {
1207 const CicoSCLayerConf* conf = NULL;
1208 conf = const_cast<CicoSCLayerConf*>(*itr);
1209 if (layerName == conf->name) {
1217 //--------------------------------------------------------------------------
1223 //--------------------------------------------------------------------------
1224 const CicoSCDisplayZoneConf*
1225 CicoSCSystemConfig::findDisplayZoneConfbyName(const string & displayName,
1226 const string & zoneName)
1228 ICO_DBG("CicoSCSystemConfig::findDisplayZoneConfbyName Enter"
1229 "(displayName=%s zoneNmae=%s)",
1230 displayName.c_str(), zoneName.c_str());
1232 const CicoSCDisplayConf* displayConf = NULL;
1233 displayConf = findDisplayConfbyName(displayName);
1234 if (NULL == displayConf) {
1235 ICO_DBG("CicoSCSystemConfig::findDisplayZoneConfbyName Leave(NULL)");
1239 vector<CicoSCDisplayZoneConf*>::const_iterator itr;
1240 itr = displayConf->zoneConfList.begin();
1241 for (; itr != displayConf->zoneConfList.end(); ++itr) {
1242 const CicoSCDisplayZoneConf* conf = NULL;
1243 conf = const_cast<CicoSCDisplayZoneConf*>(*itr);
1244 if (zoneName == conf->name) {
1245 ICO_DBG("CicoSCSystemConfig::findDisplayZoneConfbyName Leave"
1251 ICO_DBG("CicoSCSystemConfig::findDisplayZoneConfbyName Leave(NULL)");
1255 //--------------------------------------------------------------------------
1261 //--------------------------------------------------------------------------
1262 const CicoSCSoundConf*
1263 CicoSCSystemConfig::findSoundConfbyName(const string & name)
1265 vector<CicoSCSoundConf*>::iterator itr;
1266 itr = m_soundConfList.begin();
1267 for (; itr != m_soundConfList.end(); ++itr) {
1268 const CicoSCSoundConf* conf = NULL;
1269 conf = const_cast<CicoSCSoundConf*>(*itr);
1270 if (name == conf->name) {
1278 //--------------------------------------------------------------------------
1284 //--------------------------------------------------------------------------
1285 const CicoSCSoundZoneConf*
1286 CicoSCSystemConfig::findSoundZoneConfbyName(const string & soundName,
1287 const string & zoneName)
1289 ICO_DBG("CicoSCSystemConfig::findSoundZoneConfbyName Enter"
1290 "(soundName=%s zoneNmae=%s)",
1291 soundName.c_str(), zoneName.c_str());
1293 const CicoSCSoundConf* soundConf = NULL;
1294 soundConf = findSoundConfbyName(soundName);
1295 if (NULL == soundConf) {
1299 vector<CicoSCSoundZoneConf*>::const_iterator itr;
1300 itr = soundConf->zoneConfList.begin();
1301 for (; itr != soundConf->zoneConfList.end(); ++itr) {
1302 const CicoSCSoundZoneConf* conf = NULL;
1303 conf = const_cast<CicoSCSoundZoneConf*>(*itr);
1304 if (zoneName == conf->name) {
1312 //--------------------------------------------------------------------------
1318 //--------------------------------------------------------------------------
1319 const CicoSCInputDevConf*
1320 CicoSCSystemConfig::findInputDevConfbyName(const string & name)
1322 vector<CicoSCInputDevConf*>::iterator itr;
1323 itr = m_inputDevConfList.begin();
1324 for (; itr != m_inputDevConfList.end(); ++itr) {
1325 const CicoSCInputDevConf* conf = NULL;
1326 conf = const_cast<CicoSCInputDevConf*>(*itr);
1327 if (name == conf->name) {
1335 //--------------------------------------------------------------------------
1341 //--------------------------------------------------------------------------
1342 const CicoSCSwitchConf*
1343 CicoSCSystemConfig::findSwitchConfbyName(const string & inputDevName,
1344 const string & switchName)
1346 const CicoSCInputDevConf* inputDevConf = NULL;
1347 inputDevConf = findInputDevConfbyName(inputDevName);
1348 if (NULL == inputDevConf) {
1349 ICO_WRN("name(%s) input device config not found.",
1350 inputDevName.c_str());
1354 vector<CicoSCSwitchConf*>::const_iterator itr;
1355 itr = inputDevConf->switchConfList.begin();
1356 for (; itr != inputDevConf->switchConfList.end(); ++itr) {
1357 const CicoSCSwitchConf* conf = NULL;
1358 conf = const_cast<CicoSCSwitchConf*>(*itr);
1359 if (switchName == conf->name) {
1364 ICO_WRN("name(%s) switch config not found.", switchName.c_str());
1368 //--------------------------------------------------------------------------
1374 //--------------------------------------------------------------------------
1375 const CicoSCAppKindConf*
1376 CicoSCSystemConfig::findAppKindConfbyName(const string & name)
1378 vector<CicoSCAppKindConf*>::iterator itr;
1379 itr = m_appKindConfList.begin();
1380 for (; itr != m_appKindConfList.end(); ++itr) {
1381 const CicoSCAppKindConf* conf = NULL;
1382 conf = const_cast<CicoSCAppKindConf*>(*itr);
1383 if (name == conf->name) {
1391 //--------------------------------------------------------------------------
1397 //--------------------------------------------------------------------------
1398 const CicoSCSoundZoneConf*
1399 CicoSCSystemConfig::findSoundZoneConfbyId(int id)
1401 vector<CicoSCSoundConf*>::iterator itr;
1402 itr = m_soundConfList.begin();
1403 for (; itr != m_soundConfList.end(); ++itr) {
1404 vector<CicoSCSoundZoneConf*>::iterator itr2;
1405 itr2 = (*itr)->zoneConfList.begin();
1406 for (; itr2 != (*itr)->zoneConfList.end(); ++itr2) {
1407 if (id == (*itr2)->id) {
1416 //--------------------------------------------------------------------------
1422 //--------------------------------------------------------------------------
1423 const CicoSCCategoryConf*
1424 CicoSCSystemConfig::findCategoryConfbyName(const string & name)
1426 vector<CicoSCCategoryConf*>::iterator itr;
1427 itr = m_categoryConfList.begin();
1428 for (; itr != m_categoryConfList.end(); ++itr) {
1429 const CicoSCCategoryConf* conf = NULL;
1430 conf = const_cast<CicoSCCategoryConf*>(*itr);
1431 if (name == conf->name) {
1432 //return const_cast<CicoSCCategoryConf*>(itr->pointer);
1440 //--------------------------------------------------------------------------
1446 //--------------------------------------------------------------------------
1447 const CicoSCCategoryConf*
1448 CicoSCSystemConfig::findCategoryConfbyId(int id)
1450 vector<CicoSCCategoryConf*>::iterator itr;
1451 itr = m_categoryConfList.begin();
1452 for (; itr != m_categoryConfList.end(); ++itr) {
1453 const CicoSCCategoryConf* conf = NULL;
1454 conf = const_cast<CicoSCCategoryConf*>(*itr);
1455 if (id == conf->id) {
1463 //--------------------------------------------------------------------------
1469 //--------------------------------------------------------------------------
1470 const CicoSCAppKindConf *
1471 CicoSCSystemConfig::findAppKindConfbyId(int id)
1473 vector<CicoSCAppKindConf*>::iterator itr;
1474 itr = m_appKindConfList.begin();
1475 for (; itr != m_appKindConfList.end(); ++itr) {
1476 if (id == (*itr)->id) {
1484 //--------------------------------------------------------------------------
1490 //--------------------------------------------------------------------------
1491 const CicoSCDefaultConf*
1492 CicoSCSystemConfig::getDefaultConf(void)
1494 return m_defaultConf;
1497 //--------------------------------------------------------------------------
1503 //--------------------------------------------------------------------------
1505 CicoSCSystemConfig::getNodeIdbyName(const string & name)
1507 const CicoSCNodeConf* conf = NULL;
1508 conf = findNodeConfbyName(name);
1516 //--------------------------------------------------------------------------
1522 //--------------------------------------------------------------------------
1524 CicoSCSystemConfig::getDisplayIdbyName(const string & name)
1526 const CicoSCDisplayConf* conf = NULL;
1527 conf = findDisplayConfbyName(name);
1535 //--------------------------------------------------------------------------
1541 //--------------------------------------------------------------------------
1543 CicoSCSystemConfig::getLayerIdfbyName(const string & displayName,
1544 const string & layerName)
1546 const CicoSCLayerConf* conf = NULL;
1547 conf = findLayerConfbyName(displayName, layerName);
1555 //--------------------------------------------------------------------------
1561 //--------------------------------------------------------------------------
1563 CicoSCSystemConfig::getDizplayZoneIdbyName(const string & displayName,
1564 const string & zoneName)
1566 const CicoSCDisplayZoneConf* conf = NULL;
1567 conf = findDisplayZoneConfbyName(displayName, zoneName);
1575 //--------------------------------------------------------------------------
1581 //--------------------------------------------------------------------------
1583 CicoSCSystemConfig::getDizplayZoneIdbyFullName(const string & zoneFullName)
1585 string::size_type index = zoneFullName.find(".", 0);
1586 if (string::npos == index) {
1589 string displayName = zoneFullName.substr(0, index);
1590 string zoneName = zoneFullName.substr(index+1);
1592 const CicoSCDisplayZoneConf* conf = NULL;
1593 conf = findDisplayZoneConfbyName(displayName, zoneName);
1601 //--------------------------------------------------------------------------
1607 //--------------------------------------------------------------------------
1609 CicoSCSystemConfig::getSoundIdbyName(const string & name)
1611 const CicoSCSoundConf* conf = NULL;
1612 conf = findSoundConfbyName(name);
1620 //--------------------------------------------------------------------------
1626 //--------------------------------------------------------------------------
1628 CicoSCSystemConfig::getSoundZoneIdbyName(const string & soundName,
1629 const string & zoneName)
1631 const CicoSCSoundZoneConf* conf = NULL;
1632 conf = findSoundZoneConfbyName(soundName, zoneName);
1640 //--------------------------------------------------------------------------
1646 //--------------------------------------------------------------------------
1648 CicoSCSystemConfig::getSoundZoneIdbyFullName(const string & zoneFullName)
1650 string::size_type index = zoneFullName.find(".", 0);
1651 if (string::npos == index) {
1654 string soundName = zoneFullName.substr(0, index);
1655 string zoneName = zoneFullName.substr(index+1);
1657 const CicoSCSoundZoneConf* conf = NULL;
1658 conf = findSoundZoneConfbyName(soundName, zoneName);
1666 //--------------------------------------------------------------------------
1672 //--------------------------------------------------------------------------
1674 CicoSCSystemConfig::getInputDevIdbyName(const string & name)
1676 const CicoSCInputDevConf* conf = NULL;
1677 conf = findInputDevConfbyName(name);
1685 //--------------------------------------------------------------------------
1691 //--------------------------------------------------------------------------
1693 CicoSCSystemConfig::getSwitchIdbyName(const string & inputDevName,
1694 const string & switchName)
1696 const CicoSCSwitchConf* conf = NULL;
1697 conf = findSwitchConfbyName(inputDevName, switchName);
1705 //--------------------------------------------------------------------------
1711 //--------------------------------------------------------------------------
1713 CicoSCSystemConfig::getAppKindIdbyName(const string & name)
1715 const CicoSCAppKindConf* conf = NULL;
1716 conf = findAppKindConfbyName(name);
1724 //--------------------------------------------------------------------------
1730 //--------------------------------------------------------------------------
1732 CicoSCSystemConfig::getCategoryIdbyName(const string & name)
1734 const CicoSCCategoryConf* conf = NULL;
1735 conf = findCategoryConfbyName(name);
1743 //--------------------------------------------------------------------------
1745 * @brief get category config object class
1749 //--------------------------------------------------------------------------
1750 const CicoSCCategoryConf*
1751 CicoSCSystemConfig::getCategoryObjbyCaategoryID(int id)
1756 vector<CicoSCCategoryConf*>::iterator itr;
1757 itr = m_categoryConfList.begin();
1758 for (; itr != m_categoryConfList.end(); ++itr) {
1759 const CicoSCCategoryConf* conf = NULL;
1760 conf = const_cast<CicoSCCategoryConf*>(*itr);
1761 if (id == conf->id) {
1762 //return const_cast<CicoSCCategoryConf*>(itr->pointer);
1769 //--------------------------------------------------------------------------
1771 * @brief array xml tree to vector<int>
1775 //--------------------------------------------------------------------------
1776 void getArray(ptree& t, vector<int>& vec)
1779 BOOST_FOREACH (const ptree::value_type& child, t) {
1780 const int value = lexical_cast<int>(child.second.data());
1781 vec.push_back(value);
1784 // vim:set expandtab ts=4 sw=4: