1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
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 //
9 #ifndef anna_diameter_comm_ServerSession_hpp
10 #define anna_diameter_comm_ServerSession_hpp
16 #include <anna/core/util/Millisecond.hpp>
17 #include <anna/core/RuntimeException.hpp>
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>
49 Modela la conexion realizada contra un servidor diameter local.
51 class ServerSession : public Session {
57 /* virtual */void initialize() throw();
60 * Default max inactivity period for the diameter server-session health.
62 static const anna::Millisecond DefaultAllowedInactivityTime;
65 Sets the maximum allowed inactivity time on server session
67 @param allowedInactivityTime Inactivity time allowed
69 void setAllowedInactivityTime(const anna::Millisecond & allowedInactivityTime) throw();
72 Diameter listening address (ip or hostname).
73 \return Diameter listening address.
75 /* virtual */const std::string& getAddress() const throw();
79 \return Diameter listen port.
81 /* virtual */int getPort() const throw();
84 Server session key. Same as socket id
86 int getKey() const throw() { return getSocketId(); }
90 \return Local server parent
92 LocalServer *getParent() throw() { return a_parent; }
96 Sets the diameter client socket and assign the receiver factory to it
97 \param clientSocket Diameter client socket
99 void setClientSocket(anna::comm::ClientSocket *clientSocket) throw();
102 Diameter client socket
103 \return Diameter client socket
105 anna::comm::ClientSocket *getClientSocket() throw() { return a_clientSocket; }
108 // Sets deprecated state to this server session
110 // void setDeprecated(bool deprecated = true) throw() { a_deprecated = deprecated; }
113 // * Sets CEA and DWA diameter messages to be used over created server-sessions
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.
118 // void setCEAandDWA(const anna::DataBlock & cea, const anna::DataBlock & dwa) throw(anna::RuntimeException);
120 /* virtual */const Response* send(const Message* message) throw(anna::RuntimeException);
121 /* virtual */bool unbind(bool forceDisconnect /* se usa en timer, para el actionTimer del tipo SessionUnbind, etc. */ = false) throw(anna::RuntimeException); // returns true if done at call time (no pendings or ignore pendings, except Disconnecting state by mean DPR/DPA)
125 Class string representation
126 \return String with relevant information for this instance.
128 /* virtual */std::string asString() const throw();
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.
136 /* virtual */anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
146 ReceiverFactoryImpl<ServerSession, ServerSessionReceiver> a_receiverFactory;
148 // Parent information
149 LocalServer *a_parent;
152 anna::comm::ClientSocket *a_clientSocket;
154 // Auxiliary messages:
155 Message a_cer, a_dwr;
157 /* virtual */void expire(anna::timex::Engine *timeController) throw(anna::RuntimeException);
160 /* virtual */void updateIncomingActivityTime() throw();
161 /* virtual */void updateOutgoingActivityTime() throw();
162 void countSendings(const diameter::CommandId & cid, unsigned int aid, bool ok) throw();
166 Handler about event break connection from diameter client over this server-session.
168 When notified, ANNA.diameter.comm generates an diameter::comm::ServerSession::eventResponse for every request with pending answers.
170 void eventPeerShutdown() throw();
173 Handler for diameter client responses
175 \param response Answer container object for corresponding diameter request
177 void eventResponse(const Response& response) throw(anna::RuntimeException);
180 Handler for diameter client requests
182 \param request Request data block object for corresponding diameter reception
184 void eventRequest(const anna::DataBlock& request) throw(anna::RuntimeException);
185 //void eventRequest(const Message& request) throw(anna::RuntimeException);
188 Handler for diameter client responses out of context
190 \param response Answer data block object without context match
192 void eventUnknownResponse(const anna::DataBlock& response) throw(anna::RuntimeException);
195 Handler for diameter client Disconnect-Peer-Answer messages
197 \param response Answer data block object without context match
199 void eventDPA(const anna::DataBlock& response) throw(anna::RuntimeException);
204 * Handlers for receptions
206 /* virtual */void receive(const anna::comm::Message& message) throw(anna::RuntimeException);
207 /* virtual */void finalize() throw();
209 /* virtual */void expireResponse(Response*) throw();
210 void sendCEA() throw(anna::RuntimeException);
211 void sendDWA() throw(anna::RuntimeException);
214 friend class anna::diameter::comm::Timer;
215 friend class LocalServer;
217 friend class ServerSessionReceiver;