OriginHostManager to abstract Procedure (dyamic) from knowing the OriginHost node
[anna.git] / source / diameter.comm / OriginHostManager.cpp
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 // Project
10 #include <anna/diameter.comm/OriginHostManager.hpp>
11 #include <anna/diameter.comm/OriginHost.hpp>
12 #include <anna/core/tracing/Logger.hpp>
13 #include <anna/xml/Node.hpp>
14
15
16 using namespace anna::diameter::comm;
17
18 OriginHost *OriginHostManager::getOriginHost(const std::string &name) const throw() {
19   origin_hosts_it it = a_origin_hosts.find(name);
20   if (it != a_origin_hosts.end())
21     return it->second;
22
23   LOGWARNING(
24      std::string msg = "Unknown origin host node with name '"; msg += name; msg += "'";
25      anna::Logger::warning(msg, ANNA_FILE_LOCATION);
26   );
27
28   return NULL;
29 }
30
31 void OriginHostManager::registerOriginHost(const std::string &name, OriginHost* originHost) throw() {
32   if (!originHost) return; // nothing done
33   a_origin_hosts[name] = originHost;
34 }
35
36 anna::xml::Node* OriginHostManager::asXML(anna::xml::Node* parent) const
37 throw() {
38   anna::xml::Node* result = parent->createChild("OriginHostManager");
39   origin_hosts_it it_min(a_origin_hosts.begin());
40   origin_hosts_it it_max(a_origin_hosts.end());
41   for (origin_hosts_it it = it_min; it != it_max; it++)
42     it->second->asXML(result);
43
44   return result;
45 }
46