From: Eduardo Ramos Testillano Date: Tue, 6 Oct 2015 23:10:52 +0000 (+0200) Subject: Not allowed to set engine NULL !! X-Git-Tag: REFACTORING_TESTING_LIBRARY~96 X-Git-Url: https://git.teslayout.com/public/public/public/?a=commitdiff_plain;h=ceba20e0efab1bc4e564c18fe05a9a0047983653;p=anna.git Not allowed to set engine NULL !! --- diff --git a/example/diameter/batchConverter/main.cpp b/example/diameter/batchConverter/main.cpp index 0e7eff4..12265cf 100644 --- a/example/diameter/batchConverter/main.cpp +++ b/example/diameter/batchConverter/main.cpp @@ -70,7 +70,7 @@ void _exit(const std::string &message, int resultCode = 1) { // Decodes a diameter message coming from a datablock void decodeDataBlock(const anna::DataBlock &db/*, unsigned int & detectedApplicationId*/) throw() { try { - G_codecMsg.setEngine(NULL); // perhaps we will need another codec engine ... + G_codecMsg.clear(); G_codecMsg.decode(db); } catch(RuntimeException &ex) { _exit(ex.asString()); diff --git a/include/anna/diameter/codec/Message.hpp b/include/anna/diameter/codec/Message.hpp index 32aa932..a040aa1 100644 --- a/include/anna/diameter/codec/Message.hpp +++ b/include/anna/diameter/codec/Message.hpp @@ -189,12 +189,9 @@ public: * may occur. If you add elements (vendors, avps, messages) is not a problem. * * IMPORTANT NOTES: - * 1) if you want to reuse the message, as a recommendation, you should set engine to - * NULL or use #clear. In that way, next operation will adjust automatically the needed - * engine because it would not be configured in such stage. - * 2) if you want to pre-configure the engine you will need to set the engine to NULL - * previously and then you could change to the new one without warning/ignoring. - * 3) if you have dedicated message objects for each interface (application id), then + * 1) if you want to reuse the message, as a recommendation, you should #clear the + * message. In that way, next operation will adjust automatically the needed engine. + * 2) if you have dedicated message objects for each interface (application id), then * you could set the corresponding engine on constructor (or setEngine), and forget * about #clear. The needed cleanup will be done automatically from decoding and xml * loading procedures, and initialized engine will be kept along message operations. diff --git a/source/diameter/codec/Message.cpp b/source/diameter/codec/Message.cpp index 5849196..28a1d45 100644 --- a/source/diameter/codec/Message.cpp +++ b/source/diameter/codec/Message.cpp @@ -84,7 +84,12 @@ Message::~Message() { //------------------------------------------------------------------------------ void Message::setEngine(Engine *engine) throw() { - if (a_engine && 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; }