1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
38 #include <anna/diameter.comm/Response.hpp>
39 #include <anna/diameter.comm/Message.hpp>
40 #include <anna/diameter.comm/TimerManager.hpp>
41 #include <anna/diameter/defines.hpp>
42 #include <anna/diameter/helpers/helpers.hpp>
44 #include <anna/core/functions.hpp>
45 #include <anna/core/tracing/Logger.hpp>
52 diameter::comm::Response::response_pool diameter::comm::Response::st_responses;
54 //----------------------------------------------------------------------------------------
55 // Se invocan desde diameter::comm::Session
56 //----------------------------------------------------------------------------------------
57 diameter::comm::Response* diameter::comm::Response::instance(const ClassCode::_v & classCode, const HopByHop hopByHop)
58 throw(anna::RuntimeException) {
59 diameter::comm::Response* result = st_responses.create();
60 result->a_classCode = classCode;
61 result->a_hopByHop = hopByHop;
64 string msg("anna::diameter::comm::Response::instance | ");
65 msg += result->asString();
66 anna::Logger::debug(msg, ANNA_FILE_LOCATION);
71 void diameter::comm::Response::release(diameter::comm::Response* response)
74 st_responses.release(response);
75 } catch(anna::RuntimeException& ex) {
80 diameter::comm::Response::Response() :
81 a_classCode(ClassCode::Undefined),
88 void diameter::comm::Response::clear()
90 a_resultCode = ResultCode::Undefined;
96 void diameter::comm::Response::activateTimer()
97 throw(anna::RuntimeException) {
98 a_timer = TimerManager::instantiate().createTimer(this);
101 void diameter::comm::Response::cancelTimer()
103 if(a_timer != NULL) {
105 TimerManager::instantiate().cancelTimer(a_timer);
106 } catch(anna::RuntimeException& ex) {
114 const char* diameter::comm::Response::asText(const ResultCode::_v rc)
116 static const char* text [] = { "Undefined", "Success", "Timeout", "DiameterUnavailable" };
120 //bool diameter::comm::Response::isKeepAlive() const
123 // if (a_request->getCommandId() == diameter::helpers::base::COMMANDID__Device_Watchdog_Request)
130 string diameter::comm::Response::asString() const
132 string result("diameter::comm::Response { ClassCode: ");
133 result += ClassCode::asText(a_classCode);
134 result += anna::functions::asString(" | HopByHop: %u", a_hopByHop);
135 result += " | ResultCode: ";
136 result += asText(a_resultCode);
137 return result += " }";