Absolute path
[anna.git] / source / diameter / codec / Message.cpp
index 049e85a..28a1d45 100644 (file)
@@ -84,7 +84,12 @@ Message::~Message() {
 //------------------------------------------------------------------------------
 void Message::setEngine(Engine *engine) throw() {
 
-  if (a_engine && engine != a_engine) {
+  if (!engine) {
+    LOGWARNING(anna::Logger::warning("Ignored: you must assign a valid codec engine. If you want to set NULL engine, clear the message", ANNA_FILE_LOCATION));
+    return;
+  }
+
+  if (a_engine && (engine != a_engine)) {
     LOGWARNING(anna::Logger::warning("Ignored: it is not a good practice to change the codec engine once assigned. Clear the message first to set the engine again.", ANNA_FILE_LOCATION));
     return;
   }
@@ -124,7 +129,7 @@ void Message::initialize() throw() {
 //------------------------------------------------------------------------------
 //------------------------------------------------------------- Message::clear()
 //------------------------------------------------------------------------------
-void Message::clear() throw(anna::RuntimeException) {
+void Message::clear(bool resetEngine) throw(anna::RuntimeException) {
   for(avp_iterator it = avp_begin(); it != avp_end(); it++) { /*avp(it)->clear(); */getEngine()->releaseAvp(Avp::avp(it)); }
 
   a_avps.clear();
@@ -133,6 +138,7 @@ void Message::clear() throw(anna::RuntimeException) {
   a_finds.clear();
   // Initialize:
   initialize();
+  if (resetEngine) a_engine = NULL;
 }
 
 
@@ -227,6 +233,7 @@ void Message::setApplicationId(U32 aid) throw(anna::RuntimeException) {
   // Codec engine manager (a multithreaded application, normally does not achieve this point, because
   // messages are prepared for each interface with the corresponding codec engine)
   anna::diameter::codec::EngineManager &em = anna::diameter::codec::EngineManager::instantiate();
+  if (em.size() == 0) return;
   if (em.selectFromApplicationId()) {
     Engine *monostackEngine = em.getMonoStackCodecEngine();
     if (monostackEngine) { a_engine = monostackEngine; return; }
@@ -303,7 +310,7 @@ void Message::decode(const anna::DataBlock &db, Message *ptrAnswer) throw(anna::
   trace += db.asString();
   anna::Logger::debug(trace, ANNA_FILE_LOCATION);
   );
-  clear();
+  clear(false /* respect engine */);
   // EXCEPTION MANAGEMENT IN THIS METHOD
   // ===================================
   // DECODE PHASE
@@ -773,7 +780,7 @@ void Message::fromXML(const anna::xml::Node* messageNode) throw(anna::RuntimeExc
   unsigned int u_aux;
 
   // Clear the message
-  clear();
+  clear(false /* respect engine */);
 
   if(version) {
     i_aux = version->getIntegerValue();