Remove dynamic exceptions
[anna.git] / source / core / oam / Handler.cpp
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 // Local
10 #include <anna/core/oam/Module.hpp>
11 #include <anna/core/oam/Handler.hpp>
12 #include <anna/core/oam/CounterScope.hpp>
13 #include <anna/core/functions.hpp>
14
15 #include <anna/core/tracing/Logger.hpp>
16 #include <anna/core/tracing/TraceWriter.hpp>
17 #include <anna/core/tracing/TraceMethod.hpp>
18 #include <anna/core/functions.hpp>
19
20 // Standard
21 #include <stdarg.h>
22
23
24
25 //------------------------------------------------------------------------------
26 //-------------------------------------------------------- Handler::alarmEvent()
27 //------------------------------------------------------------------------------
28 const anna::oam::alarm_data_t *anna::oam::Handler::alarmEvent(const anna::oam::Module *module, const char *textPreffix, const char *textSuffix, char textSeparator, bool activation, const int & type, va_list argList) const {
29   // OAM alarm
30   const alarm_data_t *result = module->alarm(type);
31
32   // #define LOGINFORMATION(a) if (anna::Logger::isActive (anna::Logger::Information) == true) {a;}
33   // Problemas con las comas dentro de la macro:
34   if(anna::Logger::isActive(anna::Logger::Information)) {
35     // Base text:
36     std::string base = result ? result->Description : module->getDefaultInternalAlarmDescription(type);
37     // replace possible __s__ with <%s>, and __d__ with <%d>
38     base = anna::functions::replace(base, "__s__", "<%s>");
39     base = anna::functions::replace(base, "__d__", "<%d>");
40     // Final text:
41     std::string alarm;
42
43     if(textPreffix != NULL) {
44       alarm = textPreffix;
45       alarm += textSeparator;
46       alarm += base;
47     } else
48       alarm = base;
49
50     if(textSuffix != NULL) {
51       alarm += textSeparator;
52       alarm += textSuffix;
53     }
54
55     static char cad_aux[1024];
56     vsprintf(cad_aux, alarm.c_str(), argList);
57     std::string trace = module->getName();
58     trace += anna::functions::asString(" | Alarm %s event: %s", (activation ? "activation" : "cancellation"), cad_aux);
59     trace += anna::functions::asString(" | Enum type on module: %d", type);
60
61     if(result) {
62       if(activation)
63         trace += anna::functions::asString(" | ActivationId: %d", result->ActivationId);
64       else
65         trace += anna::functions::asString(" | CancellationId: %d", result->CancellationId);
66
67       trace += anna::functions::asString(" | DynamicVariablesCSL: %s", result->DynamicVariablesCSL.c_str());
68       trace += anna::functions::asString(" | ExternalId: %d", result->ExternalId);
69     }
70
71     anna::Logger::information(trace, ANNA_FILE_LOCATION);
72   }
73
74   return result;
75 }
76
77
78 //------------------------------------------------------------------------------
79 //------------------------------------------------------ Handler::counterEvent()
80 //------------------------------------------------------------------------------
81
82 const anna::oam::counter_data_t *anna::oam::Handler::counterEvent(const anna::oam::Module *module, const int & type, const int & amount) const {
83   // OAM counter
84   const counter_data_t *result = module->counter(type);
85   // Base text:
86   std::string base = result ? result->Description : module->getDefaultInternalCounterDescription(type);
87
88   // Count if registered
89   if(result) {
90     anna::oam::CounterScope *nc_cs = const_cast <anna::oam::CounterScope*>(module->getActiveCounterScope());
91     nc_cs->increment(result->Offset, amount);
92   }
93
94   LOGDEBUG
95   (
96     std::string trace = module->getName();
97     trace += anna::functions::asString(" | Counter event: %s", base.c_str());
98     trace += anna::functions::asString(" | Enum type on module: %d", type);
99     trace += anna::functions::asString(" | Amount increased: %d", amount);
100
101     if(result) trace += anna::functions::asString(" | Accumulated amount: %llu", module->getActiveCounterScope()->getAccValue(result->Offset));
102     anna::Logger::debug(trace, ANNA_FILE_LOCATION);
103   );
104
105   return result;
106 }
107
108