public:
ProgrammedAnswers() {};
- ~ProgrammedAnswers() {
+ ~ProgrammedAnswers() { clear(); }
+
+ 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() {
result += "\n establish as minimum), separate statistics analyzer per each resource, automatic CER/CEA and DWR/DWA";
result += "\n generation, expiration control and many more features.";
result += "\n";
- result += "\nProcess traces are dump on \"launcher.traces\" and could have any trace level (POSIX levels), usually";
+ result += "\nProcess traces are dump on \"launcher.trace\" and could have any trace level (POSIX levels), usually";
result += "\n 'debug' or 'warning'. See ANNA documentation for more details.";
result += "\n";
result += "\nAs any other ANNA process, context dump could be retrieved sending SIGUSR1 signal:";
result += "\nsendxml2e|<source_file> Sends xml source file (pathfile) through configured entity.";
result += "\nsendxml2c|<source_file> Sends xml source file (pathfile) to client.";
result += "\nsendxml|<source_file> Same as 'sendxml2e'.";
- result += "\nanswerxml2e|[source_file] Answer xml source file (pathfile) for corresponding request from entity.";
- result += "\nanswerxml2c|[source_file] Answer xml source file (pathfile) for corresponding request from client.";
+ result += "\nanswerxml2e|[source_file] Answer xml source file (pathfile) for incoming request with same code from entity.";
+ result += "\n The answer is stored in a FIFO queue for a specific message code, then there are";
+ result += "\n as many queues as different message codes have been received.";
+ result += "\nanswerxml2c|[source_file] Answer xml source file (pathfile) for incoming request with same code from client.";
+ result += "\n The answer is stored in a FIFO queue for a specific message code, then there are";
+ result += "\n as many queues as different message codes have been received.";
result += "\nanswerxml|[source_file] Same as 'answerxml2c'.";
- result += "\n List programmed answers if no parameter provided.";
+ result += "\nanswerxml(2e/2c) List programmed answers (to entity/client) if no parameter provided.";
+ result += "\nanswerxml(2e/2c)|dump Write programmed answers (to entity/client) to file 'programmed_answer.<code>.<sequence>',";
+ 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 += "\n";
result += "\nSend operations are available using hexadecimal content (hex formatted files) which also allow to test";
result += "\nspecial scenarios (protocol errors):";
int main(int argc, const char** argv) {
anna::Logger::setLevel(anna::Logger::Warning);
- anna::Logger::initialize("launcher", new TraceWriter("launcher.traces", 2048000));
+ anna::Logger::initialize("launcher", new TraceWriter("launcher.trace", 2048000));
anna::time::functions::initialize(); // before application instantiation (it have a anna::time object)
anna::time::functions::setControlPoint(); // start control point (application lifetime)
Launcher app;
std::string s_help = help();
std::cout << s_help << std::endl;
LOGINFORMATION(anna::Logger::information(s_help, ANNA_FILE_LOCATION));
- response_content = "Help dumped on stdout and information-level traces (launcher.traces file)\n";
+ response_content = "Help dumped on stdout and information-level traces (launcher.trace file)\n";
return;
}
if(!localServer)
throw anna::RuntimeException("Operation not applicable (no own diameter server has been configured)", ANNA_FILE_LOCATION);
- if(param1 != "") {
+ 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;
+ response_content = "Programmed answers dumped on stdout\n";
+ return;
+ } else if (param1 == "clear") {
+ G_reactingAnswers2C.clear();
+ } else if (param1 == "dump") {
+ G_reactingAnswers2C.dump();
+ } else {
anna::diameter::codec::Engine *engine = anna::functions::component <Engine> (ANNA_FILE_LOCATION);
anna::diameter::codec::Message *message = engine->createMessage(param1);
LOGDEBUG
throw anna::RuntimeException("Cannot program diameter requests. Answer type must be provided", ANNA_FILE_LOCATION);
int code = message->getId().first;
- LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to client' to the deque...", ANNA_FILE_LOCATION));
+ LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to client' to the FIFO queue corresponding to its message code ...", ANNA_FILE_LOCATION));
G_reactingAnswers2C.addMessage(code, message);
- } else { // answers query on stdout
- std::cout << std::endl << std::endl;
- std::cout << " ------------- CURRENT PROGRAMMED ANSWERS TO CLIENT -------------\n\n";
- std::cout << G_reactingAnswers2C.asString() << std::endl;
- response_content = "Programmed answers dumped on stdout\n";
- return;
}
} else if(opType == "answerxml2e") {
anna::diameter::comm::Entity *entity = getEntity();
if(!entity)
throw anna::RuntimeException("Operation not applicable (no diameter entity has been configured)", ANNA_FILE_LOCATION);
- if(param1 != "") {
+ 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;
+ response_content = "Programmed answers dumped on stdout\n";
+ return;
+ } else if (param1 == "clear") {
+ G_reactingAnswers2E.clear();
+ } else if (param1 == "dump") {
+ G_reactingAnswers2E.dump();
+ } else {
anna::diameter::codec::Engine *engine = anna::functions::component <Engine> (ANNA_FILE_LOCATION);
anna::diameter::codec::Message *message = engine->createMessage(param1);
LOGDEBUG
throw anna::RuntimeException("Cannot program diameter requests. Answer type must be provided", ANNA_FILE_LOCATION);
int code = message->getId().first;
- LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to entity' to the deque...", ANNA_FILE_LOCATION));
+ LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to entity' to the FIFO queue corresponding to its message code ...", ANNA_FILE_LOCATION));
G_reactingAnswers2E.addMessage(code, message);
- } else { // answers query on stdout
- std::cout << std::endl << std::endl;
- std::cout << " ------------- CURRENT PROGRAMMED ANSWERS TO ENTITY -------------\n\n";
- std::cout << G_reactingAnswers2E.asString() << std::endl;
- response_content = "Programmed answers dumped on stdout\n";
- return;
}
} else {
LOGWARNING(anna::Logger::warning(help(), ANNA_FILE_LOCATION));