From: Eduardo Ramos Testillano Date: Thu, 24 Jul 2014 17:53:36 +0000 (+0200) Subject: Remove core-comm dependency through CounterManager/timex in core/oam subsystem. Basic... X-Git-Tag: REFACTORING_TESTING_LIBRARY~250 X-Git-Url: https://git.teslayout.com/public/public/public/?a=commitdiff_plain;h=884501d2411bc4fdfafae65948262c959e068d7d;p=anna.git Remove core-comm dependency through CounterManager/timex in core/oam subsystem. Basic types improvements. Now record period must be managed separately (establish a MyTimer invoking module record()) Integer64 and Unsigned64 disappear, using S64 and U64. --- diff --git a/example/comm/codec/main.cpp b/example/comm/codec/main.cpp index 6369af3..e581405 100644 --- a/example/comm/codec/main.cpp +++ b/example/comm/codec/main.cpp @@ -165,7 +165,7 @@ void Test::run () /* * 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); @@ -185,8 +185,8 @@ void Test::run () 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)); @@ -209,7 +209,7 @@ void Test::run () 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; diff --git a/example/diameter/launcher/main.cpp b/example/diameter/launcher/main.cpp index 17200e8..1f5a2e0 100644 --- a/example/diameter/launcher/main.cpp +++ b/example/diameter/launcher/main.cpp @@ -33,11 +33,6 @@ // 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 #include @@ -86,6 +81,7 @@ namespace diameter { namespace comm { class Entity; class Response; +class LocalServer; } } } @@ -98,8 +94,7 @@ class Response; 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 G_commMessages; // create en el forward de requets sin answer programada -// realease en el forward de answers +anna::Recycler G_commMessages; // create on requests forwards without programmed answer / release in answers forward // Auxiliary resources for answers programming @@ -187,6 +182,7 @@ private: }; +/* class MyCounterRecorder : public anna::oam::CounterRecorder { // pure virtual definitions: @@ -195,7 +191,7 @@ class MyCounterRecorder : public anna::oam::CounterRecorder { void close() throw() {;} std::string asString() const throw() { return "Physical dump not implemented: see memory accumulations writting context (kill -10 )"; } }; - +*/ class Launcher : public anna::comm::Application { @@ -207,7 +203,7 @@ 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; @@ -908,7 +904,7 @@ Launcher::Launcher() : anna::comm::Application("launcher", "DiameterLauncher", " 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"; @@ -1182,7 +1178,7 @@ throw(anna::RuntimeException) { // 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() @@ -1297,10 +1293,10 @@ throw(anna::RuntimeException) { 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(a_counterRecorder)); + //anna::oam::CounterManager& cm = anna::oam::CounterManager::instantiate(); + //cm.setEngine(a_timeEngine); + //cm.setRecordPeriod(Millisecond(300000)); + ////cm.setCounterRecorder(static_cast(a_counterRecorder)); ... will be NULL // Checking command line parameters if (cl.exists("sessionBasedModelsClientSocketSelection")) { diff --git a/example/diameter/tme/SConscript b/example/diameter/tme/SConscript new file mode 100644 index 0000000..01bee90 --- /dev/null +++ b/example/diameter/tme/SConscript @@ -0,0 +1,36 @@ +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') diff --git a/example/diameter/tme/SConstruct b/example/diameter/tme/SConstruct new file mode 100644 index 0000000..3275f35 --- /dev/null +++ b/example/diameter/tme/SConstruct @@ -0,0 +1,8 @@ +Import ('env') + +variant = env ['VARIANT'] + +result = SConscript ('SConscript', exports='env', variant_dir='%s' % variant, duplicate=0) + +Return ('result') + diff --git a/example/diameter/tme/main.cpp b/example/diameter/tme/main.cpp new file mode 100644 index 0000000..567cf8a --- /dev/null +++ b/example/diameter/tme/main.cpp @@ -0,0 +1,155 @@ +// Standard +#include +#include + +// STL +#include + +#include +#include +#include +#include +#include +#include + + +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 += " "; + 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"); +*/ +/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +*/ + + _exit("Open 'file.trace' in order to see the stacks loaded"); +} + diff --git a/example/diameter/tme/setups b/example/diameter/tme/setups new file mode 120000 index 0000000..7a453ef --- /dev/null +++ b/example/diameter/tme/setups @@ -0,0 +1 @@ +../../../source/diameter/stack/setups \ No newline at end of file diff --git a/example/timex/ArithmeticHTTPServer/Context.cpp b/example/timex/ArithmeticHTTPServer/Context.cpp index 21e6eb1..3e45a64 100644 --- a/example/timex/ArithmeticHTTPServer/Context.cpp +++ b/example/timex/ArithmeticHTTPServer/Context.cpp @@ -49,13 +49,13 @@ using namespace anna; using namespace test; http4comm::Context::Context (timex::Engine& timeController, const Millisecond& timeout) : - timex::Context ("http4comm", timeController, timeout) + timex::Context ("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 (timex::Context ::open (id, 0)); + http4comm::Transaction* transaction = static_cast (timex::Context ::open (id, 0)); transaction->setClientSocket (&clientSocket); @@ -96,7 +96,7 @@ void http4comm::Context::releaseTransaction (timex::Transaction* tt) /** * 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); @@ -105,8 +105,8 @@ string http4comm::Context::identifierAsString (const Integer64& id) const /* * 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); } diff --git a/example/timex/ArithmeticHTTPServer/Context.hpp b/example/timex/ArithmeticHTTPServer/Context.hpp index aee3338..ba1c652 100644 --- a/example/timex/ArithmeticHTTPServer/Context.hpp +++ b/example/timex/ArithmeticHTTPServer/Context.hpp @@ -53,11 +53,11 @@ class Transaction; using namespace anna; -class Context : public timex::Context { +class Context : public timex::Context { 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: @@ -66,8 +66,8 @@ 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&); }; diff --git a/example/timex/ArithmeticHTTPServer/Request.hpp b/example/timex/ArithmeticHTTPServer/Request.hpp index 04b5410..bd3ec47 100644 --- a/example/timex/ArithmeticHTTPServer/Request.hpp +++ b/example/timex/ArithmeticHTTPServer/Request.hpp @@ -52,7 +52,7 @@ public: int x; int y; int op; - anna::Integer64 initTime; + anna::S64 initTime; Request () : anna::comm::Codec (Id, false) { attach ("X", x); diff --git a/include/anna/comm/Codec.hpp b/include/anna/comm/Codec.hpp index 9eff773..f556be2 100644 --- a/include/anna/comm/Codec.hpp +++ b/include/anna/comm/Codec.hpp @@ -170,7 +170,7 @@ public: 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 diff --git a/include/anna/comm/CompatCodec.hpp b/include/anna/comm/CompatCodec.hpp index ccc61d3..91a99ba 100644 --- a/include/anna/comm/CompatCodec.hpp +++ b/include/anna/comm/CompatCodec.hpp @@ -239,7 +239,7 @@ public: 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 diff --git a/include/anna/comm/Variable.hpp b/include/anna/comm/Variable.hpp index 3f2a66f..7e8b2db 100644 --- a/include/anna/comm/Variable.hpp +++ b/include/anna/comm/Variable.hpp @@ -83,7 +83,7 @@ public: * @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) {;} diff --git a/include/anna/comm/functions.hpp b/include/anna/comm/functions.hpp index 046b999..f13c252 100644 --- a/include/anna/comm/functions.hpp +++ b/include/anna/comm/functions.hpp @@ -37,8 +37,6 @@ #ifndef anna_comm_functions_hpp #define anna_comm_functions_hpp -#include - #include #include @@ -79,81 +77,6 @@ struct functions : public anna::app::functions { @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(); }; } diff --git a/include/anna/comm/internal/Poll.hpp b/include/anna/comm/internal/Poll.hpp index 401eb62..5410158 100644 --- a/include/anna/comm/internal/Poll.hpp +++ b/include/anna/comm/internal/Poll.hpp @@ -42,6 +42,7 @@ #include #include +#include #include #include diff --git a/include/anna/config/defines.hpp b/include/anna/config/defines.hpp index c832801..aa402be 100644 --- a/include/anna/config/defines.hpp +++ b/include/anna/config/defines.hpp @@ -122,21 +122,11 @@ 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 } diff --git a/include/anna/core/core.hpp b/include/anna/core/core.hpp index 06b3929..80a7acc 100644 --- a/include/anna/core/core.hpp +++ b/include/anna/core/core.hpp @@ -82,7 +82,6 @@ namespace anna {} #include #include #include -#include #include #include #include diff --git a/include/anna/core/functions.hpp b/include/anna/core/functions.hpp index f41d281..177e5be 100644 --- a/include/anna/core/functions.hpp +++ b/include/anna/core/functions.hpp @@ -117,7 +117,7 @@ struct functions { /* * 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. @@ -141,13 +141,13 @@ struct functions { 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. @@ -195,7 +195,7 @@ struct functions { \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); @@ -258,7 +258,7 @@ struct functions { \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. @@ -270,7 +270,7 @@ struct functions { \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. @@ -288,7 +288,7 @@ struct functions { \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); @@ -336,13 +336,13 @@ struct functions { 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. @@ -468,7 +468,7 @@ struct functions { 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. @@ -509,7 +509,7 @@ struct functions { * \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); } @@ -524,7 +524,7 @@ struct functions { * \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. @@ -1033,6 +1033,90 @@ struct functions { */ 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). * @@ -1062,7 +1146,6 @@ struct functions { */ static void codeIsupNumber(const isup_number_t & isupNumber, bool calledOrCalling, std::string & target) throw(RuntimeException); - private: static ExclusiveHash st_stringExclusiveHash; static ExclusiveHash st_string2intExclusiveHash; diff --git a/include/anna/core/oam/Counter.hpp b/include/anna/core/oam/Counter.hpp index 5df966e..d3aad32 100644 --- a/include/anna/core/oam/Counter.hpp +++ b/include/anna/core/oam/Counter.hpp @@ -80,7 +80,7 @@ public: * 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. @@ -111,7 +111,7 @@ private: 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&); diff --git a/include/anna/core/oam/CounterManager.hpp b/include/anna/core/oam/CounterManager.hpp deleted file mode 100644 index e98b253..0000000 --- a/include/anna/core/oam/CounterManager.hpp +++ /dev/null @@ -1,245 +0,0 @@ -// 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 -#include - -#include - -#include -#include - -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 { -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 ; - friend class Timer; - - friend class CounterScope; - // activateTimer - - friend class RecordingGuard; -}; - -} -} - -#endif - diff --git a/include/anna/core/oam/CounterRecorder.hpp b/include/anna/core/oam/CounterRecorder.hpp index b3c9a7c..108160f 100644 --- a/include/anna/core/oam/CounterRecorder.hpp +++ b/include/anna/core/oam/CounterRecorder.hpp @@ -46,14 +46,12 @@ namespace anna { 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: diff --git a/include/anna/core/oam/CounterScope.hpp b/include/anna/core/oam/CounterScope.hpp index 21bca01..96eceb0 100644 --- a/include/anna/core/oam/CounterScope.hpp +++ b/include/anna/core/oam/CounterScope.hpp @@ -51,57 +51,14 @@ namespace xml { 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 */ @@ -118,18 +75,11 @@ public: 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. @@ -184,7 +134,7 @@ public: * 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. @@ -193,22 +143,20 @@ public: 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; }; } diff --git a/include/anna/core/oam/CounterSummarizer.hpp b/include/anna/core/oam/CounterSummarizer.hpp deleted file mode 100644 index 2fbb6ca..0000000 --- a/include/anna/core/oam/CounterSummarizer.hpp +++ /dev/null @@ -1,71 +0,0 @@ -// 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 - -#include - -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 - diff --git a/include/anna/core/oam/Module.hpp b/include/anna/core/oam/Module.hpp index 2f0bbe6..4999d1e 100644 --- a/include/anna/core/oam/Module.hpp +++ b/include/anna/core/oam/Module.hpp @@ -57,6 +57,7 @@ class Node; } namespace oam { class CounterScope; +class CounterRecorder; } } @@ -206,7 +207,16 @@ class Module { 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; @@ -223,21 +233,25 @@ class Module { 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(); /** @@ -435,6 +449,22 @@ public: 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) @@ -499,6 +529,9 @@ protected: * @param components Alarm suffix components defined by oam module. Empty on default implementation. */ virtual void readAlarmSuffixComponents(std::vector & components) const throw() {;} + + + friend class RecordingGuard; }; } diff --git a/include/anna/core/util/Microsecond.hpp b/include/anna/core/util/Microsecond.hpp index ceee065..96fbf7b 100644 --- a/include/anna/core/util/Microsecond.hpp +++ b/include/anna/core/util/Microsecond.hpp @@ -39,7 +39,7 @@ #include -#include +#include #include namespace anna { @@ -49,7 +49,7 @@ class Second; class Microsecond { public: - typedef Integer64 type_t; + typedef S64 type_t; /** * Constructor diff --git a/include/anna/core/util/Millisecond.hpp b/include/anna/core/util/Millisecond.hpp index 8a32ede..341649c 100644 --- a/include/anna/core/util/Millisecond.hpp +++ b/include/anna/core/util/Millisecond.hpp @@ -41,7 +41,7 @@ #include -#include +#include #include namespace anna { @@ -51,7 +51,7 @@ class Microsecond; class Millisecond { public: - typedef Integer64 type_t; + typedef S64 type_t; /** * Constructor diff --git a/include/anna/core/util/Second.hpp b/include/anna/core/util/Second.hpp index 89fc062..546303e 100644 --- a/include/anna/core/util/Second.hpp +++ b/include/anna/core/util/Second.hpp @@ -53,7 +53,7 @@ class Microsecond; class Second { public: #ifdef __anna64__ - typedef Integer64 type_t; + typedef S64 type_t; #else typedef int type_t; #endif diff --git a/include/anna/core/util/String.hpp b/include/anna/core/util/String.hpp index 9e20a36..db6a23c 100644 --- a/include/anna/core/util/String.hpp +++ b/include/anna/core/util/String.hpp @@ -41,7 +41,7 @@ #include -#include +#include namespace anna { @@ -103,8 +103,8 @@ public: 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; } @@ -114,8 +114,8 @@ public: 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; } @@ -125,8 +125,8 @@ public: 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; } @@ -177,7 +177,7 @@ public: * \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"); diff --git a/include/anna/core/util/TextVariable.hpp b/include/anna/core/util/TextVariable.hpp index bf7336b..b6017e4 100644 --- a/include/anna/core/util/TextVariable.hpp +++ b/include/anna/core/util/TextVariable.hpp @@ -73,7 +73,7 @@ public: * 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. diff --git a/include/anna/core/util/Variable.hpp b/include/anna/core/util/Variable.hpp index 582bd83..3637263 100644 --- a/include/anna/core/util/Variable.hpp +++ b/include/anna/core/util/Variable.hpp @@ -37,11 +37,11 @@ #ifndef anna_core_util_Variable_hpp #define anna_core_util_Variable_hpp -#include +#include #include #include #include -#include +#include namespace anna { @@ -109,7 +109,7 @@ public: * @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), @@ -241,7 +241,7 @@ public: @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. @@ -307,7 +307,7 @@ public: 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. @@ -368,7 +368,7 @@ public: * * @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. @@ -422,7 +422,7 @@ public: 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. @@ -489,7 +489,7 @@ private: union { std::string* a_string; int* a_integer; - Integer64* a_longInteger; + S64* a_longInteger; bool* a_boolean; DataBlock* a_dataBlock; float* a_float; @@ -498,7 +498,7 @@ private: } a_value; struct { int integer; - Integer64 longInteger; + S64 longInteger; bool boolean; float theFloat; double theDouble; diff --git a/include/anna/core/util/defines.hpp b/include/anna/core/util/defines.hpp index 066dd15..536013f 100644 --- a/include/anna/core/util/defines.hpp +++ b/include/anna/core/util/defines.hpp @@ -112,11 +112,24 @@ typedef unsigned int U32; /** 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; diff --git a/include/anna/dbos/defines.hpp b/include/anna/dbos/defines.hpp index 3abfc5f..3aa56c4 100644 --- a/include/anna/dbos/defines.hpp +++ b/include/anna/dbos/defines.hpp @@ -43,7 +43,7 @@ namespace anna { namespace dbos { typedef unsigned int Size; -typedef Unsigned64 Index; +typedef U64 Index; typedef ptrnumber StorageId; typedef unsigned int Counter; } diff --git a/include/anna/diameter.comm/comm.hpp b/include/anna/diameter.comm/comm.hpp index 2e565bb..b8d1883 100644 --- a/include/anna/diameter.comm/comm.hpp +++ b/include/anna/diameter.comm/comm.hpp @@ -63,7 +63,6 @@ El ejecutable debera enlazarse con las modulos: #include #include #include -#include #include #include #include diff --git a/include/anna/diameter/codec/Avp.hpp b/include/anna/diameter/codec/Avp.hpp index cd6c100..77ae9fb 100644 --- a/include/anna/diameter/codec/Avp.hpp +++ b/include/anna/diameter/codec/Avp.hpp @@ -43,7 +43,6 @@ #include #include #include -#include #include @@ -70,17 +69,6 @@ namespace anna { namespace diameter { -namespace helpers { -namespace tme { -namespace codectypes { -class Unsigned16; -class ISDNNumber; -class ISDNAddress; -} -} -} - - namespace stack { class Dictionary; class Format; @@ -124,7 +112,6 @@ typedef std::map::iterator find_iterator; using namespace basetypes; -using namespace helpers::tme::codectypes; /** * Diameter avp generic container @@ -201,14 +188,6 @@ class Avp { 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 @@ -250,7 +229,6 @@ class Avp { 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; } @@ -293,80 +271,80 @@ class Avp { /** * 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() {}; @@ -383,6 +361,10 @@ protected: */ 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. @@ -574,15 +556,6 @@ public: /** 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. @@ -714,16 +687,6 @@ public: 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 /** diff --git a/include/anna/diameter/codec/Message.hpp b/include/anna/diameter/codec/Message.hpp index 874752b..7600b6e 100644 --- a/include/anna/diameter/codec/Message.hpp +++ b/include/anna/diameter/codec/Message.hpp @@ -202,9 +202,12 @@ public: * 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 diff --git a/include/anna/diameter/codec/basetypes/Integer64.hpp b/include/anna/diameter/codec/basetypes/Integer64.hpp index b2090b8..c5f1322 100644 --- a/include/anna/diameter/codec/basetypes/Integer64.hpp +++ b/include/anna/diameter/codec/basetypes/Integer64.hpp @@ -41,7 +41,7 @@ // Local #include -#include +#include namespace anna { @@ -97,7 +97,7 @@ public: // 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) { diff --git a/include/anna/diameter/codec/basetypes/Unsigned64.hpp b/include/anna/diameter/codec/basetypes/Unsigned64.hpp index e650dd7..15a903d 100644 --- a/include/anna/diameter/codec/basetypes/Unsigned64.hpp +++ b/include/anna/diameter/codec/basetypes/Unsigned64.hpp @@ -41,7 +41,7 @@ // Local #include -#include +#include namespace anna { @@ -97,7 +97,7 @@ public: // 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) { diff --git a/include/anna/diameter/codec/tme/Avp.hpp b/include/anna/diameter/codec/tme/Avp.hpp index 596c845..e6d5604 100644 --- a/include/anna/diameter/codec/tme/Avp.hpp +++ b/include/anna/diameter/codec/tme/Avp.hpp @@ -123,6 +123,24 @@ public: ~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; }; diff --git a/include/anna/xml/Node.hpp b/include/anna/xml/Node.hpp index fd74c78..91288c5 100644 --- a/include/anna/xml/Node.hpp +++ b/include/anna/xml/Node.hpp @@ -310,7 +310,7 @@ public: \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); } @@ -322,7 +322,7 @@ public: \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); } diff --git a/source/comm/Codec.cpp b/source/comm/Codec.cpp index 03992bf..acbda00 100644 --- a/source/comm/Codec.cpp +++ b/source/comm/Codec.cpp @@ -55,6 +55,6 @@ throw(RuntimeException) { 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()); } diff --git a/source/comm/Communicator.cpp b/source/comm/Communicator.cpp index c89b6aa..0e85efd 100644 --- a/source/comm/Communicator.cpp +++ b/source/comm/Communicator.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include diff --git a/source/comm/CompatCodec.cpp b/source/comm/CompatCodec.cpp index 1243fb6..6d0c5a1 100644 --- a/source/comm/CompatCodec.cpp +++ b/source/comm/CompatCodec.cpp @@ -120,9 +120,9 @@ throw(RuntimeException) { 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; @@ -287,7 +287,7 @@ throw(RuntimeException) { 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; @@ -317,7 +317,7 @@ throw(RuntimeException) { 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) @@ -440,7 +440,7 @@ throw(RuntimeException) { 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); @@ -515,7 +515,7 @@ throw(RuntimeException) { 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); diff --git a/source/comm/functions.cpp b/source/comm/functions.cpp index f510c4f..244b663 100644 --- a/source/comm/functions.cpp +++ b/source/comm/functions.cpp @@ -131,97 +131,3 @@ if(host->h_aliases[0] != NULL) { 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; -} diff --git a/source/core/functions.cpp b/source/core/functions.cpp index 1252701..b67d127 100644 --- a/source/core/functions.cpp +++ b/source/core/functions.cpp @@ -121,10 +121,10 @@ throw() { 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); @@ -144,7 +144,7 @@ throw() { return string(aux); } -string functions::asString(const Unsigned64 number) +string functions::asString(const U64 number) throw() { char aux [16]; sprintf(aux, "%llu", number); @@ -203,10 +203,10 @@ throw() { 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); @@ -222,14 +222,14 @@ throw() { // 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 ++; @@ -343,9 +343,9 @@ throw(RuntimeException) { 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__ @@ -393,7 +393,7 @@ throw(RuntimeException) { } /*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)); @@ -410,7 +410,7 @@ throw(RuntimeException) { throw RuntimeException(msg, ANNA_FILE_LOCATION); } - Integer64 result = n1; + S64 result = n1; result <<= bitShift; result |= n2; @@ -1331,6 +1331,109 @@ std::string functions::socketVectorAsString(const socket_v & socketVector) throw 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)) diff --git a/source/core/oam/Counter.cpp b/source/core/oam/Counter.cpp index fb9f53f..80a28ce 100644 --- a/source/core/oam/Counter.cpp +++ b/source/core/oam/Counter.cpp @@ -35,7 +35,9 @@ #include -#include +#include +#include +#include using namespace std; using namespace anna; @@ -76,3 +78,4 @@ throw() { result += functions::asString(a_accValue); return result += " }"; } + diff --git a/source/core/oam/CounterManager.cpp b/source/core/oam/CounterManager.cpp deleted file mode 100644 index 3ba98d1..0000000 --- a/source/core/oam/CounterManager.cpp +++ /dev/null @@ -1,241 +0,0 @@ -// 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 -#include - -#include -#include - -#include - -#include -#include -#include - - -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 (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(); - } -} diff --git a/source/core/oam/CounterScope.cpp b/source/core/oam/CounterScope.cpp index 56d6995..c5ac214 100644 --- a/source/core/oam/CounterScope.cpp +++ b/source/core/oam/CounterScope.cpp @@ -43,7 +43,6 @@ #include -#include #include #include @@ -105,7 +104,6 @@ throw(RuntimeException) { 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; } @@ -116,7 +114,6 @@ throw(RuntimeException) { a_counters [counter]->a_value = value; a_counters [counter]->a_accValue = value; LOGINFORMATION(a_counters [counter]->debug()); - a_counterManager.activateTimer(); return value; } @@ -127,7 +124,7 @@ throw(RuntimeException) { 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); @@ -179,25 +176,3 @@ throw(RuntimeException) { 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]; -} - diff --git a/source/core/oam/Handler.cpp b/source/core/oam/Handler.cpp index 51e7906..341f5c5 100644 --- a/source/core/oam/Handler.cpp +++ b/source/core/oam/Handler.cpp @@ -37,13 +37,13 @@ // Local #include #include +#include #include #include #include #include #include -#include // Standard #include @@ -114,8 +114,10 @@ const anna::oam::counter_data_t *anna::oam::Handler::counterEvent(const anna::oa 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 (module->getActiveCounterScope()); + nc_cs->increment(result->Offset, amount); + } LOGDEBUG ( diff --git a/source/core/oam/Module.cpp b/source/core/oam/Module.cpp index 341ed8c..99b47c9 100644 --- a/source/core/oam/Module.cpp +++ b/source/core/oam/Module.cpp @@ -38,13 +38,14 @@ #include #include #include +#include +#include #include #include #include #include #include -#include // Standard #include @@ -57,6 +58,15 @@ //----------------------------------------------------------------------- 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() //------------------------------------------------------------------------------ @@ -251,9 +261,9 @@ void anna::oam::Module::initializeCounterScope(const int & scopeId, const std::s 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); } @@ -275,7 +285,7 @@ void anna::oam::Module::initializeCounterScope(const int & scopeId, const std::s } ); 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; } @@ -493,6 +503,73 @@ int anna::oam::Module::resetCounters(const int & scopeId) throw() { } +//------------------------------------------------------------------------------ +//------------------------------------- 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() //------------------------------------------------------------------------------ diff --git a/source/core/util/String.cpp b/source/core/util/String.cpp index b066c3e..fc87b41 100644 --- a/source/core/util/String.cpp +++ b/source/core/util/String.cpp @@ -82,7 +82,7 @@ throw() { return *this; } -String& String::operator<< (const Integer64 vv) +String& String::operator<< (const S64 vv) throw() { char aux [32]; sprintf(aux, "%lld", vv); @@ -97,7 +97,7 @@ throw() { return *this; } -String& String::operator<< (const Unsigned64 vv) +String& String::operator<< (const U64 vv) throw() { char aux [32]; sprintf(aux, "%llu", vv); diff --git a/source/core/util/Variable.cpp b/source/core/util/Variable.cpp index f8da926..f55ffb5 100644 --- a/source/core/util/Variable.cpp +++ b/source/core/util/Variable.cpp @@ -93,7 +93,7 @@ throw(RuntimeException) { *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; @@ -162,7 +162,7 @@ throw(RuntimeException) { return *a_value.a_integer; } -Integer64 Variable::getInteger64Value() const +S64 Variable::getInteger64Value() const throw(RuntimeException) { int result(0); verifyIsNotNull(ANNA_FILE_LOCATION); diff --git a/source/diameter/codec/Avp.cpp b/source/diameter/codec/Avp.cpp index 59cc6d7..536584f 100644 --- a/source/diameter/codec/Avp.cpp +++ b/source/diameter/codec/Avp.cpp @@ -1579,109 +1579,3 @@ std::string Avp::asXMLString() const throw() { 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()); - } -} - diff --git a/source/statistics/Accumulator.cpp b/source/statistics/Accumulator.cpp index 9600b6e..efd319a 100644 --- a/source/statistics/Accumulator.cpp +++ b/source/statistics/Accumulator.cpp @@ -341,7 +341,7 @@ std::string Accumulator::asString(const int & numberOfDecimals) const throw() { 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)); @@ -433,7 +433,7 @@ anna::xml::Node* Accumulator::asXML(anna::xml::Node* parent, const int & numberO 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))); diff --git a/test/config/main.cpp b/test/config/main.cpp index a287136..0eb3ad0 100644 --- a/test/config/main.cpp +++ b/test/config/main.cpp @@ -43,7 +43,7 @@ #include #include -#include +#include using namespace std; using namespace anna; @@ -65,12 +65,12 @@ BOOST_AUTO_TEST_CASE(release) { } 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); } diff --git a/test/core/main.cpp b/test/core/main.cpp index 8734a8d..6a84c3a 100644 --- a/test/core/main.cpp +++ b/test/core/main.cpp @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(functions_asString) { 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);