Fix local server for multiple applications
[anna.git] / include / anna / diameter.comm / Engine.hpp
index e8febc4..8da4a6b 100644 (file)
@@ -25,6 +25,8 @@
 #include <anna/config/defines.hpp>
 #include <anna/diameter.comm/ClientSession.hpp>
 #include <anna/diameter.comm/ServerSession.hpp>
+#include <anna/core/util/defines.hpp> // U32
+
 
 // Standard
 #include <time.h>
@@ -184,22 +186,40 @@ public:
   bool bind() noexcept(false);
 
   /**
-   * Sets CER and DWR diameter messages to be used over created client-sessions.
-   * Its recommended to set this global configuration although it is possible to configure each client-session separately.
+   * Sets CER diameter messages to be used over created client-sessions.
    *
    * @param cer Capabilities-Exchange-Request message (encoded) for the client-sessions bind.
+   */
+  void setClientCER(const anna::DataBlock & cer) noexcept(false);
+
+  /**
+   * Sets CER diameter messages to be used over created client-sessions.
+   *
+   * @param cerPathFile Capabilities-Exchange-Request xml message path file for the client-sessions bind.
+   */
+  void setClientCER(const std::string & cerPathFile) noexcept(false);
+
+  /**
+   * Sets DEFAULT CER diameter messages to be used over created client-sessions.
+   *
+   * @param applicationId Application-Id for the Auth-Application-Id AVP.
+   */
+  void setClientCER(const anna::U32 &applicationId) noexcept(false);
+
+  /**
+   * Sets DWR for diameter keep-alive over client-sessions
+   *
    * @param dwr Device-Watchdog-Request message (encoded) for the client-sessions keep-alive.
    */
-  void setClientCERandDWR(const anna::DataBlock & cer, const anna::DataBlock & dwr) noexcept(false);
+  void setClientDWR(const anna::DataBlock & dwr) noexcept(false);
 
   /**
-   * Sets CER and DWR diameter messages to be used over created client-sessions. If empty string is provided for CER and/or DWR, default version will be configured.
-   * Its recommended to set this global configuration although it is possible to configure each client-session separately.
+   * Sets DWR for diameter keep-alive over client-sessions
    *
-   * @param cer Capabilities-Exchange-Request xml message path file for the client-sessions bind. If empty string is provided (default), a default version for CER will be encoded.
-   * @param dwr Device-Watchdog-Request xml message path file for the client-sessions keep-alive. If empty string is provided (default), a default version for DWR will be encoded.
+   * @param cerPathFile Device-Watchdog-Request xml message path file for the client-sessions keep-alive.
+   * If empty provided, a DEFAULT DWR will be built.
    */
-  void setClientCERandDWR(const std::string & cer = "", const std::string & dwr = "") noexcept(false);
+  void setClientDWR(const std::string & dwrPathFile = "") noexcept(false);
 
   /**
    * Sets the watchdog period (DWR) for client-sessions.
@@ -492,71 +512,6 @@ public:
   */
   virtual anna::xml::Node* asXML(anna::xml::Node* parent) const ;
 
-
-  /**
-     When there is not bound server session over the engine, this virtual method will be invoked.
-     Applications must decide to do any other tasks at this idle/isolated situation.
-     Default implementation do nothing.
-  */
-  virtual void availabilityLostForLocalServers(Engine *) const {;}
-
-  /**
-     When there is any bound server session over the engine, this virtual method will be invoked.
-     Applications must decide to do be ready for incoming traffic.
-     Default implementation do nothing.
-  */
-  virtual void availabilityRecoveredForLocalServers(Engine *) const {;}
-
-  /**
-     When there is not bound entity over the engine, this virtual method will be invoked.
-     Many applications must change communicator status to Unavailable when no engines are available.
-     Default implementation do nothing.
-  */
-  virtual void availabilityLostForEntities(Engine *) const {;}
-
-  /**
-     When there is any bound entity over the engine, this virtual method will be invoked.
-     Many applications must recover communicator status to Available when any engine are available.
-     Default implementation do nothing.
-  */
-  virtual void availabilityRecoveredForEntities(Engine *) const {;}
-
-  /**
-     When there is not bound server-session over the local server, this virtual method will be invoked.
-     Default implementation do nothing.
-  */
-  virtual void availabilityLost(LocalServer *) const {;}
-
-  /**
-     When there is any bound server-session over the local server, this virtual method will be invoked.
-     Default implementation do nothing.
-  */
-  virtual void availabilityRecovered(LocalServer *) const {;}
-
-  /**
-     When there is not bound server over the entity, this virtual method will be invoked.
-     Default implementation do nothing.
-  */
-  virtual void availabilityLost(Entity *) const {;}
-
-  /**
-     When there is any bound server over the entity, this virtual method will be invoked.
-     Default implementation do nothing.
-  */
-  virtual void availabilityRecovered(Entity *) const {;}
-
-  /**
-     When there is not bound client-session over the server, this virtual method will be invoked.
-     Default implementation do nothing.
-  */
-  virtual void availabilityLost(Server *) const {;}
-
-  /**
-     When there is any bound client-session over the server, this virtual method will be invoked.
-     Default implementation do nothing.
-  */
-  virtual void availabilityRecovered(Server *) const {;}
-
   /**
      When a subyacent client session is going to be bound, this method is invoked before.
      Default implementation do nothing.
@@ -573,7 +528,7 @@ public:
    * @param dpa DPA datablock passed as reference
    * @param dpr Corresponding DPR received (sequence values must be taken into account in order to build DPA)
   */
-  virtual void readDPA(anna::DataBlock &dpa, const anna::DataBlock & dpr) ;
+  virtual void readDPA(anna::DataBlock &dpa, const anna::DataBlock & dpr) const;
 
   /**
    * Sets optional CEA from file, when default is not enough
@@ -582,6 +537,13 @@ public:
    */
   void setCEA(const std::string &ceaPathfile) { a_ceaPathfile = ceaPathfile; }
 
+  /**
+   * Gets optional CEA from file, when default is not enough
+   *
+   * @return Path file for the CEA xml message provided
+   */
+  const std::string & getCEA() const { return a_ceaPathfile; }
+
   /**
    * Class user should implement this method in order to define Capabilities-Exchange-Answer for received CER over server socket.
    * Origin-Host and Origin-Realm are configured at comm::Engine with hostname and FQDN (Fully Qualified Domain Name).
@@ -611,7 +573,7 @@ public:
    * @param cea CEA datablock passed as reference. Empty cea implies to discard CER received.
    * @param cer Corresponding CER received (sequence values must be taken into account in order to build CEA)
   */
-  virtual void readCEA(anna::DataBlock &cea, const anna::DataBlock & cer) ;
+  virtual void readCEA(anna::DataBlock &cea, const anna::DataBlock & cer) const;
 
   /**
    * Class user should implement this method in order to define Device-Watchdog-Answer for received DWR over server socket.
@@ -622,7 +584,7 @@ public:
    * @param dwa DWA datablock passed as reference
    * @param dwr Corresponding DWR received (sequence values must be taken into account in order to build DWA)
   */
-  virtual void readDWA(anna::DataBlock &dwa, const anna::DataBlock & dwr) ;
+  virtual void readDWA(anna::DataBlock &dwa, const anna::DataBlock & dwr) const;
 
   /**
    * DRA basics: CER information is gathered on every server session managed by the diameter comm engine. You could send the message to a
@@ -661,7 +623,7 @@ protected:
      @param baseProtocolDictionary This will be used internally when calling \@readCEA, \@readDPA and \@readDWA on
      servers, and also used during base protocol messages tracing (if debug traces are enabled). You could provide
      NULL, but you must be sure that neither of the former situations are going to happen or an exception will be
-     thrown (using setClientCERandDWR with DataBlock arguments, expects externally encoded messages and could help).
+     thrown (using setClientCER and setClientDWR with DataBlock arguments, expects externally encoded messages and could help).
      It is recommended to set a base protocol dictionary loading 'source/diameter/stack/setups' dictionaries (for
      example 'avps_ietf.xml' plus 'commands_baseProtocol.xml'), or using the dictionary creation API. The dictionary
      could also be an application stack, the only condition is containing the resources to build base protocol messages.
@@ -734,14 +696,12 @@ private:
 
 
   // ClientSessions messages:
-  anna::DataBlock a_cer;
-  anna::DataBlock a_dwr;
+  anna::DataBlock a_client_cer;
+  anna::DataBlock a_client_dwr;
   anna::Millisecond a_watchdogPeriod;
 
-//   // ServerSessions messages:
+  // ServerSessions messages: no need for DWA and DPA templates, they are built on the fly (enough information).
   std::string a_ceaPathfile; // path file to optional CEA (diameter local server configuration)
-//   anna::DataBlock a_cea;
-//   anna::DataBlock a_dwa;
 
   // Client connectivity
   anna::Millisecond a_maxConnectionDelay;
@@ -766,7 +726,7 @@ private:
 
   // Integrity:
   void checkEntityCollision(const socket_v &) noexcept(false);
-  void assertBaseProtocolHealth() noexcept(false); // checks the dictionary
+  void assertBaseProtocolHealth() const noexcept(false); // checks the dictionary
 
 
   //////////////////////////