X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2FProgrammedAnswers.cpp;h=b2b89b2e2030226bee87bc6e12ea4d74f1a2bb33;hb=61f1340da3cae5159d2e3bc14fc47c6d4bf9453e;hp=8e310d72a4160d3b994b8d4c783144ad083b5229;hpb=6f990d26c49e6f5bbb31cb1a2a47615918b6c339;p=anna.git diff --git a/example/diameter/launcher/ProgrammedAnswers.cpp b/example/diameter/launcher/ProgrammedAnswers.cpp index 8e310d7..b2b89b2 100644 --- a/example/diameter/launcher/ProgrammedAnswers.cpp +++ b/example/diameter/launcher/ProgrammedAnswers.cpp @@ -5,110 +5,142 @@ // See project site at http://redmine.teslayout.com/projects/anna-suite // // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // - // Standard #include #include // Project +#include #include +#include // Process -#include "ProgrammedAnswers.hpp" +#include + +void ProgrammedAnswers::clear() throw () { + try { + anna::diameter::codec::EngineManager &em = anna::diameter::codec::EngineManager::instantiate(); + anna::diameter::codec::Engine *engine; -void ProgrammedAnswers::clear () throw() { - for (reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { - a_codecEngine->releaseMessage(*(it->second->begin())); - delete(it->second); + for (reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { + anna::diameter::codec::Message *message = *(it->second->begin()); + engine = em.getCodecEngine(message->getApplicationId()); + if (engine) { + engine->releaseMessage(message); + delete (it->second); + } + else { + LOGWARNING(anna::Logger::warning("Cannot release a message for which i don't know the codec engine (check the registered stack id regarding the message application id) !", ANNA_FILE_LOCATION)); + } + } + a_deques.clear(); + } + catch (anna::RuntimeException &ex) { + ex.trace(); } - a_deques.clear(); } -void ProgrammedAnswers::dump () throw() { +void ProgrammedAnswers::dump() throw () { std::string outfilename, xmlString; - for(reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { - int sequence = 1; - for(codec_messages_deque_const_iterator itm = it->second->begin(); itm != it->second->end(); itm++) { - // programmed_answer.. - outfilename = "programmed_answer."; - outfilename += anna::functions::asString(it->first); - outfilename += "."; - outfilename += anna::functions::asString(sequence++); - outfilename += ".xml"; - std::ofstream outfile(outfilename.c_str(), std::ifstream::out); - xmlString = (*itm)->asXMLString(); - outfile.write(xmlString.c_str(), xmlString.size()); - outfile.close(); - } + for (reacting_answers_const_iterator it = a_deques.begin(); + it != a_deques.end(); it++) { + int sequence = 1; + for (codec_messages_deque_const_iterator itm = it->second->begin(); + itm != it->second->end(); itm++) { + // programmed_answer.. + outfilename = "programmed_answer."; + outfilename += anna::functions::asString(it->first); + outfilename += "."; + outfilename += anna::functions::asString(sequence++); + outfilename += ".xml"; + std::ofstream outfile(outfilename.c_str(), std::ifstream::out); + xmlString = (*itm)->asXMLString(); + outfile.write(xmlString.c_str(), xmlString.size()); + outfile.close(); + } } } -void ProgrammedAnswers::addMessage(int code, anna::diameter::codec::Message *message) throw() { - if (!message) return; // just in case - message->setEngine(a_codecEngine); // just in case +void ProgrammedAnswers::addMessage(int code, anna::diameter::codec::Message *message) throw () { + if (!message) + return; // just in case reacting_answers_const_iterator it = a_deques.find(code); if (it != a_deques.end()) { - it->second->push_back(message); - } - else { - codec_messages_deque *deque = new codec_messages_deque; - a_deques[code] = deque; - deque->push_back(message); + it->second->push_back(message); + } else { + codec_messages_deque *deque = new codec_messages_deque; + a_deques[code] = deque; + deque->push_back(message); } } -anna::diameter::codec::Message* ProgrammedAnswers::getMessage(int code) const throw() { //get the front message (begin()), returns NULL if deque is empty +anna::diameter::codec::Message* ProgrammedAnswers::getMessage(int code) const throw () { //get the front message (begin()), returns NULL if deque is empty anna::diameter::codec::Message *result = NULL; reacting_answers_const_iterator it = a_deques.find(code); if (it != a_deques.end()) { - if (!it->second->empty()) result = *(it->second->begin()); + if (!it->second->empty()) + result = *(it->second->begin()); } return result; } -void ProgrammedAnswers::nextMessage(int code) throw() { //pops the deque and release the message (when deque is not empty: deque::empty) - reacting_answers_const_iterator it = a_deques.find(code); - if (it != a_deques.end()) { - if (!it->second->empty()) { - if (a_rotate) { - addMessage(code, *(it->second->begin())); - } - else { - a_codecEngine->releaseMessage(*(it->second->begin())); - } - it->second->pop_front(); - } +void ProgrammedAnswers::nextMessage(int code) throw () { //pops the deque and release the message (when deque is not empty: deque::empty) + anna::diameter::codec::Engine *engine; + + try { + reacting_answers_const_iterator it = a_deques.find(code); + if (it != a_deques.end()) { + if (!it->second->empty()) { + anna::diameter::codec::Message *message = *(it->second->begin()); + if (a_rotate) { + addMessage(code, message); + } else { + engine = anna::diameter::codec::EngineManager::instantiate().getCodecEngine(message->getApplicationId()); + if (engine) { + engine->releaseMessage(message); + } + else { + LOGWARNING(anna::Logger::warning("Cannot release a message for which i don't know the codec engine (check the registered stack id regarding the message application id) !", ANNA_FILE_LOCATION)); + return; + } + } + it->second->pop_front(); + } + } + } + catch (anna::RuntimeException &ex) { + ex.trace(); } } -std::string ProgrammedAnswers::asString(const char *queueName) const throw() { +std::string ProgrammedAnswers::asString(const char *queueName) const throw () { std::string result = ""; std::string aux = "FIFO QUEUE '"; aux += queueName; aux += "', Rotation "; - aux += a_rotate ? "enabled":"disabled"; + 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) { - aux = "Answer code "; - aux += anna::functions::asString(it->first); - result += anna::functions::highlightJustify(aux, anna::functions::TextHighlightMode::OverAndUnderline, - anna::functions::TextJustifyMode::Left, '-'); - for(codec_messages_deque_const_iterator itm = it->second->begin(); itm != it->second->end(); itm++) { - result += (*itm)->asXMLString(); - result += "\n"; - } - result += "\n"; - } - } - } - else { - result = "No ocurrences found\n\n"; + if (a_deques.size() != 0) { + for (reacting_answers_const_iterator it = a_deques.begin(); + it != a_deques.end(); it++) { + if (it->second->size() != 0) { + aux = "Answer code "; + aux += anna::functions::asString(it->first); + result += anna::functions::highlightJustify(aux, + anna::functions::TextHighlightMode::OverAndUnderline, + anna::functions::TextJustifyMode::Left, '-'); + for (codec_messages_deque_const_iterator itm = it->second->begin(); + itm != it->second->end(); itm++) { + result += (*itm)->asXMLString(); + result += "\n"; + } + result += "\n"; + } + } + } else { + result = "No ocurrences found\n\n"; } return result; }