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 //
13 #include <anna/diameter/codec/Message.hpp>
14 #include <anna/diameter/codec/Engine.hpp>
15 #include <anna/diameter/codec/EngineManager.hpp>
18 #include <anna/diameter/codec/MessagesDeque.hpp>
21 using namespace anna::diameter::codec;
24 void MessagesDeque::clear() throw () {
26 anna::diameter::codec::EngineManager &em = anna::diameter::codec::EngineManager::instantiate();
27 anna::diameter::codec::Engine *engine;
29 for (messages_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) {
30 anna::diameter::codec::Message *message = *(it->second->begin());
31 engine = em.getCodecEngine(message->getApplicationId());
33 engine->releaseMessage(message);
37 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));
42 catch (anna::RuntimeException &ex) {
47 void MessagesDeque::dump(const char *filenamePrefix) throw () {
48 std::string outfilename, xmlString;
49 for (messages_const_iterator it = a_deques.begin();
50 it != a_deques.end(); it++) {
52 for (codec_messages_deque_const_iterator itm = it->second->begin();
53 itm != it->second->end(); itm++) {
54 // message.<code>.<sequence>
55 outfilename = filenamePrefix;
57 outfilename += anna::functions::asString(it->first);
59 outfilename += anna::functions::asString(sequence++);
60 outfilename += ".xml";
61 std::ofstream outfile(outfilename.c_str(), std::ifstream::out);
62 xmlString = (*itm)->asXMLString();
63 outfile.write(xmlString.c_str(), xmlString.size());
69 void MessagesDeque::addMessage(int code, anna::diameter::codec::Message *message) throw () {
71 return; // just in case
73 messages_const_iterator it = a_deques.find(code);
74 if (it != a_deques.end()) {
75 it->second->push_back(message);
77 codec_messages_deque *deque = new codec_messages_deque;
78 a_deques[code] = deque;
79 deque->push_back(message);
83 anna::diameter::codec::Message* MessagesDeque::getMessage(int code) const throw () { //get the front message (begin()), returns NULL if deque is empty
84 anna::diameter::codec::Message *result = NULL;
85 messages_const_iterator it = a_deques.find(code);
86 if (it != a_deques.end()) {
87 if (!it->second->empty())
88 result = *(it->second->begin());
93 void MessagesDeque::nextMessage(int code) throw () { //pops the deque and release the message (when deque is not empty: deque::empty)
94 anna::diameter::codec::Engine *engine;
97 messages_const_iterator it = a_deques.find(code);
98 if (it != a_deques.end()) {
99 if (!it->second->empty()) {
100 anna::diameter::codec::Message *message = *(it->second->begin());
102 addMessage(code, message);
104 engine = anna::diameter::codec::EngineManager::instantiate().getCodecEngine(message->getApplicationId());
106 engine->releaseMessage(message);
109 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));
113 it->second->pop_front();
117 catch (anna::RuntimeException &ex) {
122 std::string MessagesDeque::asString(const char *queueName) const throw () {
123 std::string result = "";
124 std::string aux = "FIFO QUEUE '";
126 aux += "', Rotation ";
127 aux += a_rotate ? "enabled" : "disabled";
128 result += anna::functions::highlightJustify(aux);
129 if (a_deques.size() != 0) {
130 for (messages_const_iterator it = a_deques.begin();
131 it != a_deques.end(); it++) {
132 if (it->second->size() != 0) {
133 aux = "Message code ";
134 aux += anna::functions::asString(it->first);
135 result += anna::functions::highlightJustify(aux,
136 anna::functions::TextHighlightMode::OverAndUnderline,
137 anna::functions::TextJustifyMode::Left, '-');
138 for (codec_messages_deque_const_iterator itm = it->second->begin();
139 itm != it->second->end(); itm++) {
140 result += (*itm)->asXMLString();
147 result = "No ocurrences found\n\n";