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
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["alway"] = 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;
74 //--------------------------------------------------------------------------
78 //--------------------------------------------------------------------------
79 CicoSCSystemConfig::~CicoSCSystemConfig()
84 //--------------------------------------------------------------------------
86 * @brief Get instance of CicoSCSystemConfig
88 * @return pointer of CicoSCSystemConfig object
90 //--------------------------------------------------------------------------
92 CicoSCSystemConfig::getInstance(void)
94 if (NULL == ms_myInstance) {
95 ms_myInstance = new CicoSCSystemConfig();
100 //--------------------------------------------------------------------------
102 * @brief Get instance of CicoSCSystemConfig
104 * @param [IN] confFile config file name
105 * @return 0 on success, other on error
107 //--------------------------------------------------------------------------
109 CicoSCSystemConfig::load(const string & confFile)
112 read_xml(confFile, root);
114 createNodeConfList(root);
115 createDisplayConfList(root);
116 createSoundConfList(root);
117 createPortConf(root);
118 createCategoryConf(root);
119 createAppKindConf(root);
120 createInputDevList(root);
121 createDefaultConf(root);
123 createResourceConf(root);
128 //--------------------------------------------------------------------------
134 //--------------------------------------------------------------------------
135 const vector<CicoSCDisplayConf*>&
136 CicoSCSystemConfig::getDisplayConfList(void) const
138 return m_displayConfList;
141 //--------------------------------------------------------------------------
147 //--------------------------------------------------------------------------
149 CicoSCSystemConfig::createNodeConfList(const ptree & root)
152 // if (root.not_found() == root.find("systemconfig")) {
153 // ICO_ERR("nodes element not found");
156 ptree nodes = root.get_child("systemconfig.nodes");
158 BOOST_FOREACH (const ptree::value_type& child, nodes) {
159 if (0 != strcmp(child.first.data(),"node")) {
160 ICO_ERR("unknown element(%s)", child.first.data());
162 optional<int> id = optional<int>(-1);
163 optional<string> name;
164 optional<string> type;
165 optional<string> address;
167 id = child.second.get_optional<int>("<xmlattr>.id");
168 if (false == id.is_initialized()) {
169 ICO_ERR("node.id attr not found");
172 name = child.second.get_optional<string>("<xmlattr>.name");
173 if (false == name.is_initialized()) {
174 ICO_ERR("node.name attr not found");
177 type = child.second.get_optional<string>("type");
178 if (false == type.is_initialized()) {
179 ICO_ERR("node.type element not found");
182 address = child.second.get_optional<string>("ipaddress");
183 if (false == address.is_initialized()) {
184 ICO_ERR("node.address element not found");
188 CicoSCNodeConf* nodeConf = new CicoSCNodeConf;
189 nodeConf->id = id.get();
190 nodeConf->name = name.get();
191 nodeConf->type = m_typeTable[type.get()];
192 nodeConf->address = address.get();
193 m_nodeConfList.push_back(nodeConf);
195 nodeConf->dumpConf();
199 //--------------------------------------------------------------------------
205 //--------------------------------------------------------------------------
207 CicoSCSystemConfig::createDisplayConfList(const ptree & root)
210 // if (root.not_found() != root.find("systemconfi.displays")) {
211 // ICO_ERR("displays element not found");
215 ptree displays = root.get_child("systemconfig.displays");
216 BOOST_FOREACH (const ptree::value_type& child, displays) {
217 optional<int> id = optional<int>(-1);
218 optional<string> name;
219 optional<string> node;
220 optional<int> no = optional<int>(-1);
221 optional<string> wayland;
222 optional<string> type;
223 optional<int> width = optional<int>(-1);
224 optional<int> height = optional<int>(-1);
225 optional<int> inch = optional<int>(-1);
227 id = child.second.get_optional<int>("<xmlattr>.id");
228 if (false == id.is_initialized()) {
229 ICO_ERR("display.id attr not found");
232 name = child.second.get_optional<string>("<xmlattr>.name");
233 if (false == name.is_initialized()) {
234 ICO_ERR("display.name attr not found");
237 node = child.second.get_optional<string>("node");
238 if (false == node.is_initialized()) {
239 ICO_ERR("display.node attr not found");
242 no = child.second.get_optional<int>("no");
243 if (false == no.is_initialized()) {
244 ICO_ERR("display.no element not found");
247 wayland = child.second.get_optional<string>("wayland");
248 if (false == wayland.is_initialized()) {
249 ICO_ERR("display.wayland element not found");
252 type = child.second.get_optional<string>("type");
253 if (false == type.is_initialized()) {
254 ICO_ERR("display.type element not found");
257 width = child.second.get_optional<int>("width");
258 if (false == width.is_initialized()) {
259 ICO_ERR("display.width element not found");
262 height = child.second.get_optional<int>("height");
263 if (false == height.is_initialized()) {
264 ICO_ERR("display.height element not found");
267 inch = child.second.get_optional<int>("inch");
268 if (false == inch.is_initialized()) {
269 ICO_ERR("display.inch element not found");
273 CicoSCDisplayConf* displayConf = new CicoSCDisplayConf();
274 displayConf->id = id.get();
275 displayConf->name = name.get();
276 displayConf->node = getNodeIdbyName(node.get());
277 displayConf->no = no.get();
278 displayConf->type = m_displayTypeTable[type.get()];
279 displayConf->width = width.get();
280 displayConf->height = height.get();
281 displayConf->inch = inch.get();
283 displayConf->dumpConf();
285 createLayerConf(child, displayConf);
286 createDisplayZoneConf(child, displayConf);
288 // TODO overlap to zoneid
289 vector<CicoSCDisplayZoneConf*>::iterator itr;
290 itr = displayConf->zoneConfList.begin();
291 for (; itr != displayConf->zoneConfList.end(); ++itr) {
294 m_displayConfList.push_back(displayConf);
298 //--------------------------------------------------------------------------
304 //--------------------------------------------------------------------------
306 CicoSCSystemConfig::createLayerConf(const ptree::value_type & child,
307 CicoSCDisplayConf* displayConf)
309 ptree layers = child.second.get_child("layers");
310 BOOST_FOREACH (const ptree::value_type& layer, layers) {
311 optional<int> id = optional<int>(-1);
312 optional<string> name;
313 optional<int> type = optional<int>(-1);
314 optional<bool> overlap = optional<bool>(false);
316 id = layer.second.get_optional<int>("<xmlattr>.id");
317 if (false == id.is_initialized()) {
318 ICO_ERR("disply.layer.id attr not found");
321 name = layer.second.get_optional<string>("<xmlattr>.name");
322 if (false == name.is_initialized()) {
323 ICO_ERR("disply.layer.name attr not found");
326 type = layer.second.get_optional<int>("type");
327 if (false == type.is_initialized()) {
328 ICO_ERR("disply.layer.type element not found");
331 overlap = layer.second.get_optional<bool>("menuoverlap");
332 if (false == overlap.is_initialized()) {
333 ICO_ERR("disply.layer.overlap element not found");
337 CicoSCLayerConf* layerConf = new CicoSCLayerConf();
338 layerConf->id = id.get();
339 layerConf->name = name.get();
340 layerConf->type = type.get();
341 layerConf->menuoverlap = overlap.get();
343 displayConf->layerConfList.push_back(layerConf);
345 layerConf->dumpConf();
349 //--------------------------------------------------------------------------
355 //--------------------------------------------------------------------------
357 CicoSCSystemConfig::createDisplayZoneConf(const ptree::value_type & child,
358 CicoSCDisplayConf* displayConf)
360 ptree zones = child.second.get_child("zones");
361 BOOST_FOREACH (const ptree::value_type& zone, zones) {
362 optional<int> id = optional<int>(-1);
363 optional<string> name;
368 optional<string> overlap;
370 id = zone.second.get_optional<int>("<xmlattr>.id");
371 if (false == id.is_initialized()) {
372 ICO_WRN("zone.id.attr not found");
375 name = zone.second.get_optional<string>("<xmlattr>.name");
376 if (false == name.is_initialized()) {
377 ICO_WRN("zone.name.attr not found");
380 x = zone.second.get_optional<string>("geometry.<xmlattr>.x");
381 if (false == x.is_initialized()) {
382 ICO_WRN("zone.geometry.x attr not found");
385 y = zone.second.get_optional<string>("geometry.<xmlattr>.y");
386 if (false == y.is_initialized()) {
387 ICO_WRN("zone.geometry.y attr not found");
390 w = zone.second.get_optional<string>("geometry.<xmlattr>.w");
391 if (false == w.is_initialized()) {
392 ICO_WRN("zone.geometry.w attr not found");
395 h = zone.second.get_optional<string>("geometry.<xmlattr>.h");
396 if (false == h.is_initialized()) {
397 ICO_WRN("zone.geometry.h attr not found");
400 overlap = zone.second.get_optional<string>("overlap");
401 if (false == overlap.is_initialized()) {
402 ICO_WRN("zone.overlap element not found");
403 overlap = optional<string>("");
406 CicoSCDisplayZoneConf* zoneConf = new CicoSCDisplayZoneConf();
407 zoneConf->id = id.get();
408 zoneConf->name = name.get();
409 zoneConf->fullname = displayConf->name + "." + name.get();
410 zoneConf->x = calcGeometryExpr(x.get(), displayConf);
411 zoneConf->y = calcGeometryExpr(y.get(), displayConf);
412 zoneConf->w = calcGeometryExpr(w.get(), displayConf);
413 zoneConf->h = calcGeometryExpr(h.get(), displayConf);
414 zoneConf->overlapStr = overlap.get();
415 displayConf->zoneConfList.push_back(zoneConf);
417 zoneConf->dumpConf();
421 //--------------------------------------------------------------------------
427 //--------------------------------------------------------------------------
429 CicoSCSystemConfig::createSoundConfList(const ptree & root)
432 ptree sounds = root.get_child("systemconfig.sounds");
433 BOOST_FOREACH (const ptree::value_type& child, sounds) {
434 optional<int> id = optional<int>(-1);
435 optional<string> name;
436 optional<int> no = optional<int>(-1);
438 id = child.second.get_optional<int>("<xmlattr>.id");
439 if (false == id.is_initialized()) {
443 name = child.second.get_optional<string>("<xmlattr>.name");
444 if (false == name.is_initialized()) {
448 no = child.second.get_optional<int>("no");
449 if (false == no.is_initialized()) {
453 CicoSCSoundConf* soundConf = new CicoSCSoundConf();
454 soundConf->id = id.get();
455 soundConf->name = name.get();
456 soundConf->no = no.get();
458 soundConf->dumpConf();
460 createSoundZoneConf(child, soundConf);
462 m_soundConfList.push_back(soundConf);
466 //--------------------------------------------------------------------------
472 //--------------------------------------------------------------------------
474 CicoSCSystemConfig::createSoundZoneConf(const ptree::value_type & child,
475 CicoSCSoundConf* soundConf)
480 ptree zones = child.second.get_child("zones");
481 BOOST_FOREACH (const ptree::value_type& zone, zones) {
482 optional<int> id = optional<int>(-1);
483 optional<string> name;
485 id = zone.second.get_optional<int>("<xmlattr>.id");
486 if (false == id.is_initialized()) {
489 name = zone.second.get_optional<string>("<xmlattr>.name");
490 if (false == name.is_initialized()) {
494 cout << "id=" << id.get() << endl;
495 cout << "name=" << name.get() << endl;
498 CicoSCSoundZoneConf* zoneConf = new CicoSCSoundZoneConf();
499 zoneConf->id = id.get();
500 zoneConf->name = name.get();
501 soundConf->zoneConfList.push_back(zoneConf);
503 zoneConf->dumpConf();
507 //--------------------------------------------------------------------------
513 //--------------------------------------------------------------------------
515 CicoSCSystemConfig::createPortConf(const ptree & root)
518 ptree ports = root.get_child("systemconfig.ports");
519 BOOST_FOREACH (const ptree::value_type& child, ports) {
520 optional<int> id = optional<int>(-1);
521 optional<string> name;
523 id = child.second.get_optional<int>("<xmlattr>.id");
524 if (false == id.is_initialized()) {
527 name = child.second.get_optional<string>("<xmlattr>.name");
528 if (false == name.is_initialized()) {
533 cout << "id=" << id.get() << endl;
534 cout << "name=" << name.get() << endl;
535 cout << "port=" << child.second.data() << endl;
541 m_sysconPort = atoi(child.second.data().c_str());
544 m_soundPluginPort = atoi(child.second.data().c_str());
552 //--------------------------------------------------------------------------
558 //--------------------------------------------------------------------------
560 CicoSCSystemConfig::createCategoryConf(const ptree & root)
563 ptree categorys = root.get_child("systemconfig.categorys");
564 BOOST_FOREACH (const ptree::value_type& child, categorys) {
565 optional<int> id = optional<int>(-1);
566 optional<string> name;
567 optional<string> type;
568 optional<string> view;
569 optional<string> sound;
570 optional<string> input;
571 optional<int> priority = optional<int>(-1);
572 optional<int> r_ctrl = optional<int>(-1);
574 id = child.second.get_optional<int>("<xmlattr>.id");
575 if (false == id.is_initialized()) {
578 name = child.second.get_optional<string>("<xmlattr>.name");
579 if (false == name.is_initialized()) {
582 type = child.second.get_optional<string>("type");
583 if (false == type.is_initialized()) {
586 view = child.second.get_optional<string>("view");
587 if (false == view.is_initialized()) {
590 sound = child.second.get_optional<string>("sound");
591 if (false == sound.is_initialized()) {
594 input= child.second.get_optional<string>("input");
595 if (false == sound.is_initialized()) {
598 priority = child.second.get_optional<int>("priority");
599 if (false == priority.is_initialized()) {
602 r_ctrl = child.second.get_optional<int>("r_ctrl");
603 if (false == r_ctrl.is_initialized()) {
607 cout << "id=" << id.get() << endl;
608 cout << "name=" << name.get() << endl;
609 cout << "type=" << type.get() << endl;
610 cout << "view=" << view.get() << endl;
611 cout << "sound=" << sound.get() << endl;
612 cout << "input=" << input.get() << endl;
613 cout << "priority=" << priority.get() << endl;
614 cout << "r_ctrl=" << r_ctrl.get() << endl;
617 CicoSCCategoryConf* categoryConf = new CicoSCCategoryConf();
618 categoryConf->id = id.get();
619 categoryConf->name = name.get();
620 categoryConf->type = type.get();
621 categoryConf->view = m_categoryTalbe[view.get()];
622 categoryConf->sound = m_categoryTalbe[sound.get()];
623 categoryConf->input = m_categoryTalbe[input.get()];
624 categoryConf->priority = priority.get();
625 categoryConf->rctrl = r_ctrl.get();
626 m_categoryConfList.push_back(categoryConf);
627 categoryConf->dumpConf();
631 //--------------------------------------------------------------------------
637 //--------------------------------------------------------------------------
639 CicoSCSystemConfig::createAppKindConf(const ptree & root)
642 ptree appkinds = root.get_child("systemconfig.appkinds");
643 BOOST_FOREACH (const ptree::value_type& child, appkinds) {
644 optional<int> id = optional<int>(-1);
645 optional<string> name;
646 optional<string> privilege;
647 optional<int> priority = optional<int>(-1);
649 id = child.second.get_optional<int>("<xmlattr>.id");
650 if (false == id.is_initialized()) {
654 name = child.second.get_optional<string>("<xmlattr>.name");
655 if (false == name.is_initialized()) {
659 privilege = child.second.get_optional<string>("privilege");
660 if (false == name.is_initialized()) {
664 priority = child.second.get_optional<int>("priority");
665 if (false == priority.is_initialized()) {
670 cout << "id=" << id.get() << endl;
671 cout << "name=" << name.get() << endl;
672 cout << "privilege=" << privilege.get() << endl;
673 cout << "priority=" << priority.get() << endl;
676 CicoSCAppKindConf* appKindConf = new CicoSCAppKindConf();
677 appKindConf->id = id.get();
678 appKindConf->name = name.get();
679 appKindConf->privilege = m_privilegeTable[privilege.get()];
680 appKindConf->priority = priority.get();
681 m_appKindConfList.push_back(appKindConf);
682 appKindConf->dumpConf();
686 //--------------------------------------------------------------------------
692 //--------------------------------------------------------------------------
694 CicoSCSystemConfig::createInputDevList(const ptree & root)
697 ptree inputs = root.get_child("systemconfig.inputs");
698 BOOST_FOREACH (const ptree::value_type& child, inputs) {
699 optional<int> id = optional<int>(-1);
700 optional<string> name;
702 id = child.second.get_optional<int>("<xmlattr>.id");
703 if (false == id.is_initialized()) {
707 name = child.second.get_optional<string>("<xmlattr>.name");
708 if (false == name.is_initialized()) {
712 cout << "id=" << id.get() << endl;
713 cout << "name=" << name.get() << endl;
716 CicoSCInputDevConf* inputDevConf = new CicoSCInputDevConf();
717 inputDevConf->id = id.get();
718 inputDevConf->name = name.get();
719 inputDevConf->dumpConf();
721 createSwitchList(child, inputDevConf);
722 m_inputDevConfList.push_back(inputDevConf);
726 //--------------------------------------------------------------------------
732 //--------------------------------------------------------------------------
734 CicoSCSystemConfig::createSwitchList(const ptree::value_type & child,
735 CicoSCInputDevConf* inputDevConf)
737 ptree switchs = child.second.get_child("switchs");
738 BOOST_FOREACH (const ptree::value_type& zone, switchs) {
739 optional<int> id = optional<int>(-1);
740 optional<string> name;
741 optional<string> appid;
743 id = zone.second.get_optional<int>("<xmlattr>.id");
744 if (false == id.is_initialized()) {
748 name = zone.second.get_optional<string>("<xmlattr>.name");
749 if (false == name.is_initialized()) {
753 appid = zone.second.get_optional<string>("<xmlattr>.appid");
754 if (false == appid.is_initialized()) {
759 cout << "id=" << id.get() << endl;
760 cout << "name=" << name.get() << endl;
761 cout << "appid=" << appid.get() << endl;
764 CicoSCSwitchConf* switchConf = new CicoSCSwitchConf();
765 switchConf->id = id.get();
766 switchConf->name = name.get();
767 switchConf->appid = appid.get();
768 switchConf->dumpConf();
769 inputDevConf->switchConfList.push_back(switchConf);
773 //--------------------------------------------------------------------------
779 //--------------------------------------------------------------------------
781 CicoSCSystemConfig::createDefaultConf(const ptree & root)
784 ptree defaults = root.get_child("systemconfig.default");
786 optional<string> node;
787 optional<string> appkind;
788 optional<string> category;
789 optional<string> display;
790 optional<string> layer;
791 optional<string> displayzone;
792 optional<string> sound;
793 optional<string> soundzone;
794 optional<string> inputdev;
795 optional<string> inputsw;
797 node = defaults.get_optional<string>("node");
798 if (false == node.is_initialized()) {
799 ICO_WRN("default.node element not found");
802 appkind = defaults.get_optional<string>("appkind");
803 if (false == appkind.is_initialized()) {
804 ICO_WRN("default.appkind element not found");
807 category = defaults.get_optional<string>("category");
808 if (false == category.is_initialized()) {
809 ICO_WRN("default.category element not found");
812 display = defaults.get_optional<string>("display");
813 if (false == display.is_initialized()) {
814 ICO_WRN("default.display element not found");
817 layer = defaults.get_optional<string>("layer");
818 if (false == layer.is_initialized()) {
819 ICO_WRN("default.layer element not found");
822 displayzone = defaults.get_optional<string>("displayzone");
823 if (false == displayzone.is_initialized()) {
824 ICO_WRN("default.displayzone element not found");
827 sound = defaults.get_optional<string>("sound");
828 if (false == sound.is_initialized()) {
829 ICO_WRN("default.sound element not found");
832 soundzone = defaults.get_optional<string>("soundzone");
833 if (false == soundzone.is_initialized()) {
834 ICO_WRN("default.soundzone element not found");
837 inputdev = defaults.get_optional<string>("inputdev");
838 if (false == inputdev.is_initialized()) {
839 ICO_WRN("default.inputdev element not found");
842 inputsw = defaults.get_optional<string>("inputsw");
843 if (false == inputsw.is_initialized()) {
844 ICO_WRN("default.inputdsw element not found");
848 cout << "node=" << node.get() << endl;
849 cout << "appkind=" << appkind.get() << endl;
850 cout << "category=" << category.get() << endl;
851 cout << "display=" << display.get() << endl;
852 cout << "layer=" << layer.get() << endl;
853 cout << "displayzone=" << displayzone.get() << endl;
854 cout << "sound=" << sound.get() << endl;
855 cout << "soundzone=" << soundzone.get() << endl;
856 cout << "inputdev=" << inputdev.get() << endl;
857 cout << "inputsw=" << inputsw.get() << endl;
860 m_defaultConf = new CicoSCDefaultConf();
862 m_defaultConf->node = getNodeIdbyName(node.get());
863 m_defaultConf->appkind = getAppKindIdbyName(appkind.get());
864 m_defaultConf->category = getCategoryIdbyName(category.get());
865 m_defaultConf->display = getDisplayIdbyName(display.get());
866 m_defaultConf->layer = getLayerIdfbyName(display.get(), layer.get());
867 m_defaultConf->displayzone = getDizplayZoneIdbyName(display.get(),
869 m_defaultConf->sound = getSoundIdbyName(sound.get());
870 m_defaultConf->soundzone = getSoundZoneIdbyName(sound.get(),
872 m_defaultConf->inputdev = getInputDevIdbyName(inputdev.get());
873 m_defaultConf->inputsw = getSwitchIdbyName(inputdev.get(),
877 #define ICO_SYC_TOP_EVN (char*)"SYSCON_TOPDIR"
878 #define ICO_SYC_TOP_DIR (char*)"/usr/apps/org.tizen.ico.system-controller"
879 /* decide top directory in all configurations */
880 char *topdir = getenv(ICO_SYC_TOP_EVN);
881 if (NULL == topdir) {
882 topdir = ICO_SYC_TOP_DIR;
884 m_defaultConf->topdir = topdir;
887 #define ICO_SYC_CONFIG_ENV (char*)"SYSCON_CONFDIR"
888 #define ICO_SYC_CONFIG_DIR (char*)"res/config"
889 /* decide top directory in configuration file's */
890 char *confdir = getenv(ICO_SYC_CONFIG_ENV);
891 if (NULL != confdir) {
892 m_defaultConf->confdir = confdir;
895 m_defaultConf->confdir = m_defaultConf->topdir;
896 m_defaultConf->confdir.append("/");
897 m_defaultConf->confdir.append(ICO_SYC_CONFIG_DIR);
900 m_defaultConf->dumpConf();
903 //--------------------------------------------------------------------------
909 //--------------------------------------------------------------------------
911 CicoSCSystemConfig::createLogConf(const ptree & root)
915 ptree logNode = root.get_child("systemconfig.log");
916 int loglevel = logNode.get<int>("loglevel");
917 bool logflush = logNode.get<bool>("logflush");
920 cout << "loglevel=" << loglevel << endl;
921 cout << "logflush=" << logflush << endl;
924 m_loglevel = loglevel;
925 m_logflush = logflush;
928 //--------------------------------------------------------------------------
930 * @brief resource config class object create
934 //--------------------------------------------------------------------------
935 void getArray(ptree& t, vector<int>& vec);
936 static const char* g_resource_cpu = "systemconfig.resource_cpu_control";
938 CicoSCSystemConfig::createResourceConf(const ptree & root)
940 m_resourceConf = new CicoSCResourceConf;
941 ptree rc = root.get_child(g_resource_cpu);
943 optional<string> opts = rc.get_optional<string>("do_it");
944 if (true == opts.is_initialized()) {
945 string v = opts.get();
946 if (0 == v.compare("yes")) {
950 m_resourceConf->m_bDoIt = b;
956 optional<string> opts2 = rc.get_optional<string>("ctrl_dir_path");
957 if (true == opts2.is_initialized()) {
961 dirnm = "/sys/fs/cgroup/cpu,cpuacct/SCprivate";
963 m_resourceConf->m_cpuCGRPPath = dirnm;
966 optional<int> swt = optional<int>(-1);
967 swt = rc.get_optional<int>("sampling_wait");
968 if (false == swt.is_initialized()) {
969 m_resourceConf->m_sampling = swt.get();
972 opts = rc.get_optional<string>("sampling_wait");
973 if (true == opts.is_initialized()) {
974 m_resourceConf->m_sampling = atoi(opts.get().c_str());
978 opts = rc.get_optional<string>("log");
979 if (true == opts.is_initialized()) {
980 string v = opts.get();
981 if (0 == v.compare("true")) {
982 m_resourceConf->m_bLog = true;
987 BOOST_FOREACH(ptree::value_type& child, rc) {
988 optional<int> id = optional<int>(-1);
989 optional<string> name;
990 id = child.second.get_optional<int>("<xmlattr>.id");
991 if (false == id.is_initialized()) {
994 name = child.second.get_optional<string>("<xmlattr>.name");
995 if (false == name.is_initialized()) {
998 ptree pth = child.second.get_child("hight_array");
999 ptree ptl = child.second.get_child("low_array");
1001 CicoSCCpuResourceGrp* obj = new CicoSCCpuResourceGrp;
1002 obj->m_id = id.get();
1004 obj->m_grpNm = name.get();
1005 getArray(pth, obj->m_hight);
1006 getArray(ptl, obj->m_low);
1007 m_resourceConf->m_cpuCtrl.push_back(obj);
1009 m_resourceConf->dumpConf();
1012 //--------------------------------------------------------------------------
1018 //--------------------------------------------------------------------------
1020 CicoSCSystemConfig::calcGeometryExpr(const string & expr,
1021 CicoSCDisplayConf* conf)
1030 for (i = 0; ; i++) {
1031 if (expr[i] == ' ') continue;
1032 if ((expr[i] == 0) || (expr[i] == '+') || (expr[i] == '-') ||
1033 (expr[i] == '*') || (expr[i] == '-') || (expr[i] == '/')) {
1036 if ((strcasecmp(word, "dispw") == 0) ||
1037 (strcasecmp(word, "width") == 0)) {
1040 else if ((strcasecmp(word, "disph") == 0) ||
1041 (strcasecmp(word, "heigh") == 0)) {
1042 wval = conf->height;
1045 wval = strtol(word, (char **)0, 0);
1051 switch (sign % 10) {
1052 case 0: /* assign */
1071 if (expr[i] == '+') sign = 1;
1072 else if (expr[i] == '-') sign = 2;
1073 else if (expr[i] == '*') sign = 3;
1074 else if (expr[i] == '/') sign = 4;
1078 if ((sign > 0) && (expr[i] == '-')) {
1082 if (expr[i] == '+') sign = 1;
1083 else if (expr[i] == '-') sign = 2;
1084 else if (expr[i] == '*') sign = 3;
1085 else if (expr[i] == '/') sign = 4;
1089 if (expr[i] == 0) break;
1092 if (j < ((int)sizeof(word)-1)) {
1093 word[j++] = expr[i];
1100 //--------------------------------------------------------------------------
1106 //--------------------------------------------------------------------------
1107 const CicoSCNodeConf*
1108 CicoSCSystemConfig::findNodeConfbyName(const string & name)
1110 vector<CicoSCNodeConf*>::iterator itr;
1111 itr = m_nodeConfList.begin();
1112 for (; itr != m_nodeConfList.end(); ++itr) {
1113 const CicoSCNodeConf* conf = const_cast<CicoSCNodeConf*>(*itr);
1114 if (name == conf->name) {
1122 //--------------------------------------------------------------------------
1128 //--------------------------------------------------------------------------
1129 const CicoSCDisplayConf*
1130 CicoSCSystemConfig::findDisplayConfbyName(const string & name)
1132 vector<CicoSCDisplayConf*>::iterator itr;
1133 itr = m_displayConfList.begin();
1134 for (; itr != m_displayConfList.end(); ++itr) {
1135 const CicoSCDisplayConf* conf = NULL;
1136 conf = const_cast<CicoSCDisplayConf*>(*itr);
1137 if (name == conf->name) {
1145 //--------------------------------------------------------------------------
1151 //--------------------------------------------------------------------------
1152 const CicoSCLayerConf*
1153 CicoSCSystemConfig::findLayerConfbyName(const string & displayName,
1154 const string & layerName)
1156 const CicoSCDisplayConf* displayConf = NULL;
1157 displayConf = findDisplayConfbyName(displayName);
1158 if (NULL == displayConf) {
1162 vector<CicoSCLayerConf*>::const_iterator itr;
1163 itr = displayConf->layerConfList.begin();
1164 for (; itr != displayConf->layerConfList.end(); ++itr) {
1165 const CicoSCLayerConf* conf = NULL;
1166 conf = const_cast<CicoSCLayerConf*>(*itr);
1167 if (layerName == conf->name) {
1175 //--------------------------------------------------------------------------
1181 //--------------------------------------------------------------------------
1182 const CicoSCDisplayZoneConf*
1183 CicoSCSystemConfig::findDisplayZoneConfbyName(const string & displayName,
1184 const string & zoneName)
1186 ICO_DBG("CicoSCSystemConfig::findDisplayZoneConfbyName Enter"
1187 "(displayName=%s zoneNmae=%s)",
1188 displayName.c_str(), zoneName.c_str());
1190 const CicoSCDisplayConf* displayConf = NULL;
1191 displayConf = findDisplayConfbyName(displayName);
1192 if (NULL == displayConf) {
1193 ICO_DBG("CicoSCSystemConfig::findDisplayZoneConfbyName Leave(NULL)");
1197 vector<CicoSCDisplayZoneConf*>::const_iterator itr;
1198 itr = displayConf->zoneConfList.begin();
1199 for (; itr != displayConf->zoneConfList.end(); ++itr) {
1200 const CicoSCDisplayZoneConf* conf = NULL;
1201 conf = const_cast<CicoSCDisplayZoneConf*>(*itr);
1202 if (zoneName == conf->name) {
1203 ICO_DBG("CicoSCSystemConfig::findDisplayZoneConfbyName Leave"
1209 ICO_DBG("CicoSCSystemConfig::findDisplayZoneConfbyName Leave(NULL)");
1213 //--------------------------------------------------------------------------
1219 //--------------------------------------------------------------------------
1220 const CicoSCSoundConf*
1221 CicoSCSystemConfig::findSoundConfbyName(const string & name)
1223 vector<CicoSCSoundConf*>::iterator itr;
1224 itr = m_soundConfList.begin();
1225 for (; itr != m_soundConfList.end(); ++itr) {
1226 const CicoSCSoundConf* conf = NULL;
1227 conf = const_cast<CicoSCSoundConf*>(*itr);
1228 if (name == conf->name) {
1236 //--------------------------------------------------------------------------
1242 //--------------------------------------------------------------------------
1243 const CicoSCSoundZoneConf*
1244 CicoSCSystemConfig::findSoundZoneConfbyName(const string & soundName,
1245 const string & zoneName)
1247 const CicoSCSoundConf* soundConf = NULL;
1248 soundConf = findSoundConfbyName(soundName);
1249 if (NULL == soundConf) {
1253 vector<CicoSCSoundZoneConf*>::const_iterator itr;
1254 itr = soundConf->zoneConfList.begin();
1255 for (; itr != soundConf->zoneConfList.end(); ++itr) {
1256 const CicoSCSoundZoneConf* conf = NULL;
1257 conf = const_cast<CicoSCSoundZoneConf*>(*itr);
1258 if (zoneName == conf->name) {
1266 //--------------------------------------------------------------------------
1272 //--------------------------------------------------------------------------
1273 const CicoSCInputDevConf*
1274 CicoSCSystemConfig::findInputDevConfbyName(const string & name)
1276 vector<CicoSCInputDevConf*>::iterator itr;
1277 itr = m_inputDevConfList.begin();
1278 for (; itr != m_inputDevConfList.end(); ++itr) {
1279 const CicoSCInputDevConf* conf = NULL;
1280 conf = const_cast<CicoSCInputDevConf*>(*itr);
1281 if (name == conf->name) {
1289 //--------------------------------------------------------------------------
1295 //--------------------------------------------------------------------------
1296 const CicoSCSwitchConf*
1297 CicoSCSystemConfig::findSwitchConfbyName(const string & inputDevName,
1298 const string & switchName)
1300 const CicoSCInputDevConf* inputDevConf = NULL;
1301 inputDevConf = findInputDevConfbyName(inputDevName);
1302 if (NULL == inputDevConf) {
1303 ICO_WRN("name(%s) input device config not found.",
1304 inputDevName.c_str());
1308 vector<CicoSCSwitchConf*>::const_iterator itr;
1309 itr = inputDevConf->switchConfList.begin();
1310 for (; itr != inputDevConf->switchConfList.end(); ++itr) {
1311 const CicoSCSwitchConf* conf = NULL;
1312 conf = const_cast<CicoSCSwitchConf*>(*itr);
1313 if (switchName == conf->name) {
1318 ICO_WRN("name(%s) switch config not found.", switchName.c_str());
1322 //--------------------------------------------------------------------------
1328 //--------------------------------------------------------------------------
1329 const CicoSCAppKindConf*
1330 CicoSCSystemConfig::findAppKindConfbyName(const string & name)
1332 vector<CicoSCAppKindConf*>::iterator itr;
1333 itr = m_appKindConfList.begin();
1334 for (; itr != m_appKindConfList.end(); ++itr) {
1335 const CicoSCAppKindConf* conf = NULL;
1336 conf = const_cast<CicoSCAppKindConf*>(*itr);
1337 if (name == conf->name) {
1345 //--------------------------------------------------------------------------
1351 //--------------------------------------------------------------------------
1352 const CicoSCCategoryConf*
1353 CicoSCSystemConfig::findCategoryConfbyName(const string & name)
1355 vector<CicoSCCategoryConf*>::iterator itr;
1356 itr = m_categoryConfList.begin();
1357 for (; itr != m_categoryConfList.end(); ++itr) {
1358 const CicoSCCategoryConf* conf = NULL;
1359 conf = const_cast<CicoSCCategoryConf*>(*itr);
1360 if (name == conf->name) {
1361 //return const_cast<CicoSCCategoryConf*>(itr->pointer);
1369 //--------------------------------------------------------------------------
1375 //--------------------------------------------------------------------------
1376 const CicoSCCategoryConf*
1377 CicoSCSystemConfig::findCategoryConfbyId(int id)
1379 vector<CicoSCCategoryConf*>::iterator itr;
1380 itr = m_categoryConfList.begin();
1381 for (; itr != m_categoryConfList.end(); ++itr) {
1382 const CicoSCCategoryConf* conf = NULL;
1383 conf = const_cast<CicoSCCategoryConf*>(*itr);
1384 if (id == conf->id) {
1392 //--------------------------------------------------------------------------
1398 //--------------------------------------------------------------------------
1399 const CicoSCDefaultConf*
1400 CicoSCSystemConfig::getDefaultConf(void)
1402 return m_defaultConf;
1405 //--------------------------------------------------------------------------
1411 //--------------------------------------------------------------------------
1413 CicoSCSystemConfig::getNodeIdbyName(const string & name)
1415 const CicoSCNodeConf* conf = NULL;
1416 conf = findNodeConfbyName(name);
1424 //--------------------------------------------------------------------------
1430 //--------------------------------------------------------------------------
1432 CicoSCSystemConfig::getDisplayIdbyName(const string & name)
1434 const CicoSCDisplayConf* conf = NULL;
1435 conf = findDisplayConfbyName(name);
1443 //--------------------------------------------------------------------------
1449 //--------------------------------------------------------------------------
1451 CicoSCSystemConfig::getLayerIdfbyName(const string & displayName,
1452 const string & layerName)
1454 const CicoSCLayerConf* conf = NULL;
1455 conf = findLayerConfbyName(displayName, layerName);
1463 //--------------------------------------------------------------------------
1469 //--------------------------------------------------------------------------
1471 CicoSCSystemConfig::getDizplayZoneIdbyName(const string & displayName,
1472 const string & zoneName)
1474 const CicoSCDisplayZoneConf* conf = NULL;
1475 conf = findDisplayZoneConfbyName(displayName, zoneName);
1483 //--------------------------------------------------------------------------
1489 //--------------------------------------------------------------------------
1491 CicoSCSystemConfig::getDizplayZoneIdbyFullName(const string & zoneFullName)
1493 string::size_type index = zoneFullName.find(".", 0);
1494 if (string::npos == index) {
1497 string displayName = zoneFullName.substr(0, index);
1498 string zoneName = zoneFullName.substr(index+1);
1500 const CicoSCDisplayZoneConf* conf = NULL;
1501 conf = findDisplayZoneConfbyName(displayName, zoneName);
1509 //--------------------------------------------------------------------------
1515 //--------------------------------------------------------------------------
1517 CicoSCSystemConfig::getSoundIdbyName(const string & name)
1519 const CicoSCSoundConf* conf = NULL;
1520 conf = findSoundConfbyName(name);
1528 //--------------------------------------------------------------------------
1534 //--------------------------------------------------------------------------
1536 CicoSCSystemConfig::getSoundZoneIdbyName(const string & soundName,
1537 const string & zoneName)
1539 const CicoSCSoundZoneConf* conf = NULL;
1540 conf = findSoundZoneConfbyName(soundName, zoneName);
1548 //--------------------------------------------------------------------------
1554 //--------------------------------------------------------------------------
1556 CicoSCSystemConfig::getSoundZoneIdbyFullName(const string & zoneFullName)
1558 string::size_type index = zoneFullName.find(".", 0);
1559 if (string::npos == index) {
1562 string soundName = zoneFullName.substr(0, index);
1563 string zoneName = zoneFullName.substr(index);
1565 const CicoSCSoundZoneConf* conf = NULL;
1566 conf = findSoundZoneConfbyName(soundName, zoneName);
1574 //--------------------------------------------------------------------------
1580 //--------------------------------------------------------------------------
1582 CicoSCSystemConfig::getInputDevIdbyName(const string & name)
1584 const CicoSCInputDevConf* conf = NULL;
1585 conf = findInputDevConfbyName(name);
1593 //--------------------------------------------------------------------------
1599 //--------------------------------------------------------------------------
1601 CicoSCSystemConfig::getSwitchIdbyName(const string & inputDevName,
1602 const string & switchName)
1604 const CicoSCSwitchConf* conf = NULL;
1605 conf = findSwitchConfbyName(inputDevName, switchName);
1613 //--------------------------------------------------------------------------
1619 //--------------------------------------------------------------------------
1621 CicoSCSystemConfig::getAppKindIdbyName(const string & name)
1623 const CicoSCAppKindConf* conf = NULL;
1624 conf = findAppKindConfbyName(name);
1632 //--------------------------------------------------------------------------
1638 //--------------------------------------------------------------------------
1640 CicoSCSystemConfig::getCategoryIdbyName(const string & name)
1642 const CicoSCCategoryConf* conf = NULL;
1643 conf = findCategoryConfbyName(name);
1651 //--------------------------------------------------------------------------
1653 * @brief get category config object class
1657 //--------------------------------------------------------------------------
1658 const CicoSCCategoryConf*
1659 CicoSCSystemConfig::getCategoryObjbyCaategoryID(int id)
1664 vector<CicoSCCategoryConf*>::iterator itr;
1665 itr = m_categoryConfList.begin();
1666 for (; itr != m_categoryConfList.end(); ++itr) {
1667 const CicoSCCategoryConf* conf = NULL;
1668 conf = const_cast<CicoSCCategoryConf*>(*itr);
1669 if (id == conf->id) {
1670 //return const_cast<CicoSCCategoryConf*>(itr->pointer);
1677 //--------------------------------------------------------------------------
1679 * @brief array xml tree to vector<int>
1683 //--------------------------------------------------------------------------
1684 void getArray(ptree& t, vector<int>& vec)
1687 BOOST_FOREACH (const ptree::value_type& child, t) {
1688 const int value = lexical_cast<int>(child.second.data());
1689 vec.push_back(value);
1694 //--------------------------------------------------------------------------
1700 //--------------------------------------------------------------------------
1701 int main(int argc, char* argv[]) {
1703 cerr << "ptree_format filename" << endl;
1707 CicoSCSystemConfig::getInstance()->load(argv[1]);
1712 // vim:set expandtab ts=4 sw=4: