Updated license
[anna.git] / include / anna / core / oam / Configuration.hpp
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 #ifndef anna_core_oam_Configuration_hpp
38 #define anna_core_oam_Configuration_hpp
39
40
41 #include <anna/core/Singleton.hpp>
42 #include <anna/core/RuntimeException.hpp>
43
44 // STL
45 #include <string>
46 #include <vector>
47
48 namespace anna {
49 namespace xml {
50 class Node;
51 }
52 }
53
54
55 namespace anna {
56
57 namespace oam {
58
59
60 /**
61 * Class used for general OAM configuration
62 */
63 class Configuration : public anna::Singleton <Configuration> {
64
65   // Post-configuration for the final alarm text used for context data over each module (functionality, logic data, etc.):
66   typedef std::vector<std::string> string_vector_t;
67   string_vector_t a_alarm_text_preffix_components;
68   string_vector_t a_alarm_text_suffix_components;
69   bool a_alarms_preffix_enabled;   // Show general alarm preffix
70   bool a_alarms_suffix_enabled;    // Show general alarm suffix
71
72
73   // Delimiters (zone separator for preffix/text/suffix, and left/right/separator for preffix/suffix):
74   char a_alarm_text_delimiter_zS;
75   std::string a_alarm_text_delimiter_psL;
76   std::string a_alarm_text_delimiter_psS;
77   std::string a_alarm_text_delimiter_psR;
78
79   const string_vector_t * getAlarmPreffixComponents() const throw() { return (a_alarms_preffix_enabled ? &a_alarm_text_preffix_components : NULL); }
80   const string_vector_t * getAlarmSuffixComponents() const throw() { return (a_alarms_suffix_enabled ? &a_alarm_text_suffix_components : NULL); }
81
82   void getAlarmTextDelimiters(char & zS, std::string & psL, std::string & psS, std::string & psR) const throw();
83
84
85   Configuration(); // private constructor
86
87   friend class anna::Singleton <Configuration>;
88   friend class Module;
89
90 public:
91
92   /**
93   * Final detailed alarm text is composed by three parts: preffix, database text and suffix.
94   * To separate these zones, we configure the zone separator (space character by default).
95   * Within preffix/suffix we can configure left, right and separator delimiters (by default,
96   * we use square brackets and pipe):
97   *
98   * <pre>
99   *      ------- preffix -------        ------- suffix -------
100   *     [ pc1 | pc2 | ... | pcM ] text [ sc1 | sc2 | ... | scN ]
101   *
102   *     Then, pc[i]/sc[i] are the preffix/suffix components.
103   *     Usually, 'pc1' is the application facility name.
104   *     Dashes could be used instead of pipe '|' with nice result.
105   *
106   * </pre>
107   *
108   * @param zS Zone separator delimiter
109   * @param psL Preffix/Suffix left delimiter
110   * @param psS Preffix/Suffix separator delimiter
111   * @param psR Preffix/Suffix right delimiter
112   */
113   void setAlarmTextDelimiters(const char zS, const std::string & psL, const std::string & psS, const std::string & psR) throw();
114
115
116   /**
117   * Optional preffix definition to modify dinamically the alarm texts at context.
118   * This affects to all the management modules. It is usually used on application
119   * start tipically with the facility name, although this information is already
120   * shown at the EG component but easier to identify through that detailed text.
121   * Note that preffix components string should be multilanguage texts.
122   *
123   * @param components Preffix components for alarm text
124   */
125   void setAlarmPreffixComponents(const std::vector<std::string> & components) throw() { a_alarm_text_preffix_components = components; }
126
127
128   /**
129   * Optional suffix definition to modify dinamically the alarm texts at context.
130   * This affects to all the management modules. It is usually used by application
131   * libraries tipically with the oam module name. However this information could be
132   * only useful for developers, and usually would be set by each oam module.
133   * Note that suffix components string should be multilanguage texts.
134   *
135   * @param components Suffix components for alarm text
136   */
137   void setAlarmSuffixComponents(const std::vector<std::string> & components) throw() { a_alarm_text_suffix_components = components; }
138
139
140   /**
141   * Show general alarm preffix (enabled by default at constructor).
142   */
143   void enableAlarmsPreffix() throw();
144
145
146   /**
147   * Show general alarm suffix (enabled by default at constructor).
148   */
149   void enableAlarmsSuffix() throw();
150
151
152   /**
153   * Hide general alarm preffix (enabled by default at constructor).
154   */
155   void disableAlarmsPreffix() throw();
156
157
158   /**
159   * Hide general alarm suffix (enabled by default at constructor).
160   */
161   void disableAlarmsSuffix() throw();
162
163   /**
164   * Class XML representation
165   *
166   * @return XML with class content
167   */
168   anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
169 };
170
171 }
172 }
173
174 #endif
175