+class ProgrammedAnswers {
+
+typedef std::deque<anna::diameter::codec::Message*> codec_messages_deque;
+typedef std::deque<anna::diameter::codec::Message*>::iterator codec_messages_deque_iterator;
+typedef std::deque<anna::diameter::codec::Message*>::const_iterator codec_messages_deque_const_iterator;
+typedef std::map < int /* message code */, codec_messages_deque* > reacting_answers_container;
+typedef std::map < int /* message code */, codec_messages_deque* >::iterator reacting_answers_iterator;
+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() { a_rotate = false; }
+ ~ProgrammedAnswers() { clear(); }
+
+ bool rotate() 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 <Engine> (ANNA_FILE_LOCATION);
+ engine->releaseMessage(*(it->second->begin()));
+ delete(it->second);
+ }
+ a_deques.clear();
+ }
+
+ void 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.<code>.<sequence>
+ 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 addMessage(int code, anna::diameter::codec::Message *message) throw() {
+ 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);
+ }
+ }
+
+ anna::diameter::codec::Message* 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());
+ }
+ return result;
+ }
+
+ void 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()) {
+ anna::diameter::codec::Engine *engine = anna::functions::component <Engine> (ANNA_FILE_LOCATION);
+ if (a_rotate) {
+ addMessage(code, *(it->second->begin()));
+ }
+ else {
+ engine->releaseMessage(*(it->second->begin()));
+ }
+ it->second->pop_front();
+ }
+ }
+ }
+
+ 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) {
+ 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;
+ }
+};
+
+ProgrammedAnswers G_reactingAnswers2C, G_reactingAnswers2E;