Now record period must be managed separately (establish a MyTimer invoking module record())
Integer64 and Unsigned64 disappear, using S64 and U64.
/*
* Para comprobar que el modo de codificar los bytes son igual que en la versión de Java
*/
- char buffer [sizeof (Integer64)];
+ char buffer [sizeof (S64)];
short ss = 23456;
comm::functions::codeShort (buffer, ss);
xx = comm::functions::decodeInteger (buffer);
cout << anna::functions::asString ("Integer2: %d - 0x%x\n\n", xx, xx);
-// Integer64 ll = 31604938272LL;
- Integer64 ll = 98765432101234LL;
+// S64 ll = 31604938272LL;
+ S64 ll = 98765432101234LL;
comm::functions::codeInteger64 (buffer, ll);
dataBlock.clear ();
dataBlock.append (buffer, sizeof (ll));
cout << "Float O: " << ff2 << " (" << anna::functions::asHexString (ii) << ") " << endl;
dd = -123123123.3232;
- Integer64 ii64;
+ S64 ii64;
anna_memcpy (&ii64, &dd, sizeof (dd));
comm::functions::codeInteger64 (buffer, ii64);
cout << "Double I: " << dd << " (" << anna::functions::asHexString (ii64) << ") " << endl;
// Authors: eduardo.ramos.testillano@gmail.com
// cisco.tierra@gmail.com
-
-/*
- Establece un manejador externo para controlar el teclado, recoge los parametros de la operacion
- por este y envia la peticion al servidor.
-*/
#include <iostream>
#include <fstream>
namespace comm {
class Entity;
class Response;
+class LocalServer;
}
}
}
anna::diameter::comm::Message G_commMsgSent2c, G_commMsgSent2e, G_commMsgFwd2c, G_commMsgFwd2e;
anna::diameter::comm::Message G_commMsg;
anna::diameter::codec::Message G_codecMsg, G_codecAnsMsg;
-anna::Recycler<anna::diameter::comm::Message> G_commMessages; // create en el forward de requets sin answer programada
-// realease en el forward de answers
+anna::Recycler<anna::diameter::comm::Message> G_commMessages; // create on requests forwards without programmed answer / release in answers forward
// Auxiliary resources for answers programming
};
+/*
class MyCounterRecorder : public anna::oam::CounterRecorder {
// pure virtual definitions:
void close() throw() {;}
std::string asString() const throw() { return "Physical dump not implemented: see memory accumulations writting context (kill -10 <pid>)"; }
};
-
+*/
class Launcher : public anna::comm::Application {
bool a_splitLog, a_detailedLog;
anna::time::Date a_start_time;
anna::timex::Engine* a_timeEngine;
- MyCounterRecorder *a_counterRecorder;
+ //MyCounterRecorder *a_counterRecorder;
std::string a_cerPathfile;
std::string a_dwrPathfile;
a_splitLog = false;
a_detailedLog = false;
a_timeEngine = NULL;
- a_counterRecorder = NULL;
+ //a_counterRecorder = NULL;
a_entity = NULL;
a_diameterLocalServer = NULL;
a_cerPathfile = "cer.xml";
// workMode = anna::comm::Communicator::WorkMode::Clone;
a_communicator = new MyCommunicator(workMode);
a_timeEngine = new anna::timex::Engine((anna::Millisecond)300000, (anna::Millisecond)150);
- a_counterRecorder = new MyCounterRecorder();
+ //a_counterRecorder = new MyCounterRecorder();
}
void Launcher::run()
oamDiameterCodec.registerCounter(anna::diameter::codec::OamModule::Counter::LevelValidation__FailedRuleForCardinalityMoreThanNeeded, "", 17 /*2017*/);
oamDiameterCodec.registerCounter(anna::diameter::codec::OamModule::Counter::LevelValidation__FailedGenericAvpRuleForCardinalityFoundDisregardedItem, "", 18 /*2018*/);
oamDiameterCodec.registerCounter(anna::diameter::codec::OamModule::Counter::LevelValidation__FoundDisregardedItemsAndGenericAVPWasNotSpecified, "", 19 /*2019*/);
- anna::oam::CounterManager& cm = anna::oam::CounterManager::instantiate();
- cm.setEngine(a_timeEngine);
- cm.setRecordPeriod(Millisecond(300000));
- cm.setCounterRecorder(static_cast<anna::oam::CounterRecorder*>(a_counterRecorder));
+ //anna::oam::CounterManager& cm = anna::oam::CounterManager::instantiate();
+ //cm.setEngine(a_timeEngine);
+ //cm.setRecordPeriod(Millisecond(300000));
+ ////cm.setCounterRecorder(static_cast<anna::oam::CounterRecorder*>(a_counterRecorder)); ... will be NULL
// Checking command line parameters
if (cl.exists("sessionBasedModelsClientSocketSelection")) {
--- /dev/null
+Import ('env')
+
+# Process #################################################################
+pName = "example_diameter_tme"
+pPath = pName.replace("_", "/") + "/"
+
+# Anna modules ############################################################
+pwd = str(Dir ('.').abspath);
+anna_libpaths = []
+anna_libs = []
+modules = [ 'core', 'io', 'xml', 'time', 'diameter' ];
+for module in modules:
+ anna_libs.append ("anna_" + module)
+ #module = module.replace("_", ".")
+ anna_libpaths.append (pwd.replace (pPath, ("source/" + module + "/")))
+
+anna_rlibs = list(anna_libs)
+anna_rlibs.reverse()
+
+# Libraries ###############################################################
+# To avoid other libraries accumulation (boost testing, i.e.):
+localEnv = env.Clone()
+
+anna_library = { 'LIBS' : anna_rlibs }
+localEnv.MergeFlags (anna_library)
+
+system_library = { 'LIBS' : [ 'xml2', 'rt' ] }
+localEnv.MergeFlags (system_library)
+
+localEnv.Append(LIBPATH = anna_libpaths)
+
+# Linking #################################################################
+result = localEnv.Program (pName, Glob ('*.cpp'))
+
+
+Return ('result')
--- /dev/null
+Import ('env')
+
+variant = env ['VARIANT']
+
+result = SConscript ('SConscript', exports='env', variant_dir='%s' % variant, duplicate=0)
+
+Return ('result')
+
--- /dev/null
+// Standard
+#include <iostream>
+#include <fstream>
+
+// STL
+#include <string>
+
+#include <anna/core/core.hpp>
+#include <anna/xml/xml.hpp>
+#include <anna/diameter/stack/Engine.hpp>
+#include <anna/diameter/codec/Engine.hpp>
+#include <anna/time/functions.hpp>
+#include <anna/time/Date.hpp>
+
+
+void _exit(const std::string & msg) {
+ std::cout << std::endl << msg << std::endl;
+ exit(-1);
+}
+
+
+std::string exec_cmd(const char* cmd) {
+ FILE* pipe = popen(cmd, "r");
+ if (!pipe) return "";
+ char buffer[128];
+ std::string result = "";
+ while(!feof(pipe)) {
+ if(fgets(buffer, 128, pipe) != NULL)
+ result += buffer;
+ }
+ pclose(pipe);
+ return result;
+}
+
+int main(int argc, char** argv) {
+ Logger::setLevel(Logger::Debug);
+ Logger::initialize("tme", new TraceWriter("file.trace", 2048000));
+ anna::time::functions::initialize(); // before application instantiation (it have a anna::time object)
+ anna::time::functions::setControlPoint(); // start control point (application lifetime)
+ anna::diameter::stack::Engine & engine = anna::diameter::stack::Engine::instantiate();
+ anna::diameter::stack::Dictionary *dictionary;
+ std::string exec = argv[0];
+ std::string param = argv[1] ? argv[1] : "";
+
+ if (param == "") {
+ std::string msg = "Use: "; msg += exec; msg += " <xml directory>";
+ msg += "\n xml directory: contains the xml files needed, which are:";
+ msg += "\n";
+ msg += "\n avps_ietf.xml";
+ msg += "\n avps_etsi.xml";
+ msg += "\n avps_tgpp.xml";
+ msg += "\n avps_tme.xml";
+ msg += "\n commands_dccaOCS-CS_HuaweiNGIN_de-es.xml";
+ msg += "\n";
+ msg += "\n For example: "; msg += exec; msg += " ";
+ std::string projectRoot = exec_cmd("git rev-parse --show-toplevel");
+ if (projectRoot != "") {
+ //projectRoot.resize(projectRoot.size()-1);
+ projectRoot.erase(projectRoot.size()-1);
+ msg += projectRoot;
+ msg += "/";
+ }
+
+ msg += "source/diameter/stack/setups";
+
+ _exit(msg);
+ }
+
+ try {
+ dictionary = engine.createDictionary(0 /* general unique stack id */);
+ dictionary->allowUpdates();
+ dictionary->load(param + "/avps_ietf.xml");
+ dictionary->load(param + "/avps_etsi.xml");
+ dictionary->load(param + "/avps_tgpp.xml");
+ dictionary->load(param + "/avps_tme.xml");
+ dictionary->load(param + "/commands_dccaOCS-CS_HuaweiNGIN_de-es.xml");
+
+ // Trace:
+ LOGINFORMATION(Logger::information(engine.asString(), ANNA_FILE_LOCATION));
+ LOGDEBUG(Logger::debug(dictionary->asString(), ANNA_FILE_LOCATION));
+
+ } catch (anna::RuntimeException &ex) {
+ ex.trace();
+ std::cout << ex.getText() << std::endl;
+ }
+
+
+ anna::diameter::codec::Message ccr;
+ ccr.setId("Credit-Control-Request");
+
+ //LOGDEBUG(Logger::debug(ccr.asXMLString(), ANNA_FILE_LOCATION));
+/*
+
+ tmeAvp *sid = (tmeAvp*)ccr.addAvp("Session-Id");
+ tmeAvp *ohst = (tmeAvp*)ccr.addAvp("Origin-Host");
+ tmeAvp *orlm = (tmeAvp*)ccr.addAvp("Origin-Realm");
+
+ sid->getUTF8String()->setValue("grump.example.com:33041;23432;893;0AF3B81");
+ ohst->getDiameterIdentity()->setValue("c0-10-70-238-74-w5p1vepg1.vepc.ericsson.se");
+ orlm->getDiameterIdentity()->setValue("vepc.ericsson.se");
+*/
+/*
+ <command name="Credit-Control-Request" code="272" type="Request">
+ <avprule id="Session-Id" type="Fixed"/>
+ <avprule id="Origin-Host" type="Mandatory"/>
+ <avprule id="Origin-Realm" type="Mandatory"/>
+ <avprule id="Destination-Realm" type="Mandatory"/>
+ <avprule id="Auth-Application-Id" type="Mandatory"/>
+ <avprule id="Service-Context-Id" type="Mandatory"/>
+ <avprule id="CC-Request-Type" type="Mandatory"/>
+ <avprule id="CC-Request-Number" type="Mandatory"/>
+ <avprule id="Event-Timestamp" type="Optional"/>
+ <avprule id="Subscription-Id" type="Mandatory" qual="*"/>
+ <avprule id="Termination-Cause" type="Optional"/>
+ <avprule id="Requested-Service-Unit" type="Optional"/>
+ <avprule id="Requested-Action" type="Optional"/>
+ <avprule id="Used-Service-Unit" type="Optional"/>
+ <avprule id="CC-Correlation-Id" type="Optional"/>
+ <avprule id="User-Equipment-Info" type="Optional"/>
+ <avprule id="Proxy-Info" type="Optional" qual="*"/>
+ <avprule id="Route-Record" type="Optional" qual="*"/>
+ <avprule id="Service-Information" type="Optional"/>
+ <avprule id="AVP" type="Optional" qual="*"/>
+ </command>
+
+ <command name="Credit-Control-Answer" code="272" type="Answer">
+ <avprule id="Session-Id" type="Fixed"/>
+ <avprule id="Result-Code" type="Mandatory"/>
+ <avprule id="CS-Result-Code" type="Optional"/>
+ <avprule id="CS-Dialogue-Handling" type="Optional"/>
+ <avprule id="Origin-Host" type="Mandatory"/>
+ <avprule id="Origin-Realm" type="Mandatory"/>
+ <avprule id="Auth-Application-Id" type="Mandatory"/>
+ <avprule id="CC-Request-Type" type="Mandatory"/>
+ <avprule id="CC-Request-Number" type="Mandatory"/>
+ <avprule id="Granted-Service-Unit" type="Optional"/>
+ <avprule id="Cost-Information" type="Optional"/>
+ <avprule id="Low-Balance-Indication" type="Optional"/>
+ <avprule id="Remaining-Balance" type="Optional"/>
+ <avprule id="Credit-Control-Failure-Handling" type="Optional"/>
+ <avprule id="CC-Correlation-Id" type="Optional"/>
+ <avprule id="Redirect-Host" type="Optional" qual="*"/>
+ <avprule id="Redirect-Host-Usage" type="Optional"/>
+ <avprule id="Redirect-Max-Cache-Time" type="Optional"/>
+ <avprule id="Proxy-Info" type="Optional" qual="*"/>
+ <avprule id="Route-Record" type="Optional" qual="*"/>
+ <avprule id="Failed-AVP" type="Optional" qual="*"/>
+ <avprule id="Service-Information" type="Optional"/>
+ <avprule id="AVP" type="Optional" qual="*"/>
+ </command>
+*/
+
+ _exit("Open 'file.trace' in order to see the stacks loaded");
+}
+
--- /dev/null
+../../../source/diameter/stack/setups
\ No newline at end of file
using namespace test;
http4comm::Context::Context (timex::Engine& timeController, const Millisecond& timeout) :
- timex::Context<Integer64> ("http4comm", timeController, timeout)
+ timex::Context<S64> ("http4comm", timeController, timeout)
{;}
-void http4comm::Context::create (const Integer64 id, comm::ClientSocket& clientSocket)
+void http4comm::Context::create (const S64 id, comm::ClientSocket& clientSocket)
throw (RuntimeException)
{
- http4comm::Transaction* transaction = static_cast <http4comm::Transaction*> (timex::Context <Integer64>::open (id, 0));
+ http4comm::Transaction* transaction = static_cast <http4comm::Transaction*> (timex::Context <S64>::open (id, 0));
transaction->setClientSocket (&clientSocket);
/**
* Interpreta el identificador de la transación como cadena
*/
-string http4comm::Context::identifierAsString (const Integer64& id) const
+string http4comm::Context::identifierAsString (const S64& id) const
throw ()
{
return functions::asHexString (id);
/*
* Interpreta el contexto de la transación para obtener su Id de aplicación.
*/
-const Integer64& http4comm::Context::contextAsIdentifier (const void* cc) const
+const S64& http4comm::Context::contextAsIdentifier (const void* cc) const
throw ()
{
- return *((Integer64*) cc);
+ return *((S64*) cc);
}
using namespace anna;
-class Context : public timex::Context <Integer64> {
+class Context : public timex::Context <S64> {
public:
Context (timex::Engine&, const Millisecond& timeout);
- void create (const Integer64 id, comm::ClientSocket&) throw (RuntimeException);
+ void create (const S64 id, comm::ClientSocket&) throw (RuntimeException);
void destroy (Transaction*) throw ();
private:
timex::Transaction* createTransaction (const int /*classType*/) throw ();
void releaseTransaction (timex::Transaction* tt) throw ();
- std::string identifierAsString (const Integer64&) const throw ();
- const Integer64& contextAsIdentifier (const void*) const throw ();
+ std::string identifierAsString (const S64&) const throw ();
+ const S64& contextAsIdentifier (const void*) const throw ();
Context (const Context&);
};
int x;
int y;
int op;
- anna::Integer64 initTime;
+ anna::S64 initTime;
Request () : anna::comm::Codec (Id, false) {
attach ("X", x);
al mensaje y viceversa.
@return Un puntero que hace referencia al nuevo dato interno que ha sido creado.
*/
- const Variable* attach(const char* name, Integer64& value) throw(RuntimeException) { return CompatCodec::attach(name, size(), value); }
+ const Variable* attach(const char* name, S64& value) throw(RuntimeException) { return CompatCodec::attach(name, size(), value); }
/**
Asocia el valor recibido como parametro al dato interno identificado por `id'. Esta clase
al mensaje y viceversa.
@return Un puntero que hace referencia al nuevo dato interno que ha sido creado.
*/
- const Variable* attach(const char* name, const short int id, Integer64& value) throw(RuntimeException);
+ const Variable* attach(const char* name, const short int id, S64& value) throw(RuntimeException);
/**
Asocia el valor recibido como parametro al dato interno identificado por `id'. Esta clase
* @param name Nombre logico que recibe este variable.
* @param value Referencia a la variable que estamos recubriendo con esta instancia.
*/
- Variable(const short int id, const char* name, Integer64& value) :
+ Variable(const short int id, const char* name, S64& value) :
anna::Variable(name, value),
a_id(id), a_precode(true) {;}
#ifndef anna_comm_functions_hpp
#define anna_comm_functions_hpp
-#include <netinet/in.h>
-
#include <vector>
#include <anna/app/functions.hpp>
@return Reference to our application instance on anna.comm layer.
*/
static comm::Application& getApp() throw(RuntimeException);
-
- /**
- Encodes an integer number with 32 bits over a buffer with at least 4 bytes of length.
- @param result Buffer where the number is encoded.
- @param n Number to encode.
- \return Buffer with the encoded number.
- */
- static const char* codeInteger(char* result, const int n) throw();
-
- /**
- Encodes an integer number with 16 bits over a buffer with at least 2 bytes of length.
- @param result Buffer where the number is encoded.
- @param n Number to encode.
- \return Buffer with the encoded number.
- */
- static const char* codeShort(char* result, const short int n) throw();
-
- /**
- Encodes an integer number with 64 bits over a buffer with at least 8 bytes of length.
- @param result Buffer where the number is encoded.
- @param n Number to encode.
- \return Buffer with the encoded number.
- */
- static const char* codeInteger64(char* result, const Integer64 n) throw();
-
- /**
- Encodes a floating number with 32 bits (according to the standard IEEE-754) over a buffer with at least 4 bytes of length.
- @param result Buffer where the number is encoded.
- @param n Number to encode.
- \return Buffer with the encoded number.
- */
- static const char* codeFloat(char* result, const float n) throw();
-
- /**
- Encodes a floating number with 64 bits (according to the standard IEEE-754) over a buffer with at least 8 bytes of length.
- @param result Buffer where the number is encoded.
- @param n Number to encode.
- \return Buffer with the encoded number.
- */
- static const char* codeDouble(char* result, const double n) throw();
-
- /**
- Decodes an 32 bits integer number contained in a 4-bytes buffer.
- @param data Buffer with the encoded number.
- @return Value for the number contained in the buffer.
- */
- static int decodeInteger(const char* data) throw();
-
- /**
- Decodes an 16 bits integer number contained in a 2-bytes buffer.
- @param data Buffer with the encoded number.
- @return Value for the number contained in the buffer.
- */
- static short int decodeShort(const char* data) throw();
-
- /**
- Decodes an 64 bits integer number contained in a 8-bytes buffer.
- @param data Buffer with the encoded number.
- @return Value for the number contained in the buffer.
- */
- static Integer64 decodeInteger64(const char* data) throw();
-
- /**
- Decodes an 32 bits floating number (according to the standard IEEE-754) contained in a 4-bytes buffer.
- @param data Buffer with the encoded number.
- @return Value for the number contained in the buffer.
- */
- static float decodeFloat(const char* data) throw();
-
- /**
- Decodes an 64 bits floating number (according to the standard IEEE-754) contained in a 8-bytes buffer.
- @param data Buffer with the encoded number.
- @return Value for the number contained in the buffer.
- */
- static double decodeDouble(const char* data) throw();
};
}
#include <limits.h>
#include <anna/config/defines.hpp>
+#include <anna/core/util/defines.hpp>
#include <anna/core/RuntimeException.hpp>
#include <anna/core/functions.hpp>
namespace anna {
#ifndef __x86_64__
#undef __anna64__
-typedef int64_t Integer64;
-typedef u_int64_t Unsigned64;
-
-/**
- * Defines required data type to conversion from pointer to integer
- */
+/** Defines required data type to conversion from pointer to integer */
typedef int ptrnumber;
#else
#define __anna64__
-typedef long long Integer64;
-typedef unsigned long long Unsigned64;
-
-/**
- * Defines required data type to conversion from pointer to integer
- */
+/** Defines required data type to conversion from pointer to integer */
typedef long ptrnumber;
#endif
}
#include <anna/core/oam/CounterManager.hpp>
#include <anna/core/oam/CounterRecorder.hpp>
#include <anna/core/oam/CounterScope.hpp>
-#include <anna/core/oam/CounterSummarizer.hpp>
#include <anna/core/tracing/Configuration.hpp>
#include <anna/core/tracing/Logger.hpp>
#include <anna/core/tracing/TraceFunction.hpp>
/*
* Indica el número de bits de un entero largo.
*/
- static const int int64BitSize = sizeof(Integer64) * 8;
+ static const int int64BitSize = sizeof(S64) * 8;
/**
\param number Numero a convertir.
Devuelve un literal con tel numero convertido a cadena decimal
@return Un literal con el numero signo convertido a cadena decimal.
*/
- static std::string asString(const Integer64 number) throw();
+ static std::string asString(const S64 number) throw();
/**
Devuelve un literal con tel numero convertido a cadena decimal
@return Un literal con el numero signo convertido a cadena decimal.
*/
- static std::string asString(const Unsigned64 number) throw();
+ static std::string asString(const U64 number) throw();
/**
\param _bool Booleano a convertir.
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena decimal.
*/
- static std::string asText(const char* comment, const Integer64 number)
+ static std::string asText(const char* comment, const S64 number)
throw() {
std::string result(comment);
return result += asString(number);
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena hexadecimal.
*/
- static std::string asHexString(const Integer64 number) throw();
+ static std::string asHexString(const S64 number) throw();
/**
\param number Numero a convertir.
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena hexadecimal.
*/
- static std::string asHexString(const Unsigned64 number) throw() { return asHexString((Integer64) number); }
+ static std::string asHexString(const U64 number) throw() { return asHexString((S64) number); }
/**
\param comment Comentario que precede al valor.
\param number Numero a convertir.
@return Un literal con el numero convertido a cadena decimal.
*/
- static std::string asHexText(const char* comment, const Integer64 number)
+ static std::string asHexText(const char* comment, const S64 number)
throw() {
std::string result(comment);
return result += asHexString(number);
Calcula la funcion hash de la cadena recibida como parametro.
\param str Cadena a la que aplicar la funcion hash.
*/
- static Integer64 hash(const char* str) throw();
+ static S64 hash(const char* str) throw();
/**
Calcula la funcion hash de la cadena recibida como parametro.
\param str Cadena a la que aplicar la funcion hash.
*/
- static Integer64 hash(const std::string& str) throw() { return hash(str.c_str()); }
+ static S64 hash(const std::string& str) throw() { return hash(str.c_str()); }
/**
Calcula la funcion hash exclusive de la cadena recibida como parametro.
Interpreta la cadena recibida como parametro como un entero de 32 bits.
\return
*/
- static Integer64 asInteger64(const char* str) throw();
+ static S64 asInteger64(const char* str) throw();
/**
Devuelve el identificador de thread desde el que es invocado este metodo.
* \param n Valor a estudiar.
* \return el número de bits necesarios para representar el valor recibido como parámetro.
*/
- static int bitsize(const Integer64 n) throw() {
+ static int bitsize(const S64 n) throw() {
register int aux = n >> intBitSize;
return (aux != 0) ? (bitsize(aux) + intBitSize) : bitsize((int) n);
}
* \param bitShift Número de bits a desplazar.
* \param n2 Número a combinar con el resultado de la operación (n1 << bitShift).
*/
- static Integer64 merge(const char* whatis, const int n1, const int n2, const int bitShift) throw(RuntimeException);
+ static S64 merge(const char* whatis, const int n1, const int n2, const int bitShift) throw(RuntimeException);
/**
* Calcula el logaritmo en base 2 del número recibo como parámetro.
*/
static std::string socketVectorAsString(const socket_v & socketVector) throw();
+
+ /**
+ Endianess of the system
+
+ @result Returns true when the system is little endian, false if big endian
+ */
+ static bool littleEndian() throw();
+
+ /**
+ Encodes an integer number with 32 bits over a buffer with at least 4 bytes of length.
+ @param result Buffer where the number is encoded.
+ @param n Number to encode.
+ \return Buffer with the encoded number.
+ */
+ static const char* codeInteger(char* result, const int n) throw();
+
+ /**
+ Encodes an integer number with 16 bits over a buffer with at least 2 bytes of length.
+ @param result Buffer where the number is encoded.
+ @param n Number to encode.
+ \return Buffer with the encoded number.
+ */
+ static const char* codeShort(char* result, const short int n) throw();
+
+ /**
+ Encodes an integer number with 64 bits over a buffer with at least 8 bytes of length.
+ @param result Buffer where the number is encoded.
+ @param n Number to encode.
+ \return Buffer with the encoded number.
+ */
+ static const char* codeInteger64(char* result, const S64 n) throw();
+
+ /**
+ Encodes a floating number with 32 bits (according to the standard IEEE-754) over a buffer with at least 4 bytes of length.
+ @param result Buffer where the number is encoded.
+ @param n Number to encode.
+ \return Buffer with the encoded number.
+ */
+ static const char* codeFloat(char* result, const float n) throw();
+
+ /**
+ Encodes a floating number with 64 bits (according to the standard IEEE-754) over a buffer with at least 8 bytes of length.
+ @param result Buffer where the number is encoded.
+ @param n Number to encode.
+ \return Buffer with the encoded number.
+ */
+ static const char* codeDouble(char* result, const double n) throw();
+
+ /**
+ Decodes an 32 bits integer number contained in a 4-bytes buffer.
+ @param data Buffer with the encoded number.
+ @return Value for the number contained in the buffer.
+ */
+ static int decodeInteger(const char* data) throw();
+
+ /**
+ Decodes an 16 bits integer number contained in a 2-bytes buffer.
+ @param data Buffer with the encoded number.
+ @return Value for the number contained in the buffer.
+ */
+ static short int decodeShort(const char* data) throw();
+
+ /**
+ Decodes an 64 bits integer number contained in a 8-bytes buffer.
+ @param data Buffer with the encoded number.
+ @return Value for the number contained in the buffer.
+ */
+ static S64 decodeInteger64(const char* data) throw();
+
+ /**
+ Decodes an 32 bits floating number (according to the standard IEEE-754) contained in a 4-bytes buffer.
+ @param data Buffer with the encoded number.
+ @return Value for the number contained in the buffer.
+ */
+ static float decodeFloat(const char* data) throw();
+
+ /**
+ Decodes an 64 bits floating number (according to the standard IEEE-754) contained in a 8-bytes buffer.
+ @param data Buffer with the encoded number.
+ @return Value for the number contained in the buffer.
+ */
+ static double decodeDouble(const char* data) throw();
+
+
/**
* Decodes an ISUP Number (called or calling party number).
*
*/
static void codeIsupNumber(const isup_number_t & isupNumber, bool calledOrCalling, std::string & target) throw(RuntimeException);
-
private:
static ExclusiveHash <std::string> st_stringExclusiveHash;
static ExclusiveHash <std::string, int> st_string2intExclusiveHash;
* Devuelve el valor acumulado de este contador.
* \return El valor acumulado de este contador.
*/
- Unsigned64 getAccumulatedValue() const throw() { return a_accValue; }
+ U64 getAccumulatedValue() const throw() { return a_accValue; }
/**
Operador de conversion.
const int a_id;
std::string a_name;
type_t a_value;
- Unsigned64 a_accValue;
+ U64 a_accValue;
Counter(CounterScope& scope, const int id, const char* name);
Counter(const Counter&);
+++ /dev/null
-// ANNA - Anna is Not 'N' Anymore
-//
-// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
-//
-// https://bitbucket.org/testillano/anna
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Authors: eduardo.ramos.testillano@gmail.com
-// cisco.tierra@gmail.com
-
-
-#ifndef anna_core_oam_CounterManager_hpp
-#define anna_core_oam_CounterManager_hpp
-
-#include <anna/core/functions.hpp>
-#include <anna/core/Singleton.hpp>
-
-#include <anna/timex/Timer.hpp>
-
-#include <anna/core/oam/Counter.hpp>
-#include <anna/core/oam/CounterScope.hpp>
-
-namespace anna {
-
-namespace xml {
-class Node;
-}
-
-namespace timex {
-class Engine;
-}
-
-namespace oam {
-
-class CounterScope;
-class CounterRecorder;
-class CounterSummarizer;
-class Counter;
-
-/**
- Gestor de contadores.
-
- Mantiene la lista de ambitos y contadores definidas en nuestra aplicacion. Ademas establece
- el periodo de grabacion de los contadores modificados.
-
- El periodo de grabacion se iniciara cada vez que se incremente un contador.
-*/
-class CounterManager : public Singleton <CounterManager> {
-public:
- static const int MaxScope = 100; /**< Numero maximo de ambitos */
-
- /**
- Destructor.
- */
- virtual ~CounterManager();
-
- /**
- * Devuelve el gestor de tiempos asociado al gestor de contadores.
- * \return el gestor de tiempos asociado al gestor de contadores.
- */
- timex::Engine* getEngine() throw() { return a_timeController; }
-
- /**
- Establece el gestor de tiempos usado para establecer el periodo de grabacion
- de contadores.
- \param timeController Gestor de tiempos usado para establecer el periodo de
- grabacion de contadores.
- */
- void setEngine(timex::Engine* timeController) throw() { a_timeController = timeController; }
-
- /**
- Establece la instancia de la clase encargada de grabar el fichero con la informacion
- de los contadores.
- \param counterRecorder Instancia encargada de grabar los contadores.
- \warning Sera invocado automaticamente cuando se cumpla el periodo de grabacion indicado en
- la configuracion de esta clase.
-
- */
- void setCounterRecorder(CounterRecorder* counterRecorder) throw() { a_counterRecorder = counterRecorder; }
-
- /**
- Establece la instancia de la clase encargada de calcular los contadores acumulados o
- expresados en funcion de algunos otros.
- \param counterSummarizer Instancia encargada de calcular los contadores acumulados o
- expresados en funcion de algunos otros.
- \warning Sera invocado automaticamente cuando se cumpla el periodo de grabacion indicado en
- la configuracion de esta clase.
-
- */
- void setCounterSummarizer(CounterSummarizer* counterSummarizer) throw() { a_counterSummarizer = counterSummarizer; }
-
- /**
- Establece el periodo de grabacion de los contadores. Por defecto sera 600000 (10 minutos).
- \param millisecond Periodo de grabacion de contadores expresado en milisegundos.
- */
- void setRecordPeriod(const anna::Millisecond & millisecond) throw() { a_timer.setTimeout(millisecond); }
-
- /**
- Operador de acceso. El ambito solicitado deberia estar creado mediate #create.
- \param scope Indica el numero de ambito al que deseamos acceder.
- \return El ambito de contadores.
- */
- CounterScope& operator [](const int scope) throw(RuntimeException) { return find(scope); }
-
- /**
- Operador de acceso. El ambito solicitado deberia estar creado mediate #create.
- \param scope Indica el numero de ambito al que deseamos acceder.
- \return El ambito de contadores.
- */
- const CounterScope& operator [](const int scope) const throw(RuntimeException) { return find(scope); }
-
- /**
- Crea un nuevo ambito de contadores.
- \param scope Índice del ambito. Debera ser menor de MaxScope.
- \param name Nombre logico del ambito.
- \param reuse Reusa el ambito si ya fue creado o da excepcion (por defecto).
- */
- CounterScope& create(const int scope, const char* name, bool reuse = false) throw(RuntimeException);
-
- /**
- Crea un nuevo ambito de contadores. Creara el ambito 0.
- \param name Nombre logico del ambito.
- */
- CounterScope& create(const char* name) throw(RuntimeException) { return create(0, name); }
-
- /**
- Devuelve el ambito de contadores asociado al numero recibido como parametro.
- El ambito solicitado deberia estar creado mediate #create.
- \param scope Indica el numero de ambito al que deseamos acceder.
- \return El ambito de contadores.
- */
- CounterScope& find(const int scope) throw(RuntimeException);
-
- /**
- Devuelve el ambito de contadores asociado al numero recibido como parametro.
- El ambito solicitado deberia estar creado mediate #create.
- \param scope Indica el numero de ambito al que deseamos acceder.
- \return El ambito de contadores.
- */
- const CounterScope& find(const int scope) const throw(RuntimeException);
-
- /**
- Vuelca los contadores modificados desde la ultima llamada a este metodo.
-
- \warning Si se ha establecido un anna::timex::Engine valido mediante la invocacion al
- metodo #setEngine no seria necesario invocar a este metodo, ya que se invocara automaticamente
- cuando se cumpla el periodo de grabacion establecido por la configuracion.
- */
- void record() throw(RuntimeException);
-
- /**
- * Devuelve la información relevante de esta instancia en un documento XML.
- * \return la información relevante de esta instancia en un documento XML.
- */
- xml::Node* asXML(xml::Node* parent) const throw(RuntimeException);
-
- /**
- Incrementa la cuenta del contador identificador por (scope, counter)
- El ambito solicitado deberia estar creado mediate #create, ademas el contador debera
- estar creado mediante CounterScope::create.
- \param scope Ámbito del contador.
- \param counter Identificador del contador.
- \param value Valor con el que incrementar el contador.
- */
- static void count(const int scope, const int counter, const oam::Counter::type_t value = 1) throw();
-
- /**
- Incrementa la cuenta del contador identificador por (scope = 0, counter)
- El ambito solicitado deberia estar creado mediate #create, ademas el contador debera
- estar creado mediante CounterScope::create.
- \param counter Identificador del contador.
- */
- static void count(const int counter) { count(0, counter, 1); }
-
-private:
- class Timer : public timex::Timer {
- public:
- Timer(CounterManager& counterManager) :
- timex::Timer("anna::oam:CounterManager::Timer", Millisecond(600000)),
- a_counterManager(counterManager)
- {;}
-
- private:
- CounterManager& a_counterManager;
- void expire(timex::Engine *) throw(RuntimeException) { a_counterManager.record(); }
- };
-
- class RecordingGuard {
- public:
- RecordingGuard(CounterManager*);
- ~RecordingGuard();
- private:
- CounterManager* a_counterManager;
- };
-
- CounterScope* a_scopes [MaxScope];
- Timer a_timer;
- timex::Engine* a_timeController;
- CounterRecorder* a_counterRecorder;
- CounterSummarizer* a_counterSummarizer;
- bool a_recording;
-
- CounterManager();
- CounterManager(const CounterManager&);
- void activateTimer() throw(RuntimeException);
-
- friend class Singleton <CounterManager>;
- friend class Timer;
-
- friend class CounterScope;
- // activateTimer
-
- friend class RecordingGuard;
-};
-
-}
-}
-
-#endif
-
namespace oam {
class Counter;
-class CounterManager;
/**
Interfaz que deben implementar los objetos encargados de transferir los contadores de una
aplicacion a un medio fisico.
- Esta clase se invocara automaticamente desde ANNA.oam cuando se cumple el periodo de
- grabacion establecido por el CounterManager.
+ Esta clase se invocara automaticamente al invocar al metodo record() de un modulo oam.
*/
class CounterRecorder {
public:
class Node;
}
-namespace timex {
-class Engine;
-}
-
namespace oam {
-class CounterManager;
/**
Ámbito de contadores. Contiene un grupo logico de contadores.
*/
class CounterScope : public Mutex {
public:
- /**
- * Accesor que permite modificar el valor de los contadores asociados a un ámbito de forma segura.
- * \see anna::oam::CounterScope.
- */
- class Safe {
- public:
- /**
- * Constructor.
- * \param counterScope Ámbito de contadores a bloquear para aplicar cambios.
- * \param Texto que identifica el punto de bloqueo.
- */
- Safe(timex::Engine* ttcc, CounterScope& counterScope, const char* whatis);
-
- /**
- * Destructor.
- */
- ~Safe() throw();
-
- /**
- * Incrementa el contador recibido como parámetro.
- * \warning La invocación a este método deberá hacerse sobre una sección crítica que proteja
- * a este ámbito.
- * \return El valor actual del contador.
- */
- Counter::type_t increment(const int counter, const Counter::type_t value) throw(RuntimeException) { return a_counterScope.increment(counter, value); }
-
- /**
- * Establece el valor del contador recibido como parámetro.
- * \warning La invocación a este método deberá hacerse sobre una sección crítica que proteja
- * a este ámbito.
- * \return El valor actual del contador.
- */
- Counter::type_t assign(const int counter, const Counter::type_t value) throw(RuntimeException) { return a_counterScope.assign(counter, value); }
-
- private:
- CounterScope& a_counterScope;
- Guard* a_guards [2];
- };
static const int MaxCounter = 1000; /**< Numero maximo de contador por cada ambito */
const std::string& getName() const throw() { return a_name; }
/**
- Devuelve el identificador del ambito, que coincidira con el indicado a la hora
- de crear el contador mediante el metodo CounterManager::create.
+ Devuelve el identificador del ambito
\return El identificador del ambito.
*/
const int getId() const throw() { return a_id; }
- /**
- Devuelve el gestor de contadores asociado a este ambito.
- \return El gestor de contadores asociado a este ambito.
- */
- CounterManager& getCounterManager() throw() { return a_counterManager; }
-
/**
Crea un nuevo contador.
\param counter Numero logico del contador a crear. Debera ser menor de MaxCounter.
* Devuelve el valor actual acumulado del contador pasado como parámetro.
* \param counter Identificador del contedor cuyo valor acumulado queremos obtener.
*/
- Unsigned64 getAccValue(const int counter) const throw(RuntimeException);
+ U64 getAccValue(const int counter) const throw(RuntimeException);
/**
* Resetea los valores acumulados totales de los contadores incluidos en el ámbito.
int resetAccValues() throw(RuntimeException);
private:
- CounterManager& a_counterManager;
const int a_id;
const std::string a_name;
Counter* a_counters [MaxCounter];
- CounterScope(CounterManager& counterManager, const int id, const char* name) :
+ CounterScope(const int id, const char* name) :
Mutex(Mutex::Mode::Recursive),
- a_counterManager(counterManager),
a_id(id),
a_name(name) {
anna_memset(a_counters, 0, sizeof(a_counters));
}
friend class Safe;
- friend class CounterManager;
- // CounterScope
+ friend class Handler;
+ friend class Module;
};
}
+++ /dev/null
-// ANNA - Anna is Not 'N' Anymore
-//
-// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
-//
-// https://bitbucket.org/testillano/anna
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Authors: eduardo.ramos.testillano@gmail.com
-// cisco.tierra@gmail.com
-
-
-#ifndef anna_core_oam_CounterSummarizer_hpp
-#define anna_core_oam_CounterSummarizer_hpp
-
-#include <string>
-
-#include <anna/core/RuntimeException.hpp>
-
-namespace anna {
-
-namespace oam {
-
-class Counter;
-class CounterManager;
-
-/**
- Interfaz que deben implementar los objetos encargados de calcular los acumulados de contadores
- antes de transferirlos al medio fisico.
-
- Esta clase se invocara automaticamente desde ANNA.oam cuando se cumple el periodo de
- grabacion establecido por el CounterManager.
-*/
-class CounterSummarizer {
-public:
- /**
- Calcula el valor de los acumuladores o de los contadores calculados en funcion de algunos
- otros contadores.
- */
- virtual void apply() const throw(RuntimeException) = 0;
-};
-
-}
-}
-
-#endif
-
}
namespace oam {
class CounterScope;
+class CounterRecorder;
}
}
counter_iterator counter_find(const int &key) throw() { return a_counters.find(key); }
counter_iterator counter_begin() throw() { return a_counters.begin(); }
counter_iterator counter_end() throw() { return a_counters.end(); }
+ CounterRecorder* a_counterRecorder;
+ bool a_counterRecording;
+ class RecordingGuard {
+ public:
+ RecordingGuard(Module*);
+ ~RecordingGuard();
+ private:
+ Module *a_module;
+ };
// Alarms
typedef alarm_container::iterator alarm_iterator;
public:
+ static const int MaxScope = 100; /**< Numero maximo de ambitos */
+
+
/** Constructor
@param className Logical name for the class (better use fullNaming format including namespace resolution)
*/
Module(const std::string &className) : a_className(className),
a_handler(&a_defaultHandler),
a_counters_enabled(true),
+ a_counterRecorder(NULL),
+ a_counterRecording(false),
a_alarms_enabled(true),
a_alarms_preffix_enabled(true),
a_alarms_suffix_enabled(true) {;}
-
/**
* Destructor
*/
- virtual ~Module() {;}
+ virtual ~Module();
/**
int resetCounters(const int & scopeId = -1) throw();
+ /**
+ * Sets the instance for the class which will save the counters information.
+ * @counterRecorder Provided instance
+ * @warning It should be invoked periodically as a common solution
+ */
+ void setCounterRecorder(CounterRecorder* counterRecorder) throw() { a_counterRecorder = counterRecorder; }
+
+ /**
+ * Dumps the modified counters from last invocation to this method.
+ * A counter recorder should have been assigned by mean setCounterRecorder(), which
+ * will have the specific behaviour. This procedure is oriented to have physical storage
+ * for counters information.
+ */
+ void recordCounters() throw(anna::RuntimeException);
+
+
/**
* Activates alarm with dynamic-composed text parsed with provided data (...).
* Used at MODULE implementation (library or proccess itself)
* @param components Alarm suffix components defined by oam module. Empty on default implementation.
*/
virtual void readAlarmSuffixComponents(std::vector<std::string> & components) const throw() {;}
+
+
+ friend class RecordingGuard;
};
}
#include <string>
-#include <anna/config/defines.hpp>
+#include <anna/core/util/defines.hpp>
#include <anna/core/RuntimeException.hpp>
namespace anna {
class Microsecond {
public:
- typedef Integer64 type_t;
+ typedef S64 type_t;
/**
* Constructor
#include <string>
-#include <anna/config/defines.hpp>
+#include <anna/core/util/defines.hpp>
#include <anna/core/RuntimeException.hpp>
namespace anna {
class Millisecond {
public:
- typedef Integer64 type_t;
+ typedef S64 type_t;
/**
* Constructor
class Second {
public:
#ifdef __anna64__
- typedef Integer64 type_t;
+ typedef S64 type_t;
#else
typedef int type_t;
#endif
#include <stdio.h>
-#include <anna/config/defines.hpp>
+#include <anna/core/util/defines.hpp>
namespace anna {
String& operator = (const int vv) throw() { std::string::clear(); return operator<< (vv); }
String& operator = (const unsigned int vv) throw() { std::string::clear(); return operator<< (vv); }
String& operator = (const bool vv) throw() { std::string::clear(); return operator<< (vv); }
- String& operator = (const Integer64 vv) throw() { std::string::clear(); return operator<< (vv); }
- String& operator = (const Unsigned64 vv) throw() { std::string::clear(); return operator<< (vv); }
+ String& operator = (const S64 vv) throw() { std::string::clear(); return operator<< (vv); }
+ String& operator = (const U64 vv) throw() { std::string::clear(); return operator<< (vv); }
String& operator = (const float vv) throw() { std::string::clear(); return operator<< (vv); }
String& operator = (const double vv) throw() { std::string::clear(); return operator<< (vv); }
String& operator = (const std::string& vv) throw() { std::string::operator= (vv); return *this; }
String& operator += (const int vv) throw() { return operator<< (vv); }
String& operator += (const unsigned int vv) throw() { return operator<< (vv); }
String& operator += (const bool vv) throw() { return operator<< (vv); }
- String& operator += (const Integer64 vv) throw() { return operator<< (vv); }
- String& operator += (const Unsigned64 vv) throw() { return operator<< (vv); }
+ String& operator += (const S64 vv) throw() { return operator<< (vv); }
+ String& operator += (const U64 vv) throw() { return operator<< (vv); }
String& operator += (const float vv) throw() { return operator<< (vv); }
String& operator += (const double vv) throw() { return operator<< (vv); }
String& operator += (const std::string& vv) throw() { return *this << vv; }
String& operator << (const int vv) throw();
String& operator << (const unsigned int vv) throw();
String& operator << (const bool vv) throw() { std::string::operator+= ((vv == true) ? "true" : "false"); return *this; }
- String& operator << (const Integer64 vv) throw();
- String& operator << (const Unsigned64 vv) throw();
+ String& operator << (const S64 vv) throw();
+ String& operator << (const U64 vv) throw();
String& operator << (const float vv) throw();
String& operator << (const double vv) throw();
String& operator << (const std::string& vv) throw() { std::string::operator+= (vv); return *this; }
* \param vv Valor a interpretar.
* \return La cadena con el contenido interpretado.
*/
- static String hex(const Integer64 vv) {
+ static String hex(const S64 vv) {
return __format(vv, "0x%llx");
/*#ifdef __anna64__
return __format (vv, "0x%lx");
* Asignación a entero de 64 bits.
* \param value Valor a asignar a esta variable.
*/
- TextVariable& operator= (const Integer64 value) throw(RuntimeException) { setValue(value); return *this; }
+ TextVariable& operator= (const S64 value) throw(RuntimeException) { setValue(value); return *this; }
/**
* Asignación a flotante.
#ifndef anna_core_util_Variable_hpp
#define anna_core_util_Variable_hpp
-#include <anna/config/defines.hpp>
+#include <anna/core/util/defines.hpp>
#include <anna/core/RuntimeException.hpp>
#include <anna/core/define.autoenum.hpp>
#include <anna/core/util/String.hpp>
-#include <anna/core//DataBlock.hpp>
+#include <anna/core/DataBlock.hpp>
namespace anna {
* @param name Nombre logico que recibe este variable.
* @param value Referencia a la variable que estamos recubriendo con esta instancia.
*/
- Variable(const char* name, Integer64& value) :
+ Variable(const char* name, S64& value) :
a_name(name),
a_isNull(false),
a_type(Type::Integer64),
@return Si la variable indicada en el contructor de esta instancia puede interpretarse como
un entero de 64 bits devolvera su contenido, en otro caso lanzara una excepcion para indicar el error.
*/
- Integer64 getInteger64Value() const throw(RuntimeException);
+ S64 getInteger64Value() const throw(RuntimeException);
/**
Devuelve el valor booleano asociado a esta variable.
Interpreta el valor asociado a esta variable como un valor entero largo.
\warning No se realiza ninguna comprobacion semantica.
*/
- Integer64 getInteger64() const throw() { return *a_value.a_longInteger; }
+ S64 getInteger64() const throw() { return *a_value.a_longInteger; }
/**
Interpreta el valor asociado a esta variable como un valor booleano.
*
* @param value Valor que tomara la variable a la que recubre este variable.
*/
- void setValue(const Integer64 value) throw(RuntimeException) ;
+ void setValue(const S64 value) throw(RuntimeException) ;
/**
* Establece el valor de la variable a la que recubre. Si la variable estaba marcada como nula la desmarca.
Establece el valor asociado a esta variable como un valor entero largo.
\warning No se realiza ninguna comprobacion semantica.
*/
- void setLong(const Integer64 value) throw() { *a_value.a_longInteger = value; a_isNull = false; }
+ void setLong(const S64 value) throw() { *a_value.a_longInteger = value; a_isNull = false; }
/**
Establece el valor asociado a esta variable como un valor booleano.
union {
std::string* a_string;
int* a_integer;
- Integer64* a_longInteger;
+ S64* a_longInteger;
bool* a_boolean;
DataBlock* a_dataBlock;
float* a_float;
} a_value;
struct {
int integer;
- Integer64 longInteger;
+ S64 longInteger;
bool boolean;
float theFloat;
double theDouble;
/** Alias for int: signed integer with 32 bits */
typedef int S32;
+///** Alias for unsigned long long: unsigned integer with 64 bits */
+//typedef unsigned long long int U64;
+//
+///** Alias for long long: signed integer with 64 bits */
+//typedef long long int S64;
+#ifndef __x86_64__
+#undef __anna64__
+/** Alias for long long: signed integer with 64 bits */
+typedef int64_t S64
/** Alias for unsigned long long: unsigned integer with 64 bits */
-typedef unsigned long long int U64;
-
+typedef u_int64_t U64;
+#else
+#define __anna64__
/** Alias for long long: signed integer with 64 bits */
typedef long long int S64;
+/** Alias for unsigned long long: unsigned integer with 64 bits */
+typedef unsigned long long int U64;
+#endif
/** Alias for float: floating number with 32 bits (1-8-23) */
typedef float F32;
namespace dbos {
typedef unsigned int Size;
-typedef Unsigned64 Index;
+typedef U64 Index;
typedef ptrnumber StorageId;
typedef unsigned int Counter;
}
#include <anna/diameter.comm/ClassCode.hpp>
#include <anna/diameter.comm/Engine.hpp>
#include <anna/diameter.comm/Entity.hpp>
-#include <anna/diameter.comm/StandardEntity.hpp>
#include <anna/diameter.comm/Message.hpp>
#include <anna/diameter.comm/OamModule.hpp>
#include <anna/diameter.comm/Response.hpp>
#include <anna/diameter/defines.hpp>
#include <anna/diameter/codec/basetypes/basetypes.hpp>
#include <anna/diameter/stack/Avp.hpp>
-#include <anna/diameter/helpers/tme/codectypes/codectypes.hpp>
#include <anna/core/RuntimeException.hpp>
namespace diameter {
-namespace helpers {
-namespace tme {
-namespace codectypes {
-class Unsigned16;
-class ISDNNumber;
-class ISDNAddress;
-}
-}
-}
-
-
namespace stack {
class Dictionary;
class Format;
using namespace basetypes;
-using namespace helpers::tme::codectypes;
/**
* Diameter avp generic container
QoSFilterRule *a_QoSFilterRule;
Unknown *a_Unknown;
- // Derived formats ////////////////////////////////////////////
- /* TME */
- ISDNNumber *a_ISDNNumber;
- ISDNAddress *a_ISDNAddress;
- Unsigned16 *a_Unsigned16;
-
-
-
// Grouped helpers
find_container a_finds; // fast access for grouped and message first-level avps
static const Avp* avp(const_avp_iterator ii) throw() { return ii->second; }
// Internal
- void assertFormat(const std::string &name) const throw(anna::RuntimeException);
bool flagsOK() const throw(); // flags coherence regarding dictionary. Only must be called when AVP is identified at the dictionary.
int addChild(Avp *avp) throw(anna::RuntimeException) { assertFormat("Grouped"); return addChild(a_avps, a_insertionPositionForChilds, avp); }
bool hasChildren() throw() { return a_avps.size() != 0; }
/**
* Initializes Avp class information.
- * Default implementation supports all anna::diameter formats (including i.e. tme.db ones).
+ * Default implementation supports all anna::diameter formats (including derived ones).
* Diameter basic formats are managed at #initialize, which will invoke this method at the end.
*/
- virtual void initializeByFormat() throw();
+ virtual void initializeByFormat() throw() {};
/**
* Gets avp data-part length.
- * Default implementation supports all anna::diameter formats (including i.e. tme.db ones).
+ * Default implementation supports all anna::diameter formats (including derived ones).
* Diameter basic formats are managed at #initialize, which will invoke this method at the end.
*
* @param stackFormat Stack avp format in which data extraction is based.
*
* @return Avp data-part size.
*/
- virtual U24 getLengthByFormat(const anna::diameter::stack::Format *stackFormat) const throw();
+ virtual U24 getLengthByFormat(const anna::diameter::stack::Format *stackFormat) const throw() { return 0; };
/**
Gets data or hexadecimal data depending on avp format, for xml creating
- Default implementation supports all anna::diameter formats (including i.e. tme.db ones).
+ Default implementation supports all anna::diameter formats (including derived ones).
Diameter basic formats are managed at #initialize, which will invoke this method at the end.
\param isHex Hexadecimal/Natural data when apply.
\param stackFormat Stack avp format in which data extraction is based.
\return xml data representation
*/
- virtual std::string getXMLdataByFormat(bool & isHex, const anna::diameter::stack::Format *stackFormat) const throw();
+ virtual std::string getXMLdataByFormat(bool & isHex, const anna::diameter::stack::Format *stackFormat) const throw() { return ""; };
/**
Interpret xml data in order to dump over the class content.
- Default implementation supports all anna::diameter formats (including i.e. tme.db ones).
+ Default implementation supports all anna::diameter formats (including derived ones).
Diameter basic formats are managed at #initialize, which will invoke this method at the end.
\param data Avp data attribute
\param hexData Avp hex-data attribute
\param stackFormat Stack avp format in which data extraction is based.
*/
- virtual void fromXMLByFormat(const anna::xml::Attribute* data, const anna::xml::Attribute* hexData, const anna::diameter::stack::Format *stackFormat) throw(anna::RuntimeException);
+ virtual void fromXMLByFormat(const anna::xml::Attribute* data, const anna::xml::Attribute* hexData, const anna::diameter::stack::Format *stackFormat) throw(anna::RuntimeException) {};
/**
Encodes buffer with the class content.
- Default implementation supports all anna::diameter formats (including i.e. tme.db ones).
+ Default implementation supports all anna::diameter formats (including derived ones).
Diameter basic formats are managed at #initialize, which will invoke this method at the end.
@param dataPart Data-part begin pointer
@param stackFormat Stack avp format in which data extraction is based.
*/
- virtual void codeByFormat(char* dataPart, const anna::diameter::stack::Format *stackFormat) const throw(anna::RuntimeException);
+ virtual void codeByFormat(char* dataPart, const anna::diameter::stack::Format *stackFormat) const throw(anna::RuntimeException) {};
/**
Decodes Avp data part.
- Default implementation supports all anna::diameter formats (including i.e. tme.db ones).
+ Default implementation supports all anna::diameter formats (including derived ones).
Diameter basic formats are managed at #initialize, which will invoke this method at the end.
@param buffer Avp data part start pointer
@param size Avp data part size
@param stackFormat Stack avp format in which data extraction is based.
*/
- virtual void decodeDataPartByFormat(const char * buffer, int size, const anna::diameter::stack::Format *stackFormat) throw(anna::RuntimeException);
+ virtual void decodeDataPartByFormat(const char * buffer, int size, const anna::diameter::stack::Format *stackFormat) throw(anna::RuntimeException) {};
/**
Reserves memory for data part depending on avp format for the identifier provided.
- Default implementation supports all anna::diameter formats (including i.e. tme.db ones).
+ Default implementation supports all anna::diameter formats (including derived ones).
Diameter basic formats are managed at #initialize, which will invoke this method at the end.
@param stackFormat Stack avp format in which data extraction is based.
*/
- virtual void allocationByFormat(const anna::diameter::stack::Format *stackFormat) throw();
+ virtual void allocationByFormat(const anna::diameter::stack::Format *stackFormat) throw() {};
/**
* Clears Avp data-part format containers.
*/
- virtual void clearByFormat() throw();
+ virtual void clearByFormat() throw() {};
*/
void initialize() throw();
+ /**
+ * Assert format regarding dictionary
+ */
+ void assertFormat(const std::string &name) const throw(anna::RuntimeException);
/**
* Gets avp total length based on internal data part and header configuration.
/** Access content for Unknown Avp in order to set data part */
Unknown * getUnknown() throw(anna::RuntimeException) { assertFormat("Unknown"); return a_Unknown; }
- // Derived formats ////////////////////////////////////////////
- /* TME */
- /** Access content for ISDNNumber Avp in order to set data part */
- ISDNNumber * getISDNNumber() throw(anna::RuntimeException) { assertFormat("ISDNNumber"); return a_ISDNNumber; }
- /** Access content for ISDNAddress Avp in order to set data part */
- ISDNAddress * getISDNAddress() throw(anna::RuntimeException) { assertFormat("ISDNAddress"); return a_ISDNAddress; }
- /** Access content for Unsigned16 Avp in order to set data part */
- Unsigned16 * getUnsigned16() throw(anna::RuntimeException) { assertFormat("Unsigned16"); return a_Unsigned16; }
-
/**
Removes an Avp within grouped type (first level) and free resources.
const Unknown * getUnknown() const throw(anna::RuntimeException) { assertFormat("Unknown"); return a_Unknown; }
- // Derived formats ////////////////////////////////////////////
- /* TME */
- /** Access content for ISDNNumber Avp */
- const ISDNNumber * getISDNNumber() const throw(anna::RuntimeException) { assertFormat("ISDNNumber"); return a_ISDNNumber; }
- /** Access content for ISDNAddress Avp */
- const ISDNAddress * getISDNAddress() const throw(anna::RuntimeException) { assertFormat("ISDNAddress"); return a_ISDNAddress; }
- /** Access content for Unsigned16 Avp */
- const Unsigned16 * getUnsigned16() const throw(anna::RuntimeException) { assertFormat("Unsigned16"); return a_Unsigned16; }
-
-
// Helpers
/**
* Destructor
*/
~Message();
- // Si hago virtual al destructor, al destruir una hija se llama tambien al destructor del padre.
- // No hace falta porque he hecho virtual a 'clear' que se llama desde el destructor.
-
+ // Virtual destructors are useful when you can delete an instance of a derived class through a pointer to base class:
+ // This destructor is not virtual, then a pointer to base class (even pointing to a children one) will invoke this destructor, not the derived one.
+ // My current solution: virtualizing method 'clear'
+ //
+ // Recommendation:
+ // To sum up, always make base classes' destructors virtual when they're meant to be manipulated polymorphically.
// setters
// Local
#include <anna/diameter/codec/basetypes/AvpData.hpp>
-#include <anna/config/defines.hpp>
+#include <anna/core/util/defines.hpp>
namespace anna {
// helpers
std::string asPrintableString() throw(anna::RuntimeException) {
- return anna::functions::asString((anna::Integer64)a_value);
+ return anna::functions::asString((anna::S64)a_value);
}
std::string asString() throw(anna::RuntimeException) {
// Local
#include <anna/diameter/codec/basetypes/AvpData.hpp>
-#include <anna/config/defines.hpp>
+#include <anna/core/util/defines.hpp>
namespace anna {
// helpers
std::string asPrintableString() throw(anna::RuntimeException) {
- return anna::functions::asString((anna::Unsigned64)a_value);
+ return anna::functions::asString((anna::U64)a_value);
}
std::string asString() throw(anna::RuntimeException) {
~Avp();
+ /** Access content for ISDNNumber Avp in order to set data part */
+ ISDNNumber * getISDNNumber() throw(anna::RuntimeException) { assertFormat("ISDNNumber"); return a_ISDNNumber; }
+ /** Access content for ISDNAddress Avp in order to set data part */
+ ISDNAddress * getISDNAddress() throw(anna::RuntimeException) { assertFormat("ISDNAddress"); return a_ISDNAddress; }
+ /** Access content for Unsigned16 Avp in order to set data part */
+ Unsigned16 * getUnsigned16() throw(anna::RuntimeException) { assertFormat("Unsigned16"); return a_Unsigned16; }
+
+
+ /** Access content for ISDNNumber Avp */
+ const ISDNNumber * getISDNNumber() const throw(anna::RuntimeException) { assertFormat("ISDNNumber"); return a_ISDNNumber; }
+ /** Access content for ISDNAddress Avp */
+ const ISDNAddress * getISDNAddress() const throw(anna::RuntimeException) { assertFormat("ISDNAddress"); return a_ISDNAddress; }
+ /** Access content for Unsigned16 Avp */
+ const Unsigned16 * getUnsigned16() const throw(anna::RuntimeException) { assertFormat("Unsigned16"); return a_Unsigned16; }
+
+
+
+
friend class Message;
friend class Engine;
};
\param _namespace Referencia al namespace al que pertenece el atributo. Puede ser NULL.
\return La instancia del nuevo atributo.
*/
- xml::Attribute* createAttribute(const char* name, const Integer64* value, const Namespace* _namespace = NULL) throw() {
+ xml::Attribute* createAttribute(const char* name, const S64* value, const Namespace* _namespace = NULL) throw() {
return createAttribute(name, anna::functions::asString(*value), _namespace);
}
\param _namespace Referencia al namespace al que pertenece el atributo. Puede ser NULL.
\return La instancia del nuevo atributo.
*/
- xml::Attribute* createAttribute(const char* name, const Unsigned64* value, const Namespace* _namespace = NULL) throw() {
+ xml::Attribute* createAttribute(const char* name, const U64* value, const Namespace* _namespace = NULL) throw() {
return createAttribute(name, anna::functions::asString(*value), _namespace);
}
const comm::Variable* comm::Codec::attach(const char* name, Microsecond& value)
throw(RuntimeException) {
- return CompatCodec::attach(name, size(), (Integer64&) value.refValue());
+ return CompatCodec::attach(name, size(), (S64&) value.refValue());
}
#include <anna/core/mt/ThreadManager.hpp>
#include <anna/core/mt/Thread.hpp>
#include <anna/core/util/Microsecond.hpp>
+#include <anna/core/util/defines.hpp>
#include <anna/comm/comm.hpp>
#include <anna/comm/internal/sccs.hpp>
return result;
}
-const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, Integer64& value)
+const comm::Variable* comm::CompatCodec::attach(const char* name, const short int id, S64& value)
throw(RuntimeException) {
- const Integer64 backup(value);
+ const S64 backup(value);
const Variable* result = insert(name, id, a_variables, value);
value = backup;
return result;
register Variable* variable;
int stringLen;
const char* string;
- char aux [sizeof(Integer64)];
+ char aux [sizeof(S64)];
if(a_scramble == true) // (1)
while(c == 0) c = rand() % 0xff;
break;
case Variable::Type::Integer64:
self += variable->codec();
- self.append(comm::functions::codeInteger64(aux, variable->getInteger64()), sizeof(Integer64));
+ self.append(comm::functions::codeInteger64(aux, variable->getInteger64()), sizeof(S64));
break;
case Variable::Type::Boolean:
self.append(comm::functions::codeShort(aux, variable->getId()), sizeof(short int)); // (3)
break;
case Variable::Type::Integer64:
variable->setValue(comm::functions::decodeInteger64(++ data));
- data += sizeof(Integer64);
+ data += sizeof(S64);
break;
case Variable::Type::Boolean:
variable->setBoolean((*data & 0x80) ? true : false);
break;
case Variable::Type::Integer64:
variable->setValue(comm::functions::decodeInteger64(++ data));
- data += sizeof(Integer64);
+ data += sizeof(S64);
break;
case Variable::Type::Boolean:
variable->setBoolean((*data & 0x80) ? true : false);
return result;
}
-
-const char* comm::functions::codeInteger(char* result, const int n)
-throw() {
- int aux(htonl(n));
- register char* w((char*) &aux);
- *result = *w;
- *(result + 1) = *(w + 1);
- *(result + 2) = *(w + 2);
- *(result + 3) = *(w + 3);
- return result;
-}
-
-const char* comm::functions::codeShort(char* result, const short int n)
-throw() {
- short int aux(htons(n));
- register char* w((char*) &aux);
- *result = *w;
- *(result + 1) = *(w + 1);
- return result;
-}
-
-const char* comm::functions::codeInteger64(char* result, const Integer64 n)
-throw() {
- Integer64 aux(0xffffffff);
- int n2;
- aux <<= 32;
- aux &= n;
- n2 = (aux >> 32) & 0xffffffff;
- codeInteger(result, n2);
- n2 = n & 0xffffffff;
- codeInteger(result + sizeof(int), n2);
- return result;
-}
-
-/*static*/
-const char* comm::functions::codeFloat(char* result, const float n)
-throw() {
- int ii;
- anna_memcpy(&ii, &n, sizeof(n));
- return functions::codeInteger(result, ii);
-}
-
-/*static*/
-const char* comm::functions::codeDouble(char* result, const double n)
-throw() {
- Integer64 ii;
- anna_memcpy(&ii, &n, sizeof(n));
- return functions::codeInteger64(result, ii);
-}
-
-int comm::functions::decodeInteger(const char* data)
-throw() {
- int result;
- register char* w((char*) &result);
- *w = *data;
- *(w + 1) = *(data + 1);
- *(w + 2) = *(data + 2);
- *(w + 3) = *(data + 3);
- return ntohl(result);
-}
-
-short int comm::functions::decodeShort(const char* data)
-throw() {
- short int result;
- register char* w((char*) &result);
- *w = *data;
- *(w + 1) = *(data + 1);
- return ntohs(result);
-}
-
-Integer64 comm::functions::decodeInteger64(const char* data)
-throw() {
- Integer64 result(decodeInteger(data));
- result <<= 32;
- return result |= (decodeInteger(data + sizeof(int)) & 0xffffffff);
-}
-
-/*static*/
-float comm::functions::decodeFloat(const char* data)
-throw() {
- float result;
- int ii = functions::decodeInteger(data);
- anna_memcpy(&result, &ii, sizeof(result));
- return result;
-}
-
-/*static*/
-double comm::functions::decodeDouble(const char* data)
-throw() {
- double result;
- Integer64 ii = functions::decodeInteger64(data);
- anna_memcpy(&result, &ii, sizeof(result));
- return result;
-}
string functions::asString(const unsigned long number)
throw() {
- return asString((Unsigned64)number);
+ return asString((U64)number);
}
-string functions::asString(const Integer64 number)
+string functions::asString(const S64 number)
throw() {
char aux [24];
sprintf(aux, "%lld", number);
return string(aux);
}
-string functions::asString(const Unsigned64 number)
+string functions::asString(const U64 number)
throw() {
char aux [16];
sprintf(aux, "%llu", number);
string functions::asHexString(const long number)
throw() {
- return asHexString((Integer64)number);
+ return asHexString((S64)number);
}
-string functions::asHexString(const Integer64 number)
+string functions::asHexString(const S64 number)
throw() {
char aux [32];
sprintf(aux, "0x%llx", number);
// from a version by Allen Holub (see Andrew Binstock, "Hashing Revisited"
// Dr. Dobb's Journal, April 1996)
-Integer64 functions::hash(const char* p)
+S64 functions::hash(const char* p)
throw() {
- static const int long_bits = sizeof(Integer64) << 3;
+ static const int long_bits = sizeof(S64) << 3;
static const int one_eighth = long_bits >> 3;
static const int three_fourths = long_bits * 3 / 4;
- static const Integer64 high_bits = ((Integer64)(~0L)) << (long_bits - one_eighth);
- Integer64 result = 0;
- Integer64 temp;
+ static const S64 high_bits = ((S64)(~0L)) << (long_bits - one_eighth);
+ S64 result = 0;
+ S64 temp;
while(*p != 0) {
result = (result << one_eighth) + *p ++;
throw RuntimeException(msg, ANNA_FILE_LOCATION);
}
-Integer64 functions::asInteger64(const char* str)
+S64 functions::asInteger64(const char* str)
throw() {
- Integer64 number = 0;
+ S64 number = 0;
sscanf(str, "%lld", &number);
/*
#ifdef __anna64__
}
/*static*/
-Integer64 functions::merge(const char* whatis, const int n1, const int n2, const int bitShift)
+S64 functions::merge(const char* whatis, const int n1, const int n2, const int bitShift)
throw(RuntimeException) {
if(bitShift > intBitSize) {
string msg(functions::asString("%s | N1: 0x%x | N2: 0x%x | bitShift: %d | bitShift must be less than %d", whatis, n1, n2, bitShift, intBitSize));
throw RuntimeException(msg, ANNA_FILE_LOCATION);
}
- Integer64 result = n1;
+ S64 result = n1;
result <<= bitShift;
result |= n2;
return result;
}
+bool functions::littleEndian()
+throw() {
+ int i = 1;
+ char *p = (char *) &i;
+ if (p[0] == 1) return true;
+ return false;
+}
+
+const char* functions::codeInteger(char* result, const int n)
+throw() {
+ int aux(htonl(n));
+ register char* w((char*) &aux);
+ *result = *w;
+ *(result + 1) = *(w + 1);
+ *(result + 2) = *(w + 2);
+ *(result + 3) = *(w + 3);
+ return result;
+}
+
+const char* functions::codeShort(char* result, const short int n)
+throw() {
+ short int aux(htons(n));
+ register char* w((char*) &aux);
+ *result = *w;
+ *(result + 1) = *(w + 1);
+ return result;
+}
+
+const char* functions::codeInteger64(char* result, const S64 n)
+throw() {
+ S64 aux(0xffffffff);
+ int n2;
+ aux <<= 32;
+ aux &= n;
+ n2 = (aux >> 32) & 0xffffffff;
+ codeInteger(result, n2);
+ n2 = n & 0xffffffff;
+ codeInteger(result + sizeof(int), n2);
+ return result;
+}
+
+/*static*/
+const char* functions::codeFloat(char* result, const float n)
+throw() {
+ int ii;
+ anna_memcpy(&ii, &n, sizeof(n));
+ return functions::codeInteger(result, ii);
+}
+
+/*static*/
+const char* functions::codeDouble(char* result, const double n)
+throw() {
+ S64 ii;
+ anna_memcpy(&ii, &n, sizeof(n));
+ return functions::codeInteger64(result, ii);
+}
+
+int functions::decodeInteger(const char* data)
+throw() {
+ int result;
+ register char* w((char*) &result);
+ *w = *data;
+ *(w + 1) = *(data + 1);
+ *(w + 2) = *(data + 2);
+ *(w + 3) = *(data + 3);
+ return ntohl(result);
+}
+
+short int functions::decodeShort(const char* data)
+throw() {
+ short int result;
+ register char* w((char*) &result);
+ *w = *data;
+ *(w + 1) = *(data + 1);
+ return ntohs(result);
+}
+
+S64 functions::decodeInteger64(const char* data)
+throw() {
+ S64 result(decodeInteger(data));
+ result <<= 32;
+ return result |= (decodeInteger(data + sizeof(int)) & 0xffffffff);
+}
+
+/*static*/
+float functions::decodeFloat(const char* data)
+throw() {
+ float result;
+ int ii = functions::decodeInteger(data);
+ anna_memcpy(&result, &ii, sizeof(result));
+ return result;
+}
+
+/*static*/
+double functions::decodeDouble(const char* data)
+throw() {
+ double result;
+ S64 ii = functions::decodeInteger64(data);
+ anna_memcpy(&result, &ii, sizeof(result));
+ return result;
+}
+
+
void functions::decodeIsupNumber(const char *buffer, int length, isup_number_t & isupNumber, bool calledOrCalling) throw(anna::RuntimeException) {
#define DECODE2BYTES_INDX_VALUETYPE(buffer,indx,value_type) ((((value_type)buffer[indx] << 8) & 0xFF00) + ((value_type)buffer[indx+1] & 0x00FF))
#include <anna/core/tracing/Logger.hpp>
-#include <anna/core/oam/CounterManager.hpp>
+#include <anna/core/oam/Counter.hpp>
+#include <anna/core/oam/CounterScope.hpp>
+#include <anna/core/util/defines.hpp>
using namespace std;
using namespace anna;
result += functions::asString(a_accValue);
return result += " }";
}
+
+++ /dev/null
-// ANNA - Anna is Not 'N' Anymore
-//
-// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
-//
-// https://bitbucket.org/testillano/anna
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Authors: eduardo.ramos.testillano@gmail.com
-// cisco.tierra@gmail.com
-
-
-#include <anna/core/tracing/TraceMethod.hpp>
-#include <anna/core/tracing/Logger.hpp>
-
-#include <anna/xml/Node.hpp>
-#include <anna/xml/Attribute.hpp>
-
-#include <anna/timex/Engine.hpp>
-
-#include <anna/core/oam/CounterManager.hpp>
-#include <anna/core/oam/CounterRecorder.hpp>
-#include <anna/core/oam/CounterSummarizer.hpp>
-
-
-using namespace std;
-using namespace anna;
-
-oam::CounterManager::CounterManager() :
- a_timer(*this),
- a_timeController(NULL),
- a_counterRecorder(NULL),
- a_counterSummarizer(NULL),
- a_recording(false) {
- anna_memset(a_scopes, 0, sizeof(a_scopes));
-}
-
-oam::CounterManager::~CounterManager() {
- for(register int i = 0; i < MaxScope; i ++)
- delete a_scopes [i];
-}
-
-oam::CounterScope& oam::CounterManager::create(const int scope, const char* name, bool reuse)
-throw(RuntimeException) {
- if(scope >= MaxScope) {
- string msg(CounterScope(*this, scope, name).asString());
- msg += " | Out of range";
- throw RuntimeException(msg, ANNA_FILE_LOCATION);
- }
-
- bool exists = (a_scopes [scope] != NULL);
-
- if(exists) {
- string msg(CounterScope(*this, scope, name).asString());
- msg += " | Id was already registered as ";
- msg += a_scopes [scope]->asString();
-
- if(!reuse)
- throw RuntimeException(msg, ANNA_FILE_LOCATION);
-
- LOGWARNING(Logger::warning(msg, ANNA_FILE_LOCATION));
- } else
- a_scopes [scope] = new CounterScope(*this, scope, name);
-
- return *(a_scopes [scope]);
-}
-
-oam::CounterScope& oam::CounterManager::find(const int scope)
-throw(RuntimeException) {
- if(scope >= MaxScope) {
- string msg(CounterScope(*this, scope, "(none)").asString());
- msg += " | Out of range";
- throw RuntimeException(msg, ANNA_FILE_LOCATION);
- }
-
- if(a_scopes [scope] == NULL) {
- string msg(CounterScope(*this, scope, "(none)").asString());
- msg += " | Was not created";
- throw RuntimeException(msg, ANNA_FILE_LOCATION);
- }
-
- return *(a_scopes [scope]);
-}
-
-const oam::CounterScope& oam::CounterManager::find(const int scope) const
-throw(RuntimeException) {
- const CounterScope& result = const_cast <oam::CounterManager*>(this)->find(scope);
- return result;
-}
-
-
-// Se invoca desde oam::CounterScope
-void oam::CounterManager::activateTimer()
-throw(RuntimeException) {
- static bool warning = false;
-
- if(a_timeController == NULL) {
- if(warning == false) {
- LOGWARNING(
- Logger::write(
- Logger::Warning,
- "anna::oam::CounterManager has no time manager associated. Counters won't be dumped",
- ANNA_FILE_LOCATION
- );
- )
- warning = true;
- }
-
- return;
- }
-
- if(a_counterRecorder == NULL) {
- LOGWARNING(
- Logger::write(
- Logger::Warning,
- "anna::oam::CounterManager has no counter recorder associated. Ignore record operation.",
- ANNA_FILE_LOCATION
- );
- )
- return;
- }
-
- if(a_timer.isActive() == false && a_recording == false) {
- try {
- a_timeController->activate(a_timer);
- } catch(RuntimeException& ex) {
- ex.trace();
- }
- }
-}
-
-// Al invocar a este método el timex::Engine tiene activa una SSCC
-void oam::CounterManager::record()
-throw(RuntimeException) {
- LOGMETHOD(TraceMethod traceMethod("anna::oam::CounterManager", "record", ANNA_FILE_LOCATION));
-
- if(a_counterRecorder == NULL)
- throw RuntimeException("anna::oam::CounterManager has no counter recorder associated", ANNA_FILE_LOCATION);
-
- LOGDEBUG(
- string msg("Recording counters | ");
- msg += a_counterRecorder->asString();
- Logger::write(Logger::Debug, msg, ANNA_FILE_LOCATION)
- );
- RecordingGuard guard(this);
-
- if(a_counterSummarizer != NULL)
- a_counterSummarizer->apply();
-
- a_counterRecorder->open();
- Counter* counter = NULL;
- CounterScope* scope = NULL;
-
- try {
- for(register int iscope = 0; iscope < MaxScope; iscope ++) {
- if((scope = a_scopes [iscope]) == NULL) continue;
-
- CounterScope& counterScope(*a_scopes [iscope]);
- // Al invocar a este método el timex::Engine ya está protegido => no hace falta volver a hacerlo
- CounterScope::Safe locker(NULL, counterScope, "oam::CounterManager::record");
-
- for(register int icounter = 0; icounter < CounterScope::MaxCounter; icounter ++) {
- Counter* counter = counterScope.a_counters [icounter];
-
- if(counter == NULL)
- continue;
-
- if(counter->getValue() == 0)
- continue;
-
- a_counterRecorder->apply(*counter);
- counter->reset();
- }
- }
-
- a_counterRecorder->close();
- } catch(RuntimeException&) {
- a_counterRecorder->close();
- throw;
- }
-}
-
-xml::Node* oam::CounterManager::asXML(xml::Node* parent) const
-throw(RuntimeException) {
- xml::Node* result = parent->createChild("oam.CounterManager");
-
- for(int ii = 0; ii < MaxScope; ii ++) {
- if(a_scopes [ii] != NULL) {
- // Observar que el Scope no conoce SU id.
- a_scopes [ii]->asXML(result)->createAttribute("Id", ii);
- }
- }
-
- return result;
-}
-
-oam::CounterManager::RecordingGuard::RecordingGuard(CounterManager* counterManager) :
- a_counterManager(counterManager) {
- counterManager->a_recording = true;
-}
-
-oam::CounterManager::RecordingGuard::~RecordingGuard() {
- a_counterManager->a_recording = false;
-}
-
-//static
-void oam::CounterManager::count(const int scope, const int counter, const oam::Counter::type_t value)
-throw() {
- CounterManager& ccmm = CounterManager::instantiate();
-
- try {
- oam::CounterScope::Safe counterScope(ccmm.a_timeController, ccmm.find(scope), "oam::CounterManager::count");
- counterScope.increment(counter, value);
- } catch(Exception& ex) {
- ex.trace();
- }
-}
#include <anna/timex/Engine.hpp>
-#include <anna/core/oam/CounterManager.hpp>
#include <anna/core/oam/CounterScope.hpp>
#include <anna/core/oam/Counter.hpp>
a_counters [counter]->a_value += value;
a_counters [counter]->a_accValue += value;
LOGINFORMATION(a_counters [counter]->debug());
- a_counterManager.activateTimer();
return a_counters [counter]->a_value;
}
a_counters [counter]->a_value = value;
a_counters [counter]->a_accValue = value;
LOGINFORMATION(a_counters [counter]->debug());
- a_counterManager.activateTimer();
return value;
}
return a_counters [counter]->a_value;
}
-Unsigned64 oam::CounterScope::getAccValue(const int counter) const
+U64 oam::CounterScope::getAccValue(const int counter) const
throw(RuntimeException) {
test_range(counter);
test_instance(counter);
return result;
}
-/*
-[0x7fbfffea90]: timex::Engine | Callers: timex::Engine::activate [2],timex::Engine::tick [69]
- [0x79bf60, 2]: oam::CounterManager | Callers: MyInterface::receive [4],anna::oam::CounterManager::record [2]
- [0x7fbfffea90, 2]: timex::Engine | Callers: timex::Engine::activate [2],timex::Engine::tick [69]
- ------ Loop detected [ Level=2 | Loop: 3 ] -------
-*/
-oam::CounterScope::Safe::Safe(timex::Engine* ttcc, oam::CounterScope& counterScope, const char* whatis) :
- a_counterScope(counterScope) {
- if(ttcc != NULL)
- a_guards [0] = new Guard(ttcc, "timex::Engine from oam::CounterScope::Safe::Safe");
- else
- a_guards [0] = NULL;
-
- a_guards [1] = new Guard(counterScope, whatis);
-}
-
-oam::CounterScope::Safe::~Safe()
-throw() {
- delete a_guards [1];
- delete a_guards [0];
-}
-
// Local
#include <anna/core/oam/Module.hpp>
#include <anna/core/oam/Handler.hpp>
+#include <anna/core/oam/CounterScope.hpp>
#include <anna/core/functions.hpp>
#include <anna/core/tracing/Logger.hpp>
#include <anna/core/tracing/TraceWriter.hpp>
#include <anna/core/tracing/TraceMethod.hpp>
#include <anna/core/functions.hpp>
-#include <anna/core/oam/CounterManager.hpp>
// Standard
#include <stdarg.h>
std::string base = result ? result->Description : module->getDefaultInternalCounterDescription(type);
// Count if registered
- if(result)
- anna::oam::CounterManager::instantiate().count(module->getActiveCounterScope()->getId(), result->Offset, amount);
+ if(result) {
+ anna::oam::CounterScope *nc_cs = const_cast <anna::oam::CounterScope*>(module->getActiveCounterScope());
+ nc_cs->increment(result->Offset, amount);
+ }
LOGDEBUG
(
#include <anna/core/oam/Module.hpp>
#include <anna/core/functions.hpp>
#include <anna/core/oam/Configuration.hpp>
+#include <anna/core/oam/CounterScope.hpp>
+#include <anna/core/oam/CounterRecorder.hpp>
#include <anna/core/tracing/Logger.hpp>
#include <anna/core/tracing/TraceWriter.hpp>
#include <anna/core/tracing/TraceMethod.hpp>
#include <anna/core/functions.hpp>
#include <anna/xml/xml.hpp>
-#include <anna/core/oam/CounterManager.hpp>
// Standard
#include <cstdarg>
//----------------------------------------------------------------------- Module
//******************************************************************************
+//------------------------------------------------------------------------------
+//-------------------------------------------------------------- Module::~Module
+//------------------------------------------------------------------------------
+anna::oam::Module::~Module() {
+ for(scope_iterator scope_it = scope_begin(); scope_it != scope_end(); scope_it++)
+ delete (scope(scope_it));
+}
+
+
//------------------------------------------------------------------------------
//----------------------------------------------------------- Module::getScope()
//------------------------------------------------------------------------------
throw anna::RuntimeException("After use of counter registration can't initialize more scope ids!. Do initializations firstly", ANNA_FILE_LOCATION);
// Scope range: 0 - 99
- if(scopeId < 0 || scopeId >= anna::oam::CounterManager::MaxScope) {
+ if(scopeId < 0 || scopeId >= MaxScope) {
std::string msg = "Scope Id must be in range [0 - ";
- msg += anna::functions::asString(anna::oam::CounterManager::MaxScope - 1); // 99
+ msg += anna::functions::asString(MaxScope - 1); // 99
msg += "]";
throw anna::RuntimeException(msg, ANNA_FILE_LOCATION);
}
}
);
const char * c_description = (missingScopeDescription ? getClassName() : description.c_str());
- a_active_counter_scope = &(anna::oam::CounterManager::instantiate().create(scopeId, c_description, true /* reuses */));
+ a_active_counter_scope = new CounterScope(scopeId, c_description);
a_scopes[scopeId] = a_active_counter_scope;
}
}
+//------------------------------------------------------------------------------
+//------------------------------------- Module::RecordingGuard::RecordingGuard()
+//------------------------------------------------------------------------------
+anna::oam::Module::RecordingGuard::RecordingGuard(anna::oam::Module* module) :
+ a_module(module) {
+ module->a_counterRecording = true;
+}
+
+
+//------------------------------------------------------------------------------
+//------------------------------------ Module::RecordingGuard::~RecordingGuard()
+//------------------------------------------------------------------------------
+anna::oam::Module::RecordingGuard::~RecordingGuard() {
+ a_module->a_counterRecording = false;
+}
+
+
+//------------------------------------------------------------------------------
+//----------------------------------------------------- Module::recordCounters()
+//------------------------------------------------------------------------------
+void anna::oam::Module::recordCounters() throw(anna::RuntimeException) {
+ LOGMETHOD(anna::TraceMethod tttm("anna::oam::Module", "recordCounters", ANNA_FILE_LOCATION));
+
+ if(a_counterRecorder == NULL)
+ throw RuntimeException("anna::oam::CounterManager has no counter recorder associated", ANNA_FILE_LOCATION);
+
+ LOGDEBUG(
+ std::string msg("Recording counters | ");
+ msg += a_counterRecorder->asString();
+ anna::Logger::write(Logger::Debug, msg, ANNA_FILE_LOCATION)
+ );
+ RecordingGuard guard(this);
+
+ a_counterRecorder->open();
+ Counter* counter = NULL;
+ CounterScope* cscope = NULL;
+
+ try {
+ for(scope_iterator scope_it = scope_begin(); scope_it != scope_end(); scope_it++) {
+ cscope = scope(scope_it);
+ if(cscope == NULL) continue;
+
+ //CounterScope& counterScope(*scope);
+ //Guard csGuard(counterScope, "oam::CounterScope from oam::CounterManager::record");
+ Guard csGuard(cscope, "oam::CounterScope from oam::CounterManager::record");
+
+ for(register int icounter = 0; icounter < CounterScope::MaxCounter; icounter ++) {
+ Counter* counter = cscope->a_counters [icounter];
+
+ if(counter == NULL)
+ continue;
+
+ if(counter->getValue() == 0)
+ continue;
+
+ a_counterRecorder->apply(*counter);
+ counter->reset();
+ }
+ }
+
+ a_counterRecorder->close();
+ } catch(anna::RuntimeException&) {
+ a_counterRecorder->close();
+ throw;
+ }
+}
+
//------------------------------------------------------------------------------
//----------------------------------------------------------- Module::asString()
//------------------------------------------------------------------------------
return *this;
}
-String& String::operator<< (const Integer64 vv)
+String& String::operator<< (const S64 vv)
throw() {
char aux [32];
sprintf(aux, "%lld", vv);
return *this;
}
-String& String::operator<< (const Unsigned64 vv)
+String& String::operator<< (const U64 vv)
throw() {
char aux [32];
sprintf(aux, "%llu", vv);
*a_value.a_integer = value;
}
-void Variable::setValue(const Integer64 value)
+void Variable::setValue(const S64 value)
throw(RuntimeException) {
verifyMatchType(Type::Integer64, ANNA_FILE_LOCATION);
a_isNull = false;
return *a_value.a_integer;
}
-Integer64 Variable::getInteger64Value() const
+S64 Variable::getInteger64Value() const
throw(RuntimeException) {
int result(0);
verifyIsNotNull(ANNA_FILE_LOCATION);
return anna::xml::Compiler().apply(asXML(&root));
}
-
-/////////////////////
-// FORMAT-SPECIFIC //
-/////////////////////
-
-
-//------------------------------------------------------------------------------
-//---------------------------------------------------- Avp::initializeByFormat()
-//------------------------------------------------------------------------------
-void Avp::initializeByFormat() throw() {
- a_ISDNNumber = NULL;
- a_ISDNAddress = NULL;
- a_Unsigned16 = NULL;
-}
-
-
-//------------------------------------------------------------------------------
-//--------------------------------------------------------- Avp::clearByFormat()
-//------------------------------------------------------------------------------
-void Avp::clearByFormat() throw() {
- delete a_ISDNNumber;
- delete a_ISDNAddress;
- delete a_Unsigned16;
-}
-
-
-//------------------------------------------------------------------------------
-//---------------------------------------------------- Avp::allocationByFormat()
-//------------------------------------------------------------------------------
-void Avp::allocationByFormat(const stack::Format *stackFormat) throw() {
- if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber = new ISDNNumber();
- else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress = new ISDNAddress();
- else if(stackFormat->getName() == "Unsigned16") a_Unsigned16 = new Unsigned16();
-}
-
-
-//------------------------------------------------------------------------------
-//----------------------------------------------------- Avp::getLengthByFormat()
-//------------------------------------------------------------------------------
-U24 Avp::getLengthByFormat(const stack::Format *stackFormat) const throw() {
- U24 result = 0;
-
- if(stackFormat->getName() == "ISDNNumber") result += a_ISDNNumber->getSize();
- else if(stackFormat->getName() == "ISDNAddress") result += a_ISDNAddress->getSize();
- else if(stackFormat->getName() == "Unsigned16") result += a_Unsigned16->getSize();
-
- return result;
-}
-
-
-//------------------------------------------------------------------------------
-//------------------------------------------------ Avp::decodeDataPartByFormat()
-//------------------------------------------------------------------------------
-void Avp::decodeDataPartByFormat(const char * buffer, int size, const stack::Format *stackFormat) throw(anna::RuntimeException) {
- if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber->decode(buffer, size);
- else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress->decode(buffer, size);
- else if(stackFormat->getName() == "Unsigned16") a_Unsigned16->decode(buffer, size);
-}
-
-
-//------------------------------------------------------------------------------
-//---------------------------------------------------------- Avp::codeByFormat()
-//------------------------------------------------------------------------------
-void Avp::codeByFormat(char* dataPart, const stack::Format *stackFormat) const throw(anna::RuntimeException) {
- int dataBytes;
-
- if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber->code(dataPart, dataBytes);
- else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress->code(dataPart, dataBytes);
- else if(stackFormat->getName() == "Unsigned16") a_Unsigned16->code(dataPart, dataBytes);
-}
-
-
-//------------------------------------------------------------------------------
-//---------------------------------------------------- Avp::getXMLdataByFormat()
-//------------------------------------------------------------------------------
-std::string Avp::getXMLdataByFormat(bool & isHex, const stack::Format *stackFormat) const throw() {
- std::string result;
-
- if(stackFormat->getName() == "ISDNNumber") {
- isHex = true;
- return a_ISDNNumber->asHexString();
- } else if(stackFormat->getName() == "ISDNAddress") {
- isHex = true;
- return a_ISDNAddress->asHexString();
- } else if(stackFormat->getName() == "Unsigned16") return a_Unsigned16->asPrintableString();
-
- return result;
-}
-
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------- Avp::fromXMLByFormat()
-//------------------------------------------------------------------------------
-void Avp::fromXMLByFormat(const anna::xml::Attribute* data, const anna::xml::Attribute* hexData, const stack::Format *stackFormat) throw(anna::RuntimeException) {
- if(stackFormat->getName() == "ISDNNumber") {
- if(data) a_ISDNNumber->fromPrintableString(data->getValue().c_str());
- else if(hexData) a_ISDNNumber->fromHexString(hexData->getValue());
- } else if(stackFormat->getName() == "ISDNAddress") {
- if(data) a_ISDNAddress->fromPrintableString(data->getValue().c_str());
- else if(hexData) a_ISDNAddress->fromHexString(hexData->getValue());
- } else if(stackFormat->getName() == "Unsigned16") {
- if(data) a_Unsigned16->fromPrintableString(data->getValue().c_str());
- else if(hexData) a_Unsigned16->fromHexString(hexData->getValue());
- }
-}
-
trace += conceptDescription; trace += " ("; trace += conceptUnitDescription; trace += ")";
if(ptrConceptData->Size != 0) {
- trace += "\n Sample Size: "; trace += anna::functions::asString((anna::Unsigned64)(ptrConceptData->Size));
+ trace += "\n Sample Size: "; trace += anna::functions::asString((anna::U64)(ptrConceptData->Size));
trace += "\n Average: "; trace += anna::functions::asString(fFormat.c_str(), ptrConceptData->Average);
trace += "\n Standard Deviation: "; trace += anna::functions::asString(fFormat.c_str(), getStandardDeviation(ptrConceptData));
anna::xml::Node* data = concept->createChild("Data");
if(ptrConceptData->Size != 0) {
- data->createAttribute("Size", anna::functions::asString((anna::Unsigned64)ptrConceptData->Size));
+ data->createAttribute("Size", anna::functions::asString((anna::U64)ptrConceptData->Size));
data->createAttribute("Average", anna::functions::asString(fFormat.c_str(), ptrConceptData->Average));
data->createAttribute("StandardDeviation", anna::functions::asString(fFormat.c_str(), getStandardDeviation(ptrConceptData)));
#include <limits.h>
#include <anna/config/Release.hpp>
-#include <anna/config/defines.hpp>
+#include <anna/core/util/defines.hpp>
using namespace std;
using namespace anna;
}
BOOST_AUTO_TEST_CASE(numbers) {
- Integer64 ii64;
+ S64 ii64;
ii64 = LLONG_MAX;
BOOST_REQUIRE_EQUAL(ii64, LLONG_MAX);
ii64 = LLONG_MIN;
BOOST_REQUIRE_EQUAL(ii64, LLONG_MIN);
- Unsigned64 u64;
+ U64 u64;
u64 = ULLONG_MAX;
BOOST_REQUIRE_EQUAL(u64, ULLONG_MAX);
}
unsigned long long ull = 4321000111ULL;
sprintf(cad_aux, "%llu", ull);
BOOST_REQUIRE_EQUAL(anna::functions::asString(ull), cad_aux);
- Unsigned64 u64 = ull;
+ U64 u64 = ull;
BOOST_REQUIRE_EQUAL(anna::functions::asString(u64), cad_aux);
unsigned int ui = 1234567890U;
sprintf(cad_aux, "%u", ui);