Fix local server for multiple applications
[anna.git] / source / diameter.comm / ClientSession.cpp
index aea2851..9db3ca7 100644 (file)
@@ -57,7 +57,7 @@ ClientSession::ClientSession() : Session("diameter::comm::ClientSession", "Diame
 { initialize(); }
 
 
-void ClientSession::initialize() throw() {
+void ClientSession::initialize() {
   Session::initialize();
   a_autoRecovery = true;
   a_parent = NULL;
@@ -69,22 +69,22 @@ void ClientSession::initialize() throw() {
 //ClientSession::~ClientSession() {;}
 
 
-const std::string& ClientSession::getAddress() const throw() {
+const std::string& ClientSession::getAddress() const {
   return a_parent->getAddress();
 }
 
-int ClientSession::getPort() const throw() {
+int ClientSession::getPort() const {
   return a_parent->getPort();
 }
 
 
-void ClientSession::setState(State::_v state) throw() {
+void ClientSession::setState(State::_v state) {
   Session::setState(state);
   // Inform father server (availability changes):
   a_parent->refreshAvailability();
 }
 
-void ClientSession::bind() throw(anna::RuntimeException) {
+void ClientSession::bind() noexcept(false) {
   LOGMETHOD(anna::TraceMethod traceMethod(a_className, "bind", ANNA_FILE_LOCATION));
 
   if(a_state != State::Closed)
@@ -125,26 +125,7 @@ void ClientSession::bind() throw(anna::RuntimeException) {
 }
 
 
-void ClientSession::setCERandDWR(const anna::DataBlock & cer, const anna::DataBlock & dwr) throw(anna::RuntimeException) {
-  if(codec::functions::getCommandId(cer) != helpers::base::COMMANDID__Capabilities_Exchange_Request) {
-    throw anna::RuntimeException("The message provided as 'CER' is not a Capabilities-Exchange-Request", ANNA_FILE_LOCATION);
-  }
-
-  if(codec::functions::getCommandId(dwr) != helpers::base::COMMANDID__Device_Watchdog_Request) {
-    throw anna::RuntimeException("The message provided as 'DWR' is not a Device-Watchdog-Request", ANNA_FILE_LOCATION);
-  }
-
-  // La verificacion ya se hace implicitamente antes
-  //   if ((a_cer.isEmpty()) || (a_dwr.isEmpty())) {
-  //      LOGDEBUG (anna::Logger::debug ("Must define valid CER and DWR messages before use bind !", ANNA_FILE_LOCATION));
-  //      return;
-  //   }
-  a_cer.setBody(cer);
-  a_dwr.setBody(dwr);
-}
-
-
-const Response* ClientSession::send(const Message* message) throw(anna::RuntimeException) {
+const Response* ClientSession::send(const Message* message) noexcept(false) {
   LOGMETHOD(anna::TraceMethod traceMethod(a_className, "send", ANNA_FILE_LOCATION));
 
   if(!message)
@@ -356,7 +337,7 @@ const Response* ClientSession::send(const Message* message) throw(anna::RuntimeE
 }
 
 bool ClientSession::unbind(bool forceDisconnect)
-throw(anna::RuntimeException) {
+noexcept(false) {
   LOGMETHOD(anna::TraceMethod traceMethod(a_className, "unbind", ANNA_FILE_LOCATION));
 
   if(a_state == State::Closed)
@@ -442,12 +423,12 @@ throw(anna::RuntimeException) {
   return false;
 }
 
-void ClientSession::eventPeerShutdown() throw() {
+void ClientSession::eventPeerShutdown() {
   // Inform father server:
   a_parent->eventPeerShutdown(this);
 }
 
-void ClientSession::eventRequestRetransmission(Message *request) throw() {
+void ClientSession::eventRequestRetransmission(Message *request) {
 
   // OAM
   OamModule &oamModule = OamModule::instantiate();
@@ -458,24 +439,24 @@ void ClientSession::eventRequestRetransmission(Message *request) throw() {
   a_parent->eventRequestRetransmission(this, request);
 }
 
-void ClientSession::eventResponse(const Response& response) throw(anna::RuntimeException) {
+void ClientSession::eventResponse(const Response& response, const anna::diameter::comm::OriginHost *myNode) noexcept(false) {
   // Inform father server:
-  a_parent->eventResponse(response);
+  a_parent->eventResponse(response, myNode);
 }
 
-void ClientSession::eventRequest(const anna::DataBlock &request) throw(anna::RuntimeException) {
+void ClientSession::eventRequest(const anna::DataBlock &request, const anna::diameter::comm::OriginHost *myNode) noexcept(false) {
   // Inform father server:
-  a_parent->eventRequest(this, request);
+  a_parent->eventRequest(this, request, myNode);
 }
 
-void ClientSession::eventUnknownResponse(const anna::DataBlock& response) throw(anna::RuntimeException) {
+void ClientSession::eventUnknownResponse(const anna::DataBlock& response, const anna::diameter::comm::OriginHost *myNode) noexcept(false) {
   // Inform father server:
-  a_parent->eventUnknownResponse(this, response);
+  a_parent->eventUnknownResponse(this, response, myNode);
 }
 
-void ClientSession::eventDPA(const anna::DataBlock& response) throw(anna::RuntimeException) {
+void ClientSession::eventDPA(const anna::DataBlock& response, const anna::diameter::comm::OriginHost *myNode) noexcept(false) {
   // Inform father server:
-  a_parent->eventDPA(this, response);
+  a_parent->eventDPA(this, response, myNode);
 }
 
 
@@ -484,7 +465,7 @@ void ClientSession::eventDPA(const anna::DataBlock& response) throw(anna::Runtim
 // Se invoca desde el diameter::comm::Receiver
 //------------------------------------------------------------------------------------------
 void ClientSession::receive(const anna::comm::Message& message)
-throw(anna::RuntimeException) {
+noexcept(false) {
   LOGMETHOD(anna::TraceMethod traceMethod(a_className, "receive", ANNA_FILE_LOCATION));
   // Activity:
   updateIncomingActivityTime();
@@ -542,11 +523,10 @@ throw(anna::RuntimeException) {
       oamModule.count(OamModule::Counter::DPRReceived);
 
       if(a_state == State::Bound) {
-        a_dpr.setBody(db);
         setState(State::Disconnecting);
         LOGWARNING(anna::Logger::warning("DPR has been received from peer (diameter server)", ANNA_FILE_LOCATION));
 
-        if(getOTARequests() == 0) sendDPA();
+        if(getOTARequests() == 0) sendDPA(a_engine, db);
 
         return; // DPR won't be informed because virtual readDPA is available for this
       }
@@ -556,7 +536,7 @@ throw(anna::RuntimeException) {
       // application message counters
       ApplicationMessageOamModule::instantiate().count(cid.first, -1 /* no result code */, anna::diameter::codec::functions::getApplicationId(db), ApplicationMessageOamModule::Counter::Request_Received_AsClient);
 
-      eventRequest(db);
+      eventRequest(db, nullptr /* client classes have a valid engine usage to distinguish, and get origin host from */);
     } catch(anna::RuntimeException& ex) {
       ex.trace();
     }
@@ -569,12 +549,13 @@ throw(anna::RuntimeException) {
   /////////////////////////////
   bool doUnbind = false;
   bool immediateUnbind = false;
-  int resultCode = 0;
+  int resultCode = -1;
 
   try {
     resultCode = helpers::base::functions::getResultCode(db);
   } catch(anna::RuntimeException& ex) {
-    ex.trace();
+    // Not always mandatory ...
+    //ex.trace();
   }
 
   // Received CEA
@@ -660,7 +641,7 @@ throw(anna::RuntimeException) {
     // application message counters
     ApplicationMessageOamModule::instantiate().count(cid.first, resultCode, anna::diameter::codec::functions::getApplicationId(db), ApplicationMessageOamModule::Counter::Answer_UnknownReceived_AsClient);
 
-    eventUnknownResponse(db);
+    eventUnknownResponse(db, nullptr /* client classes have a valid engine usage to distinguish, and get origin host from */);
     string msg(asString());
     msg += anna::functions::asString(" | Response received from entity, for non registered context (HopByHop: %u)", hopByHop);
     throw anna::RuntimeException(msg, ANNA_FILE_LOCATION);
@@ -710,7 +691,7 @@ throw(anna::RuntimeException) {
       if(cid != helpers::base::COMMANDID__Capabilities_Exchange_Answer)
         ApplicationMessageOamModule::instantiate().count(cid.first, resultCode, anna::diameter::codec::functions::getApplicationId(db), ApplicationMessageOamModule::Counter::Answer_Received_AsClient);
 
-      eventResponse(*response);
+      eventResponse(*response, nullptr /* client classes have a valid engine usage to distinguish, and get origin host from */);
     } catch(anna::RuntimeException& ex) {
       ex.trace();
     }
@@ -718,7 +699,7 @@ throw(anna::RuntimeException) {
   else { // DPA
     // unbind is automatically performed, anyway we can inform to the application just in case some additional
     //  procedure could be issued:
-    eventDPA(db);
+    eventDPA(db, nullptr /* client classes have a valid engine usage to distinguish, and get origin host from */);
   }
 
   response_erase(response);
@@ -728,7 +709,7 @@ throw(anna::RuntimeException) {
     unbind(immediateUnbind);
 }
 
-void ClientSession::finalize() throw() {
+void ClientSession::finalize() {
   LOGMETHOD(anna::TraceMethod traceMethod(a_className, "finalize", ANNA_FILE_LOCATION));
   Session::finalize();
   // Inform father server (availability changes):
@@ -748,7 +729,7 @@ void ClientSession::finalize() throw() {
   }
 }
 
-void ClientSession::recover() throw() {
+void ClientSession::recover() {
   LOGMETHOD(anna::TraceMethod traceMethod(a_className, "recover", ANNA_FILE_LOCATION));
 
   try {
@@ -780,7 +761,7 @@ void ClientSession::recover() throw() {
 }
 
 void ClientSession::sendDWAToServer(const anna::DataBlock& dwrDB)
-throw(anna::RuntimeException) {
+noexcept(false) {
   LOGMETHOD(anna::TraceMethod traceMethod(a_className, "sendDWAToServer", ANNA_FILE_LOCATION));
   anna::DataBlock dwa(true);
   a_engine->readDWA(dwa, dwrDB); // Asume that DWA is valid ...
@@ -797,7 +778,7 @@ throw(anna::RuntimeException) {
 // Se invoca desde diameter::comm::Timer
 //-------------------------------------------------------------------------
 void ClientSession::expireResponse(diameter::comm::Response* response)
-throw() {
+{
   LOGMETHOD(anna::TraceMethod traceMethod(a_className, "expireResponse", ANNA_FILE_LOCATION));
   Session::expireResponse(response);
   // OAM
@@ -820,7 +801,7 @@ throw() {
 
 
 std::string ClientSession::asString() const
-throw() {
+{
   string result = Session::asString();
   result += " | Parent Server: ";
   result += anna::functions::socketLiteralAsString(getAddress(), getPort());
@@ -843,7 +824,7 @@ throw() {
 }
 
 anna::xml::Node* ClientSession::asXML(anna::xml::Node* parent) const
-throw() {
+{
   anna::xml::Node* result = Session::asXML(parent);
   parent->createChild("diameter.comm.ClientSession");
   result->createAttribute("ParentServer", anna::functions::socketLiteralAsString(getAddress(), getPort()));
@@ -860,7 +841,7 @@ throw() {
 
 
 const char* ClientSession::asText(const WatchdogState::_v watchdogState)
-throw() {
+{
   static const char* text [] = { "TimerStopped", "WaitingTimerExpiration", "WaitingDWA" };
   return text [watchdogState];
 }
@@ -869,7 +850,7 @@ throw() {
 //------------------------------------------------------------------------------
 //------------------------------------------------------ ClientSession::expire()
 //------------------------------------------------------------------------------
-void ClientSession::expire(anna::timex::Engine *timeController) throw(anna::RuntimeException) {
+void ClientSession::expire(anna::timex::Engine *timeController) noexcept(false) {
   LOGMETHOD(anna::TraceMethod traceMethod(a_className, "expire (watchdog timer)", ANNA_FILE_LOCATION));
 
   //   The client MUST NOT close the primary connection until the
@@ -906,11 +887,11 @@ void ClientSession::expire(anna::timex::Engine *timeController) throw(anna::Runt
   activateTimer();
 }
 
-void ClientSession::setWatchdogPeriod(const anna::Millisecond & watchdogPeriod) throw() {
+void ClientSession::setWatchdogPeriod(const anna::Millisecond & watchdogPeriod) {
   setTimeout(watchdogPeriod);
 }
 
-void ClientSession::setWatchdogState(WatchdogState::_v wState) throw() {
+void ClientSession::setWatchdogState(WatchdogState::_v wState) {
   LOGDEBUG(
 
   if(wState != a_watchdogState) {
@@ -925,12 +906,12 @@ void ClientSession::setWatchdogState(WatchdogState::_v wState) throw() {
 }
 
 
-void ClientSession::timerStopped() throw() {
+void ClientSession::timerStopped() {
   LOGDEBUG(anna::Logger::debug("Watchdog timer stopped", ANNA_FILE_LOCATION));
   setWatchdogState(WatchdogState::TimerStopped);
 }
 
-void ClientSession::timerStarted() throw() {
+void ClientSession::timerStarted() {
   LOGDEBUG(anna::Logger::debug("Watchdog timer started", ANNA_FILE_LOCATION));
 
   if(a_watchdogState == WatchdogState::WaitingDWA) return;
@@ -942,7 +923,7 @@ void ClientSession::timerStarted() throw() {
 //------------------------------------------------------------------------------
 //---------------------------------- ClientSession::updateIncomingActivityTime()
 //------------------------------------------------------------------------------
-void ClientSession::updateIncomingActivityTime() throw() {
+void ClientSession::updateIncomingActivityTime() {
   Session::updateIncomingActivityTime();
   a_parent->updateIncomingActivityTime();
 }
@@ -951,7 +932,7 @@ void ClientSession::updateIncomingActivityTime() throw() {
 //------------------------------------------------------------------------------
 //---------------------------------- ClientSession::updateOutgoingActivityTime()
 //------------------------------------------------------------------------------
-void ClientSession::updateOutgoingActivityTime(void) throw() {
+void ClientSession::updateOutgoingActivityTime(void) {
   Session::updateOutgoingActivityTime();
   a_parent->updateOutgoingActivityTime();
 }
@@ -961,7 +942,7 @@ void ClientSession::updateOutgoingActivityTime(void) throw() {
 //------------------------------------------------------------------------------
 //----------------------------------------------- ClientSession::countSendings()
 //------------------------------------------------------------------------------
-void ClientSession::countSendings(const diameter::CommandId & cid, unsigned int aid, bool ok)throw() {
+void ClientSession::countSendings(const diameter::CommandId & cid, unsigned int aid, bool ok){
   OamModule &oamModule = OamModule::instantiate();
   ApplicationMessageOamModule &appMsgOamModule = ApplicationMessageOamModule::instantiate();