Remove dynamic exceptions
[anna.git] / include / anna / diameter.comm / ServerSession.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_ServerSession_hpp
10 #define anna_diameter_comm_ServerSession_hpp
11
12
13 // STL
14 #include <string>
15
16 #include <anna/core/util/Millisecond.hpp>
17 #include <anna/core/RuntimeException.hpp>
18
19 #include <anna/diameter.comm/Session.hpp>
20 #include <anna/diameter/defines.hpp>
21 #include <anna/diameter.comm/Message.hpp>
22 #include <anna/diameter.comm/ServerSessionReceiver.hpp>
23 #include <anna/diameter.comm/ReceiverFactoryImpl.hpp>
24
25
26 namespace anna {
27 class DataBlock;
28 namespace timex {
29 class Engine;
30 }
31
32 namespace comm {
33 class ClientSocket;
34 }
35 }
36
37
38 namespace anna {
39
40 namespace diameter {
41
42 namespace comm {
43
44
45 class LocalServer;
46
47
48 /**
49    Modela la conexion realizada contra un servidor diameter local.
50 */
51 class ServerSession : public Session {
52 public:
53
54   ServerSession();
55
56
57   /* virtual */void initialize() ;
58
59   /**
60    * Default max inactivity period for the diameter server-session health.
61    */
62   static const anna::Millisecond DefaultAllowedInactivityTime;
63
64   /**
65      Sets the maximum allowed inactivity time on server session
66
67      @param allowedInactivityTime Inactivity time allowed
68   */
69   void setAllowedInactivityTime(const anna::Millisecond & allowedInactivityTime) ;
70
71   /**
72      Diameter listening address (ip or hostname).
73      \return Diameter listening address.
74   */
75   /* virtual */const std::string& getAddress() const ;
76
77   /**
78      Diameter listen port.
79      \return Diameter listen port.
80   */
81   /* virtual */int getPort() const ;
82
83   /**
84      Server session key. Same as socket id
85   */
86   int getKey() const { return getSocketId(); }
87
88   /**
89      Local server parent
90      \return Local server parent
91   */
92   LocalServer *getParent() { return a_parent; }
93
94
95   /**
96      Sets the diameter client socket and assign the receiver factory to it
97      \param clientSocket Diameter client socket
98   */
99   void setClientSocket(anna::comm::ClientSocket *clientSocket) ;
100
101   /**
102      Diameter client socket
103      \return Diameter client socket
104   */
105   anna::comm::ClientSocket *getClientSocket() { return a_clientSocket; }
106
107 //   /**
108 //      Sets deprecated state to this server session
109 //   */
110 //   void setDeprecated(bool deprecated = true) { a_deprecated = deprecated; }
111
112 //   /**
113 //    * Sets CEA and DWA diameter messages to be used over created server-sessions
114 //    *
115 //    * @param cea Capabilities-Exchange-Answer message (encoded) for the server-sessions bind.
116 //    * @param dwa Device-Watchdog-Answer message (encoded) for the server-sessions keep-alive.
117 //    */
118 //   void setCEAandDWA(const anna::DataBlock & cea, const anna::DataBlock & dwa) noexcept(false);
119
120   /* virtual */const Response* send(const Message* message) noexcept(false);
121   /* virtual */bool unbind(bool forceDisconnect /* se usa en timer, para el actionTimer del tipo SessionUnbind, etc. */ = false) noexcept(false); // returns true if done at call time (no pendings or ignore pendings, except Disconnecting state by mean DPR/DPA)
122
123
124   /**
125      Class string representation
126      \return String with relevant information for this instance.
127   */
128   /* virtual */std::string asString() const ;
129
130
131   /**
132      Class xml representation
133      \param parent Parent XML node on which hold this instance information.
134      \return XML document with relevant information for this instance.
135   */
136   /* virtual */anna::xml::Node* asXML(anna::xml::Node* parent) const ;
137
138 protected:
139
140   // Deprecated state
141   bool a_deprecated;
142
143 private:
144
145   // Receiver factory
146   ReceiverFactoryImpl<ServerSession, ServerSessionReceiver> a_receiverFactory;
147
148   // Parent information
149   LocalServer *a_parent;
150
151   // Client Socket
152   anna::comm::ClientSocket *a_clientSocket;
153
154   // Auxiliary messages:
155   Message a_cer, a_dwr;
156
157   /* virtual */void expire(anna::timex::Engine *timeController) noexcept(false);
158
159   // Activity:
160   /* virtual */void updateIncomingActivityTime() ;
161   /* virtual */void updateOutgoingActivityTime() ;
162   void countSendings(const diameter::CommandId & cid, unsigned int aid, bool ok) ;
163
164   // Handlers:
165   /**
166      Handler about event break connection from diameter client over this server-session.
167
168      When notified, ANNA.diameter.comm generates an diameter::comm::ServerSession::eventResponse for every request with pending answers.
169   */
170   void eventPeerShutdown() ;
171
172   /**
173      Handler about a request retransmission over the session.
174
175      \param request Message retransmitted
176   */
177   void eventRequestRetransmission(Message *request) ;
178
179   /**
180      Handler for diameter client responses
181
182      \param response Answer container object for corresponding diameter request
183   */
184   void eventResponse(const Response& response) noexcept(false);
185
186   /**
187      Handler for diameter client requests
188
189      \param request Request data block object for corresponding diameter reception
190   */
191   void eventRequest(const anna::DataBlock& request) noexcept(false);
192   //void eventRequest(const Message& request) noexcept(false);
193
194   /**
195      Handler for diameter client responses out of context
196
197      \param response Answer data block object without context match
198   */
199   void eventUnknownResponse(const anna::DataBlock& response) noexcept(false);
200
201   /**
202      Handler for diameter client Disconnect-Peer-Answer messages
203
204      \param response Answer data block object without context match
205   */
206   void eventDPA(const anna::DataBlock& response) noexcept(false);
207
208
209
210   /**
211   * Handlers for receptions
212   */
213   /* virtual */void receive(const anna::comm::Message& message) noexcept(false);
214   /* virtual */void finalize() ;
215
216   /* virtual */void expireResponse(Response*) ;
217   void sendCEA() noexcept(false);
218   void sendDWA() noexcept(false);
219
220
221   friend class anna::diameter::comm::Timer;
222   friend class LocalServer;
223   friend class Engine;
224   friend class ServerSessionReceiver;
225 };
226
227 }
228 }
229 }
230
231 #endif
232