ANNA Suite  2020b
Multipurpose development suite for Telco applications
Module.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7 
8 
9 #ifndef anna_core_oam_Module_hpp
10 #define anna_core_oam_Module_hpp
11 
12 
13 // STL
14 #include <string>
15 #include <vector>
16 #include <map>
17 
19 
22 
23 #include <cstdarg>
24 
25 
26 namespace anna {
27 namespace xml {
28 class Node;
29 }
30 namespace oam {
31 class CounterScope;
32 class CounterRecorder;
33 }
34 }
35 
36 
37 namespace anna {
38 
39 namespace oam {
40 
41 class Handler;
42 
135 class Module {
136 
137  Handler a_defaultHandler; // default OAM handler
138  Handler *a_handler; // Handler reference
139  std::string a_name; // module description
140 
141  bool a_counters_enabled; // Enable/Disable registered counters over this module (default is 'false')
142  bool a_alarms_enabled; // Enable/Disable registered alarms over this module (default is 'false')
143 
144  // GENERIC COUNTERS
145  anna::oam::CounterScope* a_active_counter_scope; // Current scope for counters generation
146  typedef std::map <int, anna::oam::CounterScope*> scope_container;
147  scope_container a_scopes; // Module can manage N scope clones (usually, there is only one registered scope: mono-context applications)
148  typedef std::map < int /*type*/, counter_data_t > counter_container;
149  counter_container a_counters;
150 
151  // GENERIC ALARMS
152  typedef std::map < int /*type*/, alarm_data_t > alarm_container;
153  alarm_container a_alarms;
154  void alarmEvent(bool activation, const int & type, va_list argList) const ;
155 
156  // dynamic modifications over alarm text
157  bool a_alarms_preffix_enabled; // Show own module alarm preffix
158  bool a_alarms_suffix_enabled; // Show own module alarm suffix
159  std::string alarmComponentsToText(const std::vector<std::string> & components, const std::string & psL, const std::string & psS, const std::string & psR) const ;
160 
161  // Counters
162  typedef scope_container::iterator scope_iterator;
163  typedef scope_container::const_iterator const_scope_iterator;
164  scope_iterator scope_find(const int &key) { return a_scopes.find(key); }
165  scope_iterator scope_begin() { return a_scopes.begin(); }
166  scope_iterator scope_end() { return a_scopes.end(); }
167  static anna::oam::CounterScope* scope(scope_iterator ii) { return ii->second; }
168  const_scope_iterator scope_begin() const { return a_scopes.begin(); }
169  const_scope_iterator scope_end() const { return a_scopes.end(); }
170  static const anna::oam::CounterScope* scope(const_scope_iterator ii) { return ii->second; }
171  anna::oam::CounterScope *getScope(const int &id) ;
172  typedef counter_container::iterator counter_iterator;
173  typedef counter_container::const_iterator const_counter_iterator;
174 // bool counter_remove(const int &key) ;
175  const_counter_iterator counter_find(const int &key) const { return a_counters.find(key); }
176  const_counter_iterator counter_begin() const { return a_counters.begin(); }
177  const_counter_iterator counter_end() const { return a_counters.end(); }
178  counter_iterator counter_find(const int &key) { return a_counters.find(key); }
179  counter_iterator counter_begin() { return a_counters.begin(); }
180  counter_iterator counter_end() { return a_counters.end(); }
181  CounterRecorder* a_counterRecorder;
182  bool a_counterRecording;
183 
184  class RecordingGuard {
185  public:
186  RecordingGuard(Module*);
187  ~RecordingGuard();
188  private:
189  Module *a_module;
190  };
191 
192  // Alarms
193  typedef alarm_container::iterator alarm_iterator;
194  typedef alarm_container::const_iterator const_alarm_iterator;
195 // bool alarm_remove(const int &key) ;
196  const_alarm_iterator alarm_find(const int &key) const { return a_alarms.find(key); }
197  const_alarm_iterator alarm_begin() const { return a_alarms.begin(); }
198  const_alarm_iterator alarm_end() const { return a_alarms.end(); }
199  alarm_iterator alarm_find(const int &key) { return a_alarms.find(key); }
200  alarm_iterator alarm_begin() { return a_alarms.begin(); }
201  alarm_iterator alarm_end() { return a_alarms.end(); }
202  void getAlarmPreffixSuffixAndZoneSeparator(std::string & preffix, std::string & suffix, char & zS) const ;
203 
204 public:
205 
206  static const int MaxScope = 1000;
212  Module(const std::string &name) :
213  a_handler(&a_defaultHandler),
214  a_name(name),
215  a_counters_enabled(false),
216  a_alarms_enabled(false),
217  a_alarms_preffix_enabled(true),
218  a_alarms_suffix_enabled(true),
219  a_counterRecorder(NULL),
220  a_counterRecording(false) {;}
221 
225  virtual ~Module();
226 
230  int scopes() const { return a_scopes.size(); }
231 
236  void enableCounters(void) ;
237 
242  void disableCounters(void) ;
243 
248  void enableAlarms(void) ;
249 
254  void disableAlarms(void) ;
255 
259  bool countersEnabled() const { return a_counters_enabled; }
260 
264  bool alarmsEnabled() const { return a_alarms_enabled; }
265 
270  void enableAlarmsPreffix(void) ;
271 
276  void enableAlarmsSuffix(void) ;
277 
282  void disableAlarmsPreffix(void) ;
283 
288  void disableAlarmsSuffix(void) ;
289 
299  void setHandler(Handler *handler) { if(handler) a_handler = handler; }
300 
315  void initializeCounterScope(const int & scopeId, const std::string & description = "") noexcept(false);
316 
317 
325  void setActiveCounterScope(const int & scopeId) ;
326 
327 
333  const anna::oam::CounterScope* getActiveCounterScope() const { return a_active_counter_scope; }
334 
344  virtual std::string getDefaultInternalAlarmDescription(const int & type) const ;
345 
355  virtual std::string getDefaultInternalCounterDescription(const int & type) const ;
356 
357 
368  void registerCounter(const int &type, const std::string &description, const int &offset) noexcept(false);
369 
370 
384  void registerAlarm(const int &type, const std::string &description, const int &externalId, const std::string &dynamicVariablesCSL, const int &activationId, const int &cancellationId = -1) noexcept(false);
385 
386 
392  const char *getName() const { return a_name.c_str(); }
393 
394 
400  const counter_data_t *counter(const int &type) const {
401  const_counter_iterator it = counter_find(type);
402  return ((it != counter_end()) ? (&(*it).second) : NULL);
403  }
404 
410  const alarm_data_t *alarm(const int &type) const {
411  const_alarm_iterator it = alarm_find(type);
412  return ((it != alarm_end()) ? (&(*it).second) : NULL);
413  }
414 
415 
423  void count(const int & type, const int & amount = 1) noexcept(false);
424 
425 
434  int resetCounters(const int & scopeId = -1) ;
435 
436 
442  void setCounterRecorder(CounterRecorder* counterRecorder) { a_counterRecorder = counterRecorder; }
443 
450  void recordCounters() noexcept(false);
451 
452 
460  void activateAlarm(int type, ...) const noexcept(false);
461 
462 
470  void cancelAlarm(int type, ...) const noexcept(false);
471 
472 
479  virtual std::string asString(void) const ;
480 
481 
488  virtual anna::xml::Node* asXML(anna::xml::Node* parent) const ;
489 
490 
491 protected:
492 
503  virtual void readAlarmPreffixComponents(std::vector<std::string> & components) const {;}
504 
505 
516  virtual void readAlarmSuffixComponents(std::vector<std::string> & components) const {;}
517 
518 
519  friend class RecordingGuard;
520 };
521 
522 }
523 }
524 
525 #endif
526 
Definition: Handler.hpp:33
Definition: Module.hpp:135
Definition: Node.hpp:56
Definition: defines.hpp:21
Module(const std::string &name)
Definition: Module.hpp:212
int scopes() const
Definition: Module.hpp:230
const counter_data_t * counter(const int &type) const
Definition: Module.hpp:400
bool alarmsEnabled() const
Definition: Module.hpp:264
virtual void readAlarmPreffixComponents(std::vector< std::string > &components) const
Definition: Module.hpp:503
Definition: CounterScope.hpp:32
xml::Node Node
Definition: Node.hpp:21
Definition: CounterRecorder.hpp:28
Definition: defines.hpp:31
Definition: app.hpp:12
virtual void readAlarmSuffixComponents(std::vector< std::string > &components) const
Definition: Module.hpp:516
void setHandler(Handler *handler)
Definition: Module.hpp:299
const char * getName() const
Definition: Module.hpp:392
const anna::oam::CounterScope * getActiveCounterScope() const
Definition: Module.hpp:333
void setCounterRecorder(CounterRecorder *counterRecorder)
Definition: Module.hpp:442
bool countersEnabled() const
Definition: Module.hpp:259
const alarm_data_t * alarm(const int &type) const
Definition: Module.hpp:410