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 #include <anna/core/tracing/TraceMethod.hpp>
11 #include <anna/xml/Node.hpp>
13 #include <anna/comm/Host.hpp>
14 #include <anna/comm/Server.hpp>
15 #include <anna/comm/Communicator.hpp>
16 #include <anna/comm/ClientSocket.hpp>
17 #include <anna/comm/Device.hpp>
18 #include <anna/comm/ServerAllocator.hpp>
24 for(server_iterator ii = server_begin(), maxii = server_end(); ii != maxii; ii ++)
31 int comm::Host::SortBy::value(const Server* server)
33 return server->getRemotePort();
37 const comm::Server* comm::Host::find_server(const int remotePort) const
39 return a_servers.find(remotePort);
42 comm::Server* comm::Host::find_server(const int remotePort)
44 return a_servers.find(remotePort);
48 comm::Server* comm::Host::createServer(const string& name, const int remotePort, const bool autoRecovery, comm::TransportFactory* transportFactory, const bool ignoreIncomingMessages, const bool doConnect)
49 throw(RuntimeException) {
50 return add(createServer(ServerAllocator(name, *this, remotePort, autoRecovery, transportFactory, ignoreIncomingMessages)), remotePort, doConnect);
53 //-------------------------------------------------------------------------------
54 // (1) Acelera las posibilidades principales de busqueda => por nombre y por
55 // puerto remoto en que esta atendiendo peticiones.
57 // Ojo!! Siempre devuelve un Server aunque posiblemente no este conectado al
58 // ServerSocket remoto.
59 //-------------------------------------------------------------------------------
60 comm::Server* comm::Host::createServer(const ServerAllocator& serverAllocator)
61 throw(RuntimeException) {
62 const int remotePort = serverAllocator.getRemotePort();
63 Server* result = serverAllocator.apply();
64 result->setIgnoreIncomingMessages(serverAllocator.getIgnoreIncomingMessages());
68 void comm::Host::assign(const Device* device)
69 throw(RuntimeException) {
70 if(contains(device) == false)
71 a_devices.push_back(device);
75 string comm::Host::asString() const
78 result = "comm::Host { Name: ";
80 result += " | Devices: ";
82 if(a_devices.empty() == true)
85 for(const_device_iterator ii = device_begin(), maxii = device_end(); ii != maxii; ii ++) {
86 result += device(ii)->asString();
91 return result += " }";
95 xml::Node* comm::Host::asXML(xml::Node* parent) const
96 throw(RuntimeException) {
97 xml::Node* host = parent->createChild("comm.Host");
99 host->createAttribute("Name", getName());
100 node = host->createChild("Devices");
102 for(const_device_iterator ii = device_begin(), maxii = device_end(); ii != maxii; ii ++)
103 device(ii)->asXML(node);
105 node = host->createChild("Servers");
107 for(const_server_iterator ss = server_begin(), maxss = server_end(); ss != maxss; ss ++)
108 server(ss)->asXML(node);
114 comm::Server* comm::Host::add(comm::Server* result, const int remotePort, const bool doConnect)
116 result->a_sequence = a_servers.size();
117 a_servers.add(result);
121 string msg("comm::Host::add");
122 msg += (doConnect ? "(server creation and connection) | " : "(server creation, but connection not performed now) | ");
123 msg += result->asString();
124 Logger::information(msg, ANNA_FILE_LOCATION)
127 if(doConnect) result->connect();
128 } catch(RuntimeException& ex) {