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/Timer.hpp>
39 #include <anna/diameter.comm/Response.hpp>
40 #include <anna/diameter.comm/Session.hpp>
41 #include <anna/diameter.comm/LocalServer.hpp>
43 #include <anna/core/tracing/Logger.hpp>
49 void diameter::comm::Timer::expire(anna::timex::Engine*)
50 throw(anna::RuntimeException) {
51 Response* response = NULL;
52 Session* session = NULL;
53 LocalServer* localServer = NULL;
56 case Type::ResponseExpiration:
57 response = getResponse();
58 response->setResultCode(Response::ResultCode::Timeout);
59 session = response->getSession();
61 string msg("anna::diameter::comm::Timer::expire | Response: ");
62 msg += response->asString();
63 anna::Logger::debug(msg, ANNA_FILE_LOCATION);
66 session->expireResponse(response);
68 case Type::SessionUnbind:
69 session = getSession();
73 string msg("anna::diameter::comm::Timer::expire | Session (ending): ");
74 msg += session->asString();
75 anna::Logger::debug(msg, ANNA_FILE_LOCATION);
78 //session->setOnDisconnect(Session::OnDisconnect::IgnorePendings);
79 session->unbind(true /* immediate */);
81 // La client-session desaparecio (hice un closeSession)
82 LOGDEBUG(anna::Logger::debug("anna::diameter::comm::Timer::expire | Session missing", ANNA_FILE_LOCATION));
86 case Type::SessionRecover:
87 session = getSession();
91 string msg("anna::diameter::comm::Timer::expire | Session (recovering): ");
92 msg += session->asString();
93 anna::Logger::debug(msg, ANNA_FILE_LOCATION);
96 session->setState(Session::State::Bound);
98 // La client-session desaparecio (hice un closeSession)
99 LOGDEBUG(anna::Logger::debug("anna::diameter::comm::Timer::expire | Session missing", ANNA_FILE_LOCATION));
103 case Type::LocalServerAttach:
104 localServer = getLocalServer();
108 string msg("anna::diameter::comm::Timer::expire | LocalServer (attach retry)");
109 //msg += localServer->asString();
110 anna::Logger::debug(msg, ANNA_FILE_LOCATION);
113 localServer->attach();
115 // LocalServer desaparecio (hice un closeLocalServer)
116 LOGDEBUG(anna::Logger::debug("anna::diameter::comm::Timer::expire | LocalServer missing", ANNA_FILE_LOCATION));
123 const char* diameter::comm::Timer::asText(const Type::_v type)
125 static const char* text [] = { "ResponseExpiration", "SessionUnbind", "SessionRecover", "LocalServerAttach" };
129 string diameter::comm::Timer::asString() const
131 string result("anna::diameter::comm::Timer { ");
132 result += anna::timex::Transaction::asString();
134 result += asText(a_type);
137 case Type::ResponseExpiration: {
138 const Response* response = getResponse();
140 if(response != NULL) {
142 result += response->asString();
144 result += " | Response: <null>";
148 case Type::SessionUnbind:
149 case Type::SessionRecover: {
150 const Session *session = getSession();
152 if(session != NULL) {
154 result += session->asString();
156 result += " | Session: <null>"; // puede ocurrir ??
160 case Type::LocalServerAttach: {
161 const LocalServer *localServer = getLocalServer();
163 if(localServer != NULL) {
165 result += localServer->asString();
167 result += " | LocalServer: <null>"; // puede ocurrir ??
173 return result += " }";