1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
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
17 // * Neither the name of the copyright holder 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.
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.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
38 #include <anna/core/oam/Module.hpp>
39 #include <anna/core/oam/Handler.hpp>
40 #include <anna/core/oam/CounterScope.hpp>
41 #include <anna/core/functions.hpp>
43 #include <anna/core/tracing/Logger.hpp>
44 #include <anna/core/tracing/TraceWriter.hpp>
45 #include <anna/core/tracing/TraceMethod.hpp>
46 #include <anna/core/functions.hpp>
53 //------------------------------------------------------------------------------
54 //-------------------------------------------------------- Handler::alarmEvent()
55 //------------------------------------------------------------------------------
56 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() {
58 const alarm_data_t *result = module->alarm(type);
60 // #define LOGINFORMATION(a) if (anna::Logger::isActive (anna::Logger::Information) == true) {a;}
61 // Problemas con las comas dentro de la macro:
62 if(anna::Logger::isActive(anna::Logger::Information)) {
64 std::string base = result ? result->Description : module->getDefaultInternalAlarmDescription(type);
65 // replace possible __s__ with <%s>, and __d__ with <%d>
66 base = anna::functions::replace(base, "__s__", "<%s>");
67 base = anna::functions::replace(base, "__d__", "<%d>");
71 if(textPreffix != NULL) {
73 alarm += textSeparator;
78 if(textSuffix != NULL) {
79 alarm += textSeparator;
83 static char cad_aux[1024];
84 vsprintf(cad_aux, alarm.c_str(), argList);
85 std::string trace = module->getClassName();
86 trace += anna::functions::asString(" | Alarm %s event: %s", (activation ? "activation" : "cancellation"), cad_aux);
87 trace += anna::functions::asString(" | Enum type on module: %d", type);
91 trace += anna::functions::asString(" | ActivationId: %d", result->ActivationId);
93 trace += anna::functions::asString(" | CancellationId: %d", result->CancellationId);
95 trace += anna::functions::asString(" | DynamicVariablesCSL: %s", result->DynamicVariablesCSL.c_str());
96 trace += anna::functions::asString(" | ExternalId: %d", result->ExternalId);
99 anna::Logger::information(trace, ANNA_FILE_LOCATION);
106 //------------------------------------------------------------------------------
107 //------------------------------------------------------ Handler::counterEvent()
108 //------------------------------------------------------------------------------
110 const anna::oam::counter_data_t *anna::oam::Handler::counterEvent(const anna::oam::Module *module, const int & type, const int & amount) const throw() {
112 const counter_data_t *result = module->counter(type);
114 std::string base = result ? result->Description : module->getDefaultInternalCounterDescription(type);
116 // Count if registered
118 anna::oam::CounterScope *nc_cs = const_cast <anna::oam::CounterScope*>(module->getActiveCounterScope());
119 nc_cs->increment(result->Offset, amount);
124 std::string trace = module->getClassName();
125 trace += anna::functions::asString(" | Counter event: %s", base.c_str());
126 trace += anna::functions::asString(" | Enum type on module: %d", type);
127 trace += anna::functions::asString(" | Amount increased: %d", amount);
129 if(result) trace += anna::functions::asString(" | Accumulated amount: %llu", module->getActiveCounterScope()->getAccValue(result->Offset));
130 anna::Logger::debug(trace, ANNA_FILE_LOCATION);