Updated license
[anna.git] / source / core / oam / Configuration.cpp
1 // ANNA - Anna is Not Nothingness Anymore
2 //
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
4 //
5 // https://bitbucket.org/testillano/anna
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 //     * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //     * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 //     * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Authors: eduardo.ramos.testillano@gmail.com
34 //          cisco.tierra@gmail.com
35
36
37 #include <anna/core/tracing/Logger.hpp>
38 #include <anna/core/tracing/TraceWriter.hpp>
39 #include <anna/core/functions.hpp>
40 #include <anna/xml/Node.hpp>
41
42 // Local
43 #include <anna/core/oam/Configuration.hpp>
44
45
46 //******************************************************************************
47 //---------------------------------------------------------------- Configuration
48 //******************************************************************************
49
50
51 //------------------------------------------------------------------------------
52 //----------------------------------------------- Configuration::Configuration()
53 //------------------------------------------------------------------------------
54 anna::oam::Configuration::Configuration() {
55   //a_alarm_text_preffix_components.clear();
56   //a_alarm_text_suffix_components.clear();
57   a_alarms_preffix_enabled = true;
58   a_alarms_suffix_enabled = true;
59   // Alarm Text Delimiters:
60   a_alarm_text_delimiter_zS = ' ';
61   a_alarm_text_delimiter_psL = "[ ";
62   a_alarm_text_delimiter_psS = " | ";
63   a_alarm_text_delimiter_psR = " ]";
64 };
65
66
67 //------------------------------------------------------------------------------
68 //-------------------------------------- Configuration::setAlarmTextDelimiters()
69 //------------------------------------------------------------------------------
70 void anna::oam::Configuration::setAlarmTextDelimiters(const char zS, const std::string & psL, const std::string & psS, const std::string & psR) throw() {
71   a_alarm_text_delimiter_zS = zS;
72   a_alarm_text_delimiter_psL = psL;
73   a_alarm_text_delimiter_psS = psS;
74   a_alarm_text_delimiter_psR = psR;
75 }
76
77
78 //------------------------------------------------------------------------------
79 //-------------------------------------- Configuration::getAlarmTextDelimiters()
80 //------------------------------------------------------------------------------
81 void anna::oam::Configuration::getAlarmTextDelimiters(char & zS, std::string & psL, std::string & psS, std::string & psR) const throw() {
82   zS = a_alarm_text_delimiter_zS;
83   psL = a_alarm_text_delimiter_psL;
84   psS = a_alarm_text_delimiter_psS;
85   psR = a_alarm_text_delimiter_psR;
86 }
87
88
89 //------------------------------------------------------------------------------
90 //----------------------------------------- Configuration::enableAlarmsPreffix()
91 //------------------------------------------------------------------------------
92 void anna::oam::Configuration::enableAlarmsPreffix(void) throw() {
93   a_alarms_preffix_enabled = true;
94   LOGDEBUG(anna::Logger::debug("Alarm preffix global components SHOWN", ANNA_FILE_LOCATION));
95 }
96
97
98 //------------------------------------------------------------------------------
99 //------------------------------------------ Configuration::enableAlarmsSuffix()
100 //------------------------------------------------------------------------------
101 void anna::oam::Configuration::enableAlarmsSuffix(void) throw() {
102   a_alarms_suffix_enabled = true;
103   LOGDEBUG(anna::Logger::debug("Alarm suffix global components SHOWN", ANNA_FILE_LOCATION));
104 }
105
106
107 //------------------------------------------------------------------------------
108 //---------------------------------------- Configuration::disableAlarmsPreffix()
109 //------------------------------------------------------------------------------
110 void anna::oam::Configuration::disableAlarmsPreffix(void) throw() {
111   a_alarms_preffix_enabled = false;
112   LOGDEBUG(anna::Logger::debug("Alarm preffix global components HIDDEN", ANNA_FILE_LOCATION));
113 }
114
115
116 //------------------------------------------------------------------------------
117 //----------------------------------------- Configuration::disableAlarmsSuffix()
118 //------------------------------------------------------------------------------
119 void anna::oam::Configuration::disableAlarmsSuffix(void) throw() {
120   a_alarms_suffix_enabled = false;
121   LOGDEBUG(anna::Logger::debug("Alarm suffix global components HIDDEN", ANNA_FILE_LOCATION));
122 }
123
124
125 //------------------------------------------------------------------------------
126 //------------------------------------------------------- Configuration::asXML()
127 //------------------------------------------------------------------------------
128 anna::xml::Node* anna::oam::Configuration::asXML(anna::xml::Node* parent) const throw() {
129   anna::xml::Node* result = parent->createChild("anna.oam.Configuration");
130   std::vector<std::string>::const_iterator it, it_min, it_max;
131   result->createAttribute("AlarmsPreffix", a_alarms_preffix_enabled ? "Enabled" : "Disabled");
132   it_min = a_alarm_text_preffix_components.begin();
133   it_max = a_alarm_text_preffix_components.end();
134
135   if(a_alarm_text_preffix_components.size() != 0) {
136     anna::xml::Node* pc = result->createChild("AlarmsPreffixComponents");
137
138     for(it = it_min; it != it_max; it++)
139       pc->createAttribute(anna::functions::asString("Text%d", (int)(it - it_min) + 1).c_str(), *it);
140   }
141
142   result->createAttribute("AlarmsSuffix", a_alarms_suffix_enabled ? "Enabled" : "Disabled");
143   it_min = a_alarm_text_suffix_components.begin();
144   it_max = a_alarm_text_suffix_components.end();
145
146   if(a_alarm_text_suffix_components.size() != 0) {
147     anna::xml::Node* pc = result->createChild("AlarmsSuffixComponents");
148
149     for(it = it_min; it != it_max; it++)
150       pc->createAttribute(anna::functions::asString("Text%d", (int)(it - it_min) + 1).c_str(), *it);
151   }
152
153   char zoneDelimiterCharacter[2];
154   sprintf(zoneDelimiterCharacter, "%c", a_alarm_text_delimiter_zS);
155   result->createAttribute("AlarmTextZoneDelimiter", zoneDelimiterCharacter);
156   result->createAttribute("AlarmPreffixSuffixLeftDelimiter", a_alarm_text_delimiter_psL);
157   result->createAttribute("AlarmPreffixSuffixSeparatorDelimiter", a_alarm_text_delimiter_psS);
158   result->createAttribute("AlarmPreffixSuffixRightDelimiter", a_alarm_text_delimiter_psR);
159   return result;
160 }
161