bool processHex = xmlOnly ? false:true;
Logger::setLevel(debug ? Logger::Debug:Logger::Warning);
Logger::initialize(execBN.c_str(), new TraceWriter(filetrace.c_str(), 2048000));
- G_codecEngine = new anna::diameter::codec::Engine();
+ G_codecEngine = new anna::diameter::codec::Engine("MyCodecEngine");
G_codecMsg = G_codecEngine->createMessage();
anna::diameter::stack::Engine &stackEngine = anna::diameter::stack::Engine::instantiate();
#define SIGUSR2_TASKS_INPUT_FILENAME "./sigusr2.tasks.input"
#define SIGUSR2_TASKS_OUTPUT_FILENAME "./sigusr2.tasks.output"
-
+#define DIAMETER_CODEC_ENGINE_NAME_PREFIX "MyCodecEngine"
Launcher::Launcher() : anna::comm::Application("launcher", "DiameterLauncher", "1.1"), a_communicator(NULL) {
a_myDiameterEngine = new MyDiameterEngine();
//ServerSocket *createServerSocket(const std::string & addr, int port = Session::DefaultPort, int maxConnections = -1, int category = 1, const std::string & description = "")
a_diameterLocalServer = (MyLocalServer*)(a_myDiameterEngine->createLocalServer(address, port, diameterServerSessions));
a_diameterLocalServer->setDescription("Launcher diameter local server");
+ a_diameterLocalServer->setProgrammedAnswersCodecEngine(getCodecEngine());
int allowedInactivityTime = 90000; // ms
if(cl.exists("allowedInactivityTime")) allowedInactivityTime = cl.getIntegerValue("allowedInactivityTime");
}
// Stack:
- anna::diameter::codec::Engine *codecEngine = new anna::diameter::codec::Engine();
+ a_codecEngine = new anna::diameter::codec::Engine(DIAMETER_CODEC_ENGINE_NAME_PREFIX);
anna::diameter::stack::Engine &stackEngine = anna::diameter::stack::Engine::instantiate();
anna::diameter::stack::Dictionary * d = stackEngine.createDictionary(0 /* stack id; its value don't mind, is not used (ADL is monostack) */);
// Analyze comma-separated list:
}
}
- codecEngine->setDictionary(d);
- LOGDEBUG(anna::Logger::debug(codecEngine->asString(), ANNA_FILE_LOCATION));
+ getCodecEngine()->setDictionary(d);
+ LOGDEBUG(anna::Logger::debug(getCodecEngine()->asString(), ANNA_FILE_LOCATION));
if(lst.size() > 1) {
std::string all_in_one = "./dictionary-all-in-one.xml";
// Integration (validation 'Complete' for receiving messages) and debugging (validation also before encoding: 'Always').
// If missing 'integrationAndDebugging', default behaviour at engine is: mode 'AfterDecoding', depth 'FirstError':
if(cl.exists("integrationAndDebugging")) {
- codecEngine->setValidationMode(anna::diameter::codec::Engine::ValidationMode::Always);
- codecEngine->setValidationDepth(anna::diameter::codec::Engine::ValidationDepth::Complete);
+ getCodecEngine()->setValidationMode(anna::diameter::codec::Engine::ValidationMode::Always);
+ getCodecEngine()->setValidationDepth(anna::diameter::codec::Engine::ValidationDepth::Complete);
}
// Fix mode
else if (fixMode == "Always") fm = anna::diameter::codec::Engine::FixMode::Always;
else if (fixMode == "Never") fm = anna::diameter::codec::Engine::FixMode::Never;
else LOGINFORMATION(anna::Logger::information("Unreconized command-line fix mode. Assumed default 'BeforeEncoding'", ANNA_FILE_LOCATION));
- codecEngine->setFixMode(fm);
+ getCodecEngine()->setFixMode(fm);
}
- codecEngine->ignoreFlagsOnValidation(cl.exists("ignoreFlags"));
+ getCodecEngine()->ignoreFlagsOnValidation(cl.exists("ignoreFlags"));
// Diameter Server:
if(cl.exists("diameterServer"))
a_entity = (MyDiameterEntity*)(a_myDiameterEngine->createEntity(servers, "Launcher diameter entity"));
a_entity->setClassCodeTimeout(anna::diameter::comm::ClassCode::Bind, ceaTimeout);
a_entity->setClassCodeTimeout(anna::diameter::comm::ClassCode::ApplicationMessage, answersTimeout);
+ a_entity->setProgrammedAnswersCodecEngine(getCodecEngine());
a_entity->bind();
}
}
} else if (param1 == "dump") {
localServer->getReactingAnswers()->dump();
} else {
- anna::diameter::codec::Engine *engine = anna::functions::component <Engine> (ANNA_FILE_LOCATION);
- anna::diameter::codec::Message *message = engine->createMessage(param1);
+ anna::diameter::codec::Message *message = getCodecEngine()->createMessage(param1);
LOGDEBUG
(
anna::Logger::debug(message->asXMLString(), ANNA_FILE_LOCATION);
} else if (param1 == "dump") {
entity->getReactingAnswers()->dump();
} else {
- anna::diameter::codec::Engine *engine = anna::functions::component <Engine> (ANNA_FILE_LOCATION);
- anna::diameter::codec::Message *message = engine->createMessage(param1);
+ anna::diameter::codec::Message *message = getCodecEngine()->createMessage(param1);
LOGDEBUG
(
anna::Logger::debug(message->asXMLString(), ANNA_FILE_LOCATION);
result->createAttribute("StartTime", a_start_time.asString());
result->createAttribute("SecondsLifeTime", anna::time::functions::lapsedMilliseconds() / 1000);
// Diameter:
- (anna::functions::component <anna::diameter::codec::Engine> (ANNA_FILE_LOCATION))->asXML(result);
+ getCodecEngine()->asXML(result);
// OAM:
anna::diameter::comm::OamModule::instantiate().asXML(result);
anna::diameter::comm::ApplicationMessageOamModule::instantiate().asXML(result);
MyCommunicator *a_communicator;
MyDiameterEngine *a_myDiameterEngine;
MyDiameterEntity *a_entity;
+ anna::diameter::codec::Engine *a_codecEngine;
std::string a_logFile, a_burstLogFile;
std::ofstream a_burstLogStream;
bool a_splitLog, a_detailedLog, a_dumpLog;
public:
Launcher();
+ anna::diameter::codec::Engine *getCodecEngine() const throw() { return a_codecEngine; }
MyCommunicator *getCommunicator() throw() { return a_communicator; }
MyDiameterEngine* getMyDiameterEngine() const throw() { return (a_myDiameterEngine); }
void baseProtocolSetupAsClient(void) throw(anna::RuntimeException);
class MyDiameterEngine : public anna::diameter::comm::Engine {
public:
- static const char* getClassName() throw() { return "launcher::MyDiameterEngine"; }
- MyDiameterEngine() {;}
+ MyDiameterEngine(const char *className = "MyDiameterEngine") : Engine(className) {;}
// Default implementation is enough
// void readDPA(anna::DataBlock &dpa, const anna::DataBlock & dpr) throw() {;} // DPA is not replied
// Process
#include "ProgrammedAnswers.hpp"
+namespace anna {
+ namespace diameter {
+ namespace codec {
+ class Engine;
+ }
+ }
+}
class MyDiameterEntity : public anna::diameter::comm::Entity {
public:
ProgrammedAnswers a_reactingAnswers;
+ void setProgrammedAnswersCodecEngine(anna::diameter::codec::Engine *codecEngine) throw() { a_reactingAnswers.setCodecEngine(codecEngine); }
ProgrammedAnswers *getReactingAnswers() throw() { return (ProgrammedAnswers *)&a_reactingAnswers; }
};
} else return; // nothing done
}
- anna::diameter::codec::Engine *codecEngine = (anna::functions::component <anna::diameter::codec::Engine> (ANNA_FILE_LOCATION));
+ anna::diameter::codec::Engine *codecEngine = my_app.getCodecEngine();
anna::diameter::codec::Engine::ValidationMode::_v backupVM = codecEngine->getValidationMode();
if(!analysisOK)
// Process
#include "ProgrammedAnswers.hpp"
+namespace anna {
+ namespace diameter {
+ namespace codec {
+ class Engine;
+ }
+ }
+}
class MyLocalServer : public anna::diameter::comm::LocalServer {
public:
ProgrammedAnswers a_reactingAnswers;
+ void setProgrammedAnswersCodecEngine(anna::diameter::codec::Engine *codecEngine) throw() { a_reactingAnswers.setCodecEngine(codecEngine); }
ProgrammedAnswers *getReactingAnswers() throw() { return (ProgrammedAnswers *)&a_reactingAnswers; }
};
void ProgrammedAnswers::clear () throw() {
for (reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) {
- anna::diameter::codec::Engine *engine = anna::functions::component <Engine> (ANNA_FILE_LOCATION);
- engine->releaseMessage(*(it->second->begin()));
+ a_codecEngine->releaseMessage(*(it->second->begin()));
delete(it->second);
}
a_deques.clear();
reacting_answers_const_iterator it = a_deques.find(code);
if (it != a_deques.end()) {
if (!it->second->empty()) {
- anna::diameter::codec::Engine *engine = anna::functions::component <Engine> (ANNA_FILE_LOCATION);
if (a_rotate) {
addMessage(code, *(it->second->begin()));
}
else {
- engine->releaseMessage(*(it->second->begin()));
+ a_codecEngine->releaseMessage(*(it->second->begin()));
}
it->second->pop_front();
}
aux += "', Rotation ";
aux += a_rotate ? "enabled":"disabled";
result += anna::functions::highlightJustify(aux);
+ result += "Codec engine: ";
+ result += a_codecEngine->getClassName();
if(a_deques.size() != 0) {
for(reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) {
if (it->second->size() != 0) {
namespace diameter {
namespace codec {
class Message;
+ class Engine;
}
}
}
reacting_answers_container a_deques;
bool a_rotate;
+ anna::diameter::codec::Engine *a_codecEngine;
public:
ProgrammedAnswers() { a_rotate = false; }
~ProgrammedAnswers() { clear(); }
+ void setCodecEngine(anna::diameter::codec::Engine *codecEngine) throw() { a_codecEngine = codecEngine; }
bool rotate() const throw() { return a_rotate; }
void rotate(bool r) throw() { a_rotate = r; }
*/
static Application& getApp() throw(RuntimeException);
- /**
- Patron para obtener facilmente la instancia de un determinado componente.
- Estos dos parametros suelen ser sustituidos por la macro C <b>FILE_LOCATION</b>.
-
- \param fromFile Fichero desde el que se invoca a este metodo
- \param fromLine Numero de linea desde el que se invoca a este metodo.
-
- \return La instancia del componente de la clase recibida como parametro.
- \warning La clase T de implementar un metodo de la forma:
- \code
- static const char* getClassName () throw ();
- \endcode
- \see Component
- */
- template <typename T> static T* component(const char* fromFile, const int fromLine)
- throw(anna::RuntimeException) {
- return component<T> (T::getClassName(), fromFile, fromLine);
- }
/**
- Patron para obtener facilmente la instancia de un determinado componente.
- Estos dos parametros suelen ser sustituidos por la macro C <b>FILE_LOCATION</b>.
- \param className Nombre del componente buscado.
- \param fromFile Fichero desde el que se invoca a este metodo
- \param fromLine Numero de linea desde el que se invoca a este metodo.
+ Pattern to obtain a multi named application component instance easily.
+ Parameters are usually replaced by the macro C <b>FILE_LOCATION</b>.
+
+ \param className Application component class name
+ \param fromFile File which called the method
+ \param fromLine Line number within the file from where the method is called.
- \return La instancia del componente de la clase recibida como parametro.
+ \return Application component instance for the class provided at the pattern
\see Component
*/
- template <typename T> static T* component(const char* className, const char* fromFile, const int fromLine)
+ template <typename T> static T* componentByName(const char *className, const char* fromFile, const int fromLine)
throw(anna::RuntimeException) {
T* result = static_cast <T*>(functions::getApp().find(className));
}
};
+ /**
+ Pattern to obtain a single named application component instance easily.
+ Parameters are usually replaced by the macro C <b>FILE_LOCATION</b>.
+
+ \param fromFile File which called the method
+ \param fromLine Line number within the file from where the method is called.
+
+ \return Application component instance for the class provided at the pattern
+ \warning T class must implement a method in the form:
+ \code
+ static const char* getClassName () throw ();
+ \endcode
+ \see Component
+ */
+ template <typename T> static T* component(const char* fromFile, const int fromLine)
+ throw(RuntimeException) {
+ return functions::componentByName<T> (T::getClassName(), fromFile, fromLine);
+ }
+
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
/**
- Pattern to obtain a component instance easily.
+ Pattern to obtain a multi named component instance easily.
Parameters are usually replaced by the macro C <b>FILE_LOCATION</b>.
+ \param className Component class name
\param fromFile File which called the method
\param fromLine Line number within the file from where the method is called.
\return Component instance for the class provided at the pattern
- \warning The class T must define:
- \code
- static const char* getClassName () throw ();
- \endcode
\see Component
*/
- template <typename T> static T* component(const char* fromFile, const int fromLine)
+ template <typename T> static T* componentByName(const char *className, const char* fromFile, const int fromLine)
throw(RuntimeException) {
ComponentManager &cm = ComponentManager::instantiate();
- const char *className = T::getClassName();
T* result = static_cast <T*>(cm.find(className));
if(result == NULL) {
std::string msg(className);
- msg += " | Componente no registrado";
+ msg += " | Unregistered component";
throw RuntimeException(msg, fromFile, fromLine);
}
return result;
}
+ /**
+ Pattern to obtain a single named component instance easily.
+ Parameters are usually replaced by the macro C <b>FILE_LOCATION</b>.
+
+ \param fromFile File which called the method
+ \param fromLine Line number within the file from where the method is called.
+
+ \return Component instance for the class provided at the pattern
+ \warning T class must implement a method in the form:
+ \code
+ static const char* getClassName () throw ();
+ \endcode
+ \see Component
+ */
+ template <typename T> static T* component(const char* fromFile, const int fromLine)
+ throw(RuntimeException) {
+ return functions::componentByName<T> (T::getClassName(), fromFile, fromLine);
+ }
+
+
/**
* Gets exclusive hash for string provided on integer range
*
public:
static const char* defaultSection;
- /**
- Constructor.
- \param className Nombre de la clase usado para registrar en la lista de componentes.
- */
- Configuration(const char* className) {;}
-
/**
Constructor.
*/
\return La cadena por la que podemos buscar el componente.
\see Application::find
*/
- static const char* getClassName() { return "dbms::mysql::Database"; }
+ static const char* getClassName() { return "anna::dbms::mysql::Database"; }
private:
char* a_host;
class Engine : public anna::app::Component {
public:
- /**
- Logical name for this anna::app::Component.
- \return Logical name for this anna::app::Component.
- */
- static const char* getClassName() throw() { return "anna::diameter::comm::Engine"; }
-
/**
Diameter application node realm name (used to be the site domain name).
protected:
/**
Constructor.
+ @param className Component class name
*/
- Engine();
+ Engine(const char *className);
// INTERNAL CREATORS AND CLOSE METHODS
Avp(AvpId id);
+ /** Sets the codec engine */
+ void setEngine(Engine *engine) throw() { a_engine = engine; }
+
+
// Length references
static const int HeaderLengthVactive;
static const int HeaderLengthVinactive;
public:
- static const char* getClassName() throw() { return "anna::diameter::codec::Engine"; }
-
- Engine() : EngineImpl(getClassName()) {;}
+ /**
+ Constructor
+ @param className Logical name for the class.
+ */
+ Engine(const char *className) : EngineImpl(className) {;}
void releaseAvp(Avp* avp) throw() {
if(avp == NULL) return;
*
* class MyEngine : public EngineImpl {
* public:
- * Engine (getClassName()) {;}
- * static const char* getClassName() throw() { return "<full-naming path>::MyEngine"; }
+ * MyEngine (const char *className = "MyEngine") : Engine(className) {;}
*
* private:
* anna::Recycler<MyAvp> a_avps;
Message(CommandId id);
+ /** Sets the codec engine */
+ void setEngine(Engine *engine) throw() { a_engine = engine; }
+
+
// Length references
static const int HeaderLength;
public:
- static const char* getClassName() throw() { return "anna::diameter::codec::tme::Engine"; }
-
- Engine() : EngineImpl(getClassName()) {;}
+ /**
+ Constructor
+ @param className Logical name for the class.
+ */
+ Engine(const char *className = "anna::diameter::codec::tme::Engine") : EngineImpl(className) {;}
void releaseAvp(anna::diameter::codec::Avp* avp) throw() {
if(avp == NULL) return;
app::Component* app::Application::find(const char* className)
throw() {
Component* component;
-
for(iterator ii = begin(), maxii = end(); ii != maxii; ii ++) {
component = Application::component(ii);
using namespace anna::diameter::comm;
-Engine::Engine() :
- anna::app::Component(getClassName()),
+Engine::Engine(const char *className) :
+ anna::app::Component(className),
a_autoBind(true),
a_availableForEntities(false),
a_availableForLocalServers(false),
//------------------------------------------------------------- Avp::getEngine()
//------------------------------------------------------------------------------
Engine * Avp::getEngine() const throw(anna::RuntimeException) {
- return a_engine ? a_engine : (a_engine = anna::functions::component <Engine> (ANNA_FILE_LOCATION));
+ if(!a_engine)
+ throw anna::RuntimeException("Invalid codec engine reference (NULL)", ANNA_FILE_LOCATION);
+
+ return a_engine;
}
//------------------------------------------------------------ Avp::initialize()
//------------------------------------------------------------------------------
void Avp::initialize() throw() {
- a_engine = NULL;
a_id = helpers::AVPID__AVP; // (0,0)
a_flags = 0x00;
a_insertionPositionForChilds = 0;
if((result = allocateAvp()) == NULL)
throw anna::RuntimeException("diameter::codec::EngineImpl::allocateAvp returns NULL", ANNA_FILE_LOCATION);
+ // Sets engine
+ result->setEngine((Engine*)this);
+
//result->clear(); better clear this at releaseAvp(), see class-help implementation example
if(id) result->setId(*id);
if((result = allocateMessage()) == NULL)
throw anna::RuntimeException("diameter::codec::EngineImpl::allocateMessage returns NULL", ANNA_FILE_LOCATION);
+ // Sets engine
+ result->setEngine((Engine*)this);
+
//result->clear(); better clear this at releaseMessage(), see class-help implementation example
if(id) result->setId(*id);
//--------------------------------------------------------- Message::getEngine()
//------------------------------------------------------------------------------
Engine * Message::getEngine() const throw(anna::RuntimeException) {
- return a_engine ? a_engine : (a_engine = anna::functions::component <Engine> (ANNA_FILE_LOCATION));
+ if(!a_engine)
+ throw anna::RuntimeException("Invalid codec engine reference (NULL)", ANNA_FILE_LOCATION);
+
+ return a_engine;
+
}
//-------------------------------------------------------- Message::initialize()
//------------------------------------------------------------------------------
void Message::initialize() throw() {
- a_engine = NULL;
a_version = 1;
a_id = CommandId(0, false);
a_flags = 0x00;
//------------------------------------------------------------- Avp::getEngine()
//------------------------------------------------------------------------------
anna::diameter::codec::Engine * Avp::getEngine() const throw(anna::RuntimeException) {
- return a_engine ? a_engine : (a_engine = (anna::diameter::codec::Engine *)anna::functions::component <Engine> (ANNA_FILE_LOCATION));
+ if(!a_engine)
+ throw anna::RuntimeException("Invalid codec engine reference (NULL)", ANNA_FILE_LOCATION);
+
+ return a_engine;
}
//--------------------------------------------------------- Message::getEngine()
//------------------------------------------------------------------------------
anna::diameter::codec::Engine * Message::getEngine() const throw(anna::RuntimeException) {
- return a_engine ? a_engine : (a_engine = (anna::diameter::codec::Engine*)anna::functions::component <Engine> (ANNA_FILE_LOCATION));
+ if(!a_engine)
+ throw anna::RuntimeException("Invalid codec engine reference (NULL)", ANNA_FILE_LOCATION);
+
+ return a_engine;
}