1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
14 #include <anna/diameter/codec/Engine.hpp>
17 #include "ProgrammedAnswers.hpp"
20 void ProgrammedAnswers::clear () throw() {
21 for (reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) {
22 a_codecEngine->releaseMessage(*(it->second->begin()));
28 void ProgrammedAnswers::dump () throw() {
29 std::string outfilename, xmlString;
30 for(reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) {
32 for(codec_messages_deque_const_iterator itm = it->second->begin(); itm != it->second->end(); itm++) {
33 // programmed_answer.<code>.<sequence>
34 outfilename = "programmed_answer.";
35 outfilename += anna::functions::asString(it->first);
37 outfilename += anna::functions::asString(sequence++);
38 outfilename += ".xml";
39 std::ofstream outfile(outfilename.c_str(), std::ifstream::out);
40 xmlString = (*itm)->asXMLString();
41 outfile.write(xmlString.c_str(), xmlString.size());
47 void ProgrammedAnswers::addMessage(int code, anna::diameter::codec::Message *message) throw() {
48 reacting_answers_const_iterator it = a_deques.find(code);
49 if (it != a_deques.end()) {
50 it->second->push_back(message);
53 codec_messages_deque *deque = new codec_messages_deque;
54 a_deques[code] = deque;
55 deque->push_back(message);
59 anna::diameter::codec::Message* ProgrammedAnswers::getMessage(int code) const throw() { //get the front message (begin()), returns NULL if deque is empty
60 anna::diameter::codec::Message *result = NULL;
61 reacting_answers_const_iterator it = a_deques.find(code);
62 if (it != a_deques.end()) {
63 if (!it->second->empty()) result = *(it->second->begin());
68 void ProgrammedAnswers::nextMessage(int code) throw() { //pops the deque and release the message (when deque is not empty: deque::empty)
69 reacting_answers_const_iterator it = a_deques.find(code);
70 if (it != a_deques.end()) {
71 if (!it->second->empty()) {
73 addMessage(code, *(it->second->begin()));
76 a_codecEngine->releaseMessage(*(it->second->begin()));
78 it->second->pop_front();
83 std::string ProgrammedAnswers::asString(const char *queueName) const throw() {
84 std::string result = "";
85 std::string aux = "FIFO QUEUE '";
87 aux += "', Rotation ";
88 aux += a_rotate ? "enabled":"disabled";
89 result += anna::functions::highlightJustify(aux);
90 result += "Codec engine: ";
91 result += a_codecEngine->getClassName();
92 if(a_deques.size() != 0) {
93 for(reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) {
94 if (it->second->size() != 0) {
96 aux += anna::functions::asString(it->first);
97 result += anna::functions::highlightJustify(aux, anna::functions::TextHighlightMode::OverAndUnderline,
98 anna::functions::TextJustifyMode::Left, '-');
99 for(codec_messages_deque_const_iterator itm = it->second->begin(); itm != it->second->end(); itm++) {
100 result += (*itm)->asXMLString();
108 result = "No ocurrences found\n\n";