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_OriginHostManager_hpp
10 #define anna_diameter_comm_OriginHostManager_hpp
14 #include <anna/core/Singleton.hpp>
15 #include <anna/diameter/defines.hpp>
16 #include <anna/core/util/defines.hpp> // U32
36 typedef std::map<std::string, anna::diameter::comm::OriginHost*> origin_hosts_t;
37 typedef std::map<std::string, anna::diameter::comm::OriginHost*>::const_iterator origin_hosts_it;
38 typedef std::map<std::string, anna::diameter::comm::OriginHost*>::iterator origin_hosts_nc_it;
42 * Helper class to centralize application Origin Host Nodes
45 class OriginHostManager : public anna::Singleton <OriginHostManager> {
49 origin_hosts_t a_origin_hosts;
50 std::map<std::string /* remove OH name */, std::string /* own OH name */> a_remote_to_own_origin_hosts{};
53 // private constructor
54 OriginHostManager() {};
58 virtual ~OriginHostManager() {;}
61 * First element iterator
63 origin_hosts_it begin() const { return a_origin_hosts.begin(); }
66 * Last element iterator
68 origin_hosts_it end() const { return a_origin_hosts.end(); }
71 * Number of registered origin hosts
73 int size() const { return a_origin_hosts.size(); }
76 * Registers a new origin host node (externally allocated) associated to a name.
77 * If the name exists, the new origin host pointer will replace the existing one.
79 * @param name Origin Host Name
80 * @param originHost Associated Origin Host node
82 void registerOriginHost(const std::string &name, OriginHost* originHost) ;
85 * Registers the relation between Origin Host for incoming request and
88 * @param remoteName origin host name for the received CER
89 * @param ownName Own origin host name
91 void registerRemoteOriginHost(const std::string &remoteName, const std::string &ownName);
94 * Get the associated origin host node for a provided name.
96 * @param name Origin Host Name
98 * @return Found origin host node, NULL if not found
100 OriginHost *getOriginHost(const std::string &name) const ;
103 * Get the associated origin host name for a provided remote origin host name.
104 * This relation was established on CER reception.
106 * @param name remote origin host name
108 * @return own origin host, NULL if not found
110 OriginHost * getOriginHostForRemoteOriginHost(const std::string &name) const;
113 * Get the associated origin host node for a specific application id
114 * No indexed map by application id, so this search is sequential, but
115 * performance is not required as this is used when receiving CER.
117 * @applicationId application id to search
119 * @return Found origin host node, NULL if not found
121 OriginHost *getOriginHost(const anna::U32 &applicationId) const;
125 Class XML representation.
126 \param parent XML node over which we will put instance information.
127 \return XML with class content.
129 virtual anna::xml::Node* asXML(anna::xml::Node* parent) const ;
132 friend class anna::Singleton <OriginHostManager>;