From e82da89c86bc6131727bb37498b76ce8ea3d0826 Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Testillano Date: Sat, 18 Apr 2015 21:30:20 +0200 Subject: [PATCH] Improv. presentetion of answering queues. New management operations for answering: rotate/exhaust --- example/diameter/launcher/main.cpp | 62 +++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/example/diameter/launcher/main.cpp b/example/diameter/launcher/main.cpp index 4b36441..ab5ea0a 100644 --- a/example/diameter/launcher/main.cpp +++ b/example/diameter/launcher/main.cpp @@ -113,11 +113,15 @@ typedef std::map < int /* message code */, codec_messages_deque* >::iterator re typedef std::map < int /* message code */, codec_messages_deque* >::const_iterator reacting_answers_const_iterator; reacting_answers_container a_deques; + bool a_rotate; public: - ProgrammedAnswers() {}; + ProgrammedAnswers() { a_rotate = false; } ~ProgrammedAnswers() { clear(); } + bool rotate() const const throw() { return a_rotate; } + void rotate(bool r) throw() { a_rotate = r; } + void clear () throw() { for (reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { anna::diameter::codec::Engine *engine = anna::functions::component (ANNA_FILE_LOCATION); @@ -172,29 +176,42 @@ typedef std::map < int /* message code */, codec_messages_deque* >::const_iterat if (it != a_deques.end()) { if (!it->second->empty()) { anna::diameter::codec::Engine *engine = anna::functions::component (ANNA_FILE_LOCATION); - engine->releaseMessage(*(it->second->begin())); + if (a_rotate) { + addMessage(code, *(it->second->begin())); + } + else { + engine->releaseMessage(*(it->second->begin())); + } it->second->pop_front(); } } } - std::string asString() const throw() { - std::string result = "No ocurrences found\n\n"; - std::string s_code; + std::string asString(const char *queueName) const throw() { + std::string result = ""; + std::string aux = "FIFO QUEUE '"; + aux += queueName; + aux += "', Rotation "; + aux += a_rotate ? "enabled":"disabled"; + result += anna::functions::highlightJustify(aux); if(a_deques.size() != 0) { - result = ""; for(reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { - - s_code = "Answer code "; - s_code += anna::functions::asString(it->first); - result += anna::functions::highlightJustify(s_code); - for(codec_messages_deque_const_iterator itm = it->second->begin(); itm != it->second->end(); itm++) { - result += (*itm)->asXMLString(); + 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"; } - result += "\n"; } } + else { + result = "No ocurrences found\n\n"; + } return result; } }; @@ -858,6 +875,9 @@ std::string Launcher::help() const throw() { result += "\nanswerxml(2e/2c)|dump Write programmed answers (to entity/client) to file 'programmed_answer..',"; result += "\n where 'sequence' is the order of the answer in each FIFO code-queue of programmed answers."; result += "\nanswerxml(2e/2c)|clear Clear programmed answers (to entity/client)."; + result += "\nanswerxml(2e/2c)|exhaust Disable the corresponding queue rotation, which is the default behaviour."; + result += "\nanswerxml(2e/2c)|rotate Enable the corresponding queue rotation, useful in performance tests."; + result += "\n Rotation consists in add again to the queue, each element retrieved for answering."; result += "\n"; result += "\nSend operations are available using hexadecimal content (hex formatted files) which also allow to test"; result += "\nspecial scenarios (protocol errors):"; @@ -2060,11 +2080,13 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Operation not applicable (no own diameter server has been configured)", ANNA_FILE_LOCATION); if(param1 == "") { // programmed answers FIFO's to stdout - std::cout << std::endl << std::endl; - std::cout << " ------------- CURRENT PROGRAMMED ANSWERS TO CLIENT -------------\n\n"; - std::cout << G_reactingAnswers2C.asString() << std::endl; + std::cout << G_reactingAnswers2C.asString("ANSWERS TO CLIENT") << std::endl; response_content = "Programmed answers dumped on stdout\n"; return; + } else if (param1 == "rotate") { + G_reactingAnswers2C.rotate(true); + } else if (param1 == "exhaust") { + G_reactingAnswers2C.rotate(false); } else if (param1 == "clear") { G_reactingAnswers2C.clear(); } else if (param1 == "dump") { @@ -2091,11 +2113,13 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Operation not applicable (no diameter entity has been configured)", ANNA_FILE_LOCATION); if(param1 == "") { // programmed answers FIFO's to stdout - std::cout << std::endl << std::endl; - std::cout << " ------------- CURRENT PROGRAMMED ANSWERS TO ENTITY -------------\n\n"; - std::cout << G_reactingAnswers2E.asString() << std::endl; + std::cout << G_reactingAnswers2E.asString("ANSWERS TO ENTITY") << std::endl; response_content = "Programmed answers dumped on stdout\n"; return; + } else if (param1 == "rotate") { + G_reactingAnswers2C.rotate(true); + } else if (param1 == "exhaust") { + G_reactingAnswers2C.rotate(false); } else if (param1 == "clear") { G_reactingAnswers2E.clear(); } else if (param1 == "dump") { -- 2.20.1