Remove dynamic exceptions
[anna.git] / include / anna / diameter.comm / Response.hpp
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 #ifndef anna_diameter_comm_Response_hpp
10 #define anna_diameter_comm_Response_hpp
11
12
13 #include <anna/core/util/Recycler.hpp>
14 #include <anna/core/Allocator.hpp>
15 #include <anna/core/RuntimeException.hpp>
16
17 // Local
18 #include <anna/diameter/defines.hpp>
19 #include <anna/diameter.comm/ClassCode.hpp>
20
21
22 namespace anna {
23 class DataBlock;
24 }
25
26
27 namespace anna {
28
29 namespace diameter {
30
31 namespace comm {
32
33 class Session;
34 class Timer;
35 class Message;
36
37 /**
38    Answers that we could receive from diameter servers.
39
40    La respuesta correspondiente a una peticion se genera automaticamente al invocar a diameter::comm::Session::send.
41    ANNA::diameter::comm notifies el resultado de la operacion solicitada mediante la invocacion
42    al metodo-menejador diameter::comm::Session::eventResponse de nuestra sesion.
43 */
44 class Response {
45 public:
46
47   struct ResultCode {
48     enum _v {
49       Undefined,
50       Success,
51       Timeout, /**< answer timeout from peer, or transport failure with OTA request notification of timeout event deferred by configurtion */
52       DiameterUnavailable /**< Diameter server was unavailable and notification is not deferred to timeout event for OTA requests */
53     };
54   };
55
56   /**
57      Devuelve el tipo de la clase de esta respuesta.
58      \return El tipo de la clase de esta respuesta.
59   */
60   const ClassCode::_v & getClassCode() const { return a_classCode; }
61
62   /**
63      Devuelve la identificacion del mensaje diameter.
64      Esta identificacion sera generada automaticamente al enviar la peticion.
65      \return Identificacion del mensaje asociado a esta peticion/respuesta.
66      \see diameter::comm::Session::send
67   */
68   HopByHop getHopByHop() const { return a_hopByHop; }
69
70   /**
71      Devuelve la sesion que genera esta respuesta.
72      \return La instancia de la sesion que genera esta respuesta.
73   */
74   const Session* getSession() const { return a_session; }
75
76   /**
77      Devuelve la sesion que origino la creacion de esta respuesta.
78      \return La sesion que origino la creacion de esta respuesta.
79   */
80   Session* getSession() { return a_session; }
81
82
83   /**
84      Devuelve el resultado de la peticion diameter solicitada.
85      \return El resultado de la peticion diameter solicitada.
86   */
87   const ResultCode::_v & getResultCode() const { return a_resultCode; }
88
89
90   /**
91      Returns original request for the response received from the network.
92      \see diameter::comm::Session::send
93   */
94   const Message* getRequest() const { return a_request; }
95
96   /**
97      Returns message received from the network.
98      \see diameter::comm::Session::send
99   */
100   const anna::DataBlock *getMessage() const { return a_message; }
101
102   // helpers
103
104 //   /**
105 //      Reponse regarding diameter keepalive
106 //   */
107 //   bool isKeepAlive() const ;
108
109   /**
110      Devuelve una cadena con la informacion relevante sobre esta instancia.
111      \return Una cadena con la informacion relevante sobre esta instancia.
112   */
113   std::string asString() const ;
114
115 private:
116   ClassCode::_v a_classCode;
117   HopByHop a_hopByHop;
118   Session* a_session;
119   ResultCode::_v a_resultCode;
120   Timer* a_timer;
121   const Message* a_request; // associated original request
122   const anna::DataBlock *a_message; // received datablock from server
123
124   typedef anna::Recycler<Response> response_pool;
125   static response_pool st_responses;
126
127   Response();
128
129   static Response* instance(const ClassCode::_v &, const HopByHop) noexcept(false);
130   static void release(Response* response) ;
131
132   void clear() ;
133
134   void setSession(Session* session) { a_session = session; }
135   void setRequest(const Message* request) { a_request = request; }
136   void setMessage(const anna::DataBlock *message) { a_message = message; }
137   void activateTimer() noexcept(false);
138   void cancelTimer() ;
139   void setResultCode(const ResultCode::_v & resultCode) { a_resultCode = resultCode; }
140
141   static const char* asText(const ResultCode::_v) ;
142
143   friend class Session;
144   friend class ClientSession;
145   friend class ServerSession;
146   friend class Timer;
147   friend class anna::Allocator<Response>;
148 };
149
150 }
151 }
152 }
153
154 #endif
155