App counters including message name and result code if proceed
[anna.git] / source / diameter.comm / Response.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 // Local
10 #include <anna/diameter.comm/Response.hpp>
11 #include <anna/diameter.comm/Message.hpp>
12 #include <anna/diameter.comm/TimerManager.hpp>
13 #include <anna/diameter/defines.hpp>
14 #include <anna/diameter/helpers/helpers.hpp>
15
16 #include <anna/core/functions.hpp>
17 #include <anna/core/tracing/Logger.hpp>
18
19
20
21 using namespace std;
22 using namespace anna;
23
24 diameter::comm::Response::response_pool diameter::comm::Response::st_responses;
25
26 //----------------------------------------------------------------------------------------
27 // Se invocan desde diameter::comm::Session
28 //----------------------------------------------------------------------------------------
29 diameter::comm::Response* diameter::comm::Response::instance(const ClassCode::_v & classCode, const HopByHop hopByHop)
30 throw(anna::RuntimeException) {
31   diameter::comm::Response* result = st_responses.create();
32   result->a_classCode = classCode;
33   result->a_hopByHop = hopByHop;
34   result->clear();
35   LOGDEBUG(
36     string msg("anna::diameter::comm::Response::instance | ");
37     msg += result->asString();
38     anna::Logger::debug(msg, ANNA_FILE_LOCATION);
39   );
40   return result;
41 }
42
43 void diameter::comm::Response::release(diameter::comm::Response* response)
44 throw() {
45   try {
46     st_responses.release(response);
47   } catch(anna::RuntimeException& ex) {
48     ex.trace();
49   }
50 }
51
52 diameter::comm::Response::Response() :
53   a_classCode(ClassCode::Undefined),
54   a_hopByHop(0),
55   a_session(NULL),
56   a_timer(NULL),
57   a_request(NULL) {
58 }
59
60 void diameter::comm::Response::clear()
61 throw() {
62   a_resultCode = ResultCode::Undefined;
63   a_session = NULL;
64   a_timer = NULL;
65   a_request = NULL;
66 }
67
68 void diameter::comm::Response::activateTimer()
69 throw(anna::RuntimeException) {
70   a_timer = TimerManager::instantiate().createTimer(this);
71 }
72
73 void diameter::comm::Response::cancelTimer()
74 throw() {
75   if(a_timer != NULL) {
76     try {
77       TimerManager::instantiate().cancelTimer(a_timer);
78     } catch(anna::RuntimeException& ex) {
79       ex.trace();
80     }
81
82     a_timer = NULL;
83   }
84 }
85
86 const char* diameter::comm::Response::asText(const ResultCode::_v rc)
87 throw() {
88   static const char* text [] = { "Undefined", "Success", "Timeout", "DiameterUnavailable" };
89   return text [rc];
90 }
91
92 //bool diameter::comm::Response::isKeepAlive() const
93 //throw() {
94 //   if (a_request) {
95 //      if (a_request->getCommandId() == diameter::helpers::base::COMMANDID__Device_Watchdog_Request)
96 //         return true;
97 //   }
98 //
99 //   return false;
100 //}
101
102 string diameter::comm::Response::asString() const
103 throw() {
104   string result("diameter::comm::Response { ClassCode: ");
105   result += ClassCode::asText(a_classCode);
106   result += anna::functions::asString(" | HopByHop: %u", a_hopByHop);
107   result += " | ResultCode: ";
108   result += asText(a_resultCode);
109   return result += " }";
110 }
111