Fix local server for multiple applications
[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 #include <anna/core/util/defines.hpp> // U32
17
18
19 // Standard
20 #include <map>
21 #include <string>
22
23
24 namespace anna {
25
26 namespace xml {
27   class Node;
28
29 }
30 namespace diameter {
31
32 namespace comm {
33
34 class OriginHost;
35
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;
39
40
41 /**
42  * Helper class to centralize application Origin Host Nodes
43  *
44  */
45 class OriginHostManager : public anna::Singleton <OriginHostManager> {
46
47 private:
48
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{};
51
52
53   // private constructor
54   OriginHostManager() {};
55
56 public:
57
58   virtual ~OriginHostManager() {;}
59
60   /**
61    * First element iterator
62    */
63   origin_hosts_it begin() const { return a_origin_hosts.begin(); }
64
65   /**
66    * Last element iterator
67    */
68   origin_hosts_it end() const { return a_origin_hosts.end(); }
69
70   /**
71    * Number of registered origin hosts
72    */
73   int size() const { return a_origin_hosts.size(); }
74
75   /**
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.
78    *
79    * @param name Origin Host Name
80    * @param originHost Associated Origin Host node
81    */
82   void registerOriginHost(const std::string &name, OriginHost* originHost) ;
83
84   /**
85    * Registers  the relation between Origin Host for incoming request and
86    * own origin host.
87    *
88    * @param remoteName origin host name for the received CER
89    * @param ownName Own origin host name
90    */
91   void registerRemoteOriginHost(const std::string &remoteName, const std::string &ownName);
92
93   /**
94    * Get the associated origin host node for a provided name.
95    *
96    * @param name Origin Host Name
97    *
98    * @return Found origin host node, NULL if not found
99    */
100   OriginHost *getOriginHost(const std::string &name) const ;
101
102   /**
103    * Get the associated origin host name for a provided remote origin host name.
104    * This relation was established on CER reception.
105    *
106    * @param name remote origin host name
107    *
108    * @return own origin host, NULL if not found
109    */
110   OriginHost * getOriginHostForRemoteOriginHost(const std::string &name) const;
111
112   /**
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.
116    *
117    * @applicationId application id to search
118    *
119    * @return Found origin host node, NULL if not found
120    */
121   OriginHost *getOriginHost(const anna::U32 &applicationId) const;
122
123
124   /**
125      Class XML representation.
126      \param parent XML node over which we will put instance information.
127      \return XML with class content.
128   */
129   virtual anna::xml::Node* asXML(anna::xml::Node* parent) const ;
130
131
132   friend class anna::Singleton <OriginHostManager>;
133 };
134
135 }
136 }
137 }
138
139 #endif
140