OriginHostManager to abstract Procedure (dyamic) from knowing the OriginHost node
[anna.git] / include / anna / diameter.comm / OriginHostManager.hpp
diff --git a/include/anna/diameter.comm/OriginHostManager.hpp b/include/anna/diameter.comm/OriginHostManager.hpp
new file mode 100644 (file)
index 0000000..af5793b
--- /dev/null
@@ -0,0 +1,105 @@
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
+
+
+#ifndef anna_diameter_comm_OriginHostManager_hpp
+#define anna_diameter_comm_OriginHostManager_hpp
+
+
+// Project
+#include <anna/core/Singleton.hpp>
+#include <anna/diameter/defines.hpp>
+
+// Standard
+#include <map>
+#include <string>
+
+
+namespace anna {
+
+namespace xml {
+  class Node;
+
+}
+namespace diameter {
+
+namespace comm {
+
+class OriginHost;
+
+typedef std::map<std::string, anna::diameter::comm::OriginHost*> origin_hosts_t;
+typedef std::map<std::string, anna::diameter::comm::OriginHost*>::const_iterator origin_hosts_it;
+typedef std::map<std::string, anna::diameter::comm::OriginHost*>::iterator origin_hosts_nc_it;
+
+
+/**
+ * Helper class to centralize application Origin Host Nodes
+ *
+ */
+class OriginHostManager : public anna::Singleton <OriginHostManager> {
+
+private:
+
+  origin_hosts_t a_origin_hosts;
+
+  // private constructor
+  OriginHostManager() {};
+
+public:
+
+  virtual ~OriginHostManager() {;}
+
+  /**
+   * First element iterator
+   */
+  origin_hosts_it begin() const throw() { return a_origin_hosts.begin(); }
+
+  /**
+   * Last element iterator
+   */
+  origin_hosts_it end() const throw() { return a_origin_hosts.end(); }
+
+  /**
+   * Number of registered origin hosts
+   */
+  int size() const throw() { return a_origin_hosts.size(); }
+
+  /**
+   * Registers a new origin host node (externally allocated) associated to a name.
+   * If the name exists, the new origin host pointer will replace the existing one.
+   *
+   * @param name Origin Host Name
+   * @param originHost Associated Origin Host node
+   */
+  void registerOriginHost(const std::string &name, OriginHost* originHost) throw();
+
+  /**
+   * Get the associated origin host node for a provided name.
+   *
+   * @param name Origin Host Name
+   *
+   * @return Found origin host node, NULL if not found
+   */
+  OriginHost *getOriginHost(const std::string &name) const throw();
+
+  /**
+     Class XML representation.
+     \param parent XML node over which we will put instance information.
+     \return XML with class content.
+  */
+  virtual anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
+
+
+  friend class anna::Singleton <OriginHostManager>;
+};
+
+}
+}
+}
+
+#endif
+