1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
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 //
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>
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>
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 throw() {
30 const alarm_data_t *result = module->alarm(type);
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)) {
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>");
43 if(textPreffix != NULL) {
45 alarm += textSeparator;
50 if(textSuffix != NULL) {
51 alarm += textSeparator;
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);
63 trace += anna::functions::asString(" | ActivationId: %d", result->ActivationId);
65 trace += anna::functions::asString(" | CancellationId: %d", result->CancellationId);
67 trace += anna::functions::asString(" | DynamicVariablesCSL: %s", result->DynamicVariablesCSL.c_str());
68 trace += anna::functions::asString(" | ExternalId: %d", result->ExternalId);
71 anna::Logger::information(trace, ANNA_FILE_LOCATION);
78 //------------------------------------------------------------------------------
79 //------------------------------------------------------ Handler::counterEvent()
80 //------------------------------------------------------------------------------
82 const anna::oam::counter_data_t *anna::oam::Handler::counterEvent(const anna::oam::Module *module, const int & type, const int & amount) const throw() {
84 const counter_data_t *result = module->counter(type);
86 std::string base = result ? result->Description : module->getDefaultInternalCounterDescription(type);
88 // Count if registered
90 anna::oam::CounterScope *nc_cs = const_cast <anna::oam::CounterScope*>(module->getActiveCounterScope());
91 nc_cs->increment(result->Offset, amount);
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);
101 if(result) trace += anna::functions::asString(" | Accumulated amount: %llu", module->getActiveCounterScope()->getAccValue(result->Offset));
102 anna::Logger::debug(trace, ANNA_FILE_LOCATION);