OriginHostManager to abstract Procedure (dyamic) from knowing the OriginHost node
[anna.git] / include / anna / diameter.comm / OriginHostManager.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 #ifndef anna_diameter_comm_OriginHostManager_hpp
10 #define anna_diameter_comm_OriginHostManager_hpp
11
12
13 // Project
14 #include <anna/core/Singleton.hpp>
15 #include <anna/diameter/defines.hpp>
16
17 // Standard
18 #include <map>
19 #include <string>
20
21
22 namespace anna {
23
24 namespace xml {
25   class Node;
26
27 }
28 namespace diameter {
29
30 namespace comm {
31
32 class OriginHost;
33
34 typedef std::map<std::string, anna::diameter::comm::OriginHost*> origin_hosts_t;
35 typedef std::map<std::string, anna::diameter::comm::OriginHost*>::const_iterator origin_hosts_it;
36 typedef std::map<std::string, anna::diameter::comm::OriginHost*>::iterator origin_hosts_nc_it;
37
38
39 /**
40  * Helper class to centralize application Origin Host Nodes
41  *
42  */
43 class OriginHostManager : public anna::Singleton <OriginHostManager> {
44
45 private:
46
47   origin_hosts_t a_origin_hosts;
48
49   // private constructor
50   OriginHostManager() {};
51
52 public:
53
54   virtual ~OriginHostManager() {;}
55
56   /**
57    * First element iterator
58    */
59   origin_hosts_it begin() const throw() { return a_origin_hosts.begin(); }
60
61   /**
62    * Last element iterator
63    */
64   origin_hosts_it end() const throw() { return a_origin_hosts.end(); }
65
66   /**
67    * Number of registered origin hosts
68    */
69   int size() const throw() { return a_origin_hosts.size(); }
70
71   /**
72    * Registers a new origin host node (externally allocated) associated to a name.
73    * If the name exists, the new origin host pointer will replace the existing one.
74    *
75    * @param name Origin Host Name
76    * @param originHost Associated Origin Host node
77    */
78   void registerOriginHost(const std::string &name, OriginHost* originHost) throw();
79
80   /**
81    * Get the associated origin host node for a provided name.
82    *
83    * @param name Origin Host Name
84    *
85    * @return Found origin host node, NULL if not found
86    */
87   OriginHost *getOriginHost(const std::string &name) const throw();
88
89   /**
90      Class XML representation.
91      \param parent XML node over which we will put instance information.
92      \return XML with class content.
93   */
94   virtual anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
95
96
97   friend class anna::Singleton <OriginHostManager>;
98 };
99
100 }
101 }
102 }
103
104 #endif
105