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 Server* result = serverAllocator.apply();
63 result->setIgnoreIncomingMessages(serverAllocator.getIgnoreIncomingMessages());
67 void comm::Host::assign(const Device* device)
68 throw(RuntimeException) {
69 if(contains(device) == false)
70 a_devices.push_back(device);
74 string comm::Host::asString() const
77 result = "comm::Host { Name: ";
79 result += " | Devices: ";
81 if(a_devices.empty() == true)
84 for(const_device_iterator ii = device_begin(), maxii = device_end(); ii != maxii; ii ++) {
85 result += device(ii)->asString();
90 return result += " }";
94 xml::Node* comm::Host::asXML(xml::Node* parent) const
95 throw(RuntimeException) {
96 xml::Node* host = parent->createChild("comm.Host");
98 host->createAttribute("Name", getName());
99 node = host->createChild("Devices");
101 for(const_device_iterator ii = device_begin(), maxii = device_end(); ii != maxii; ii ++)
102 device(ii)->asXML(node);
104 node = host->createChild("Servers");
106 for(const_server_iterator ss = server_begin(), maxss = server_end(); ss != maxss; ss ++)
107 server(ss)->asXML(node);
113 comm::Server* comm::Host::add(comm::Server* result, const int remotePort, const bool doConnect)
115 result->a_sequence = a_servers.size();
116 a_servers.add(result);
120 string msg("comm::Host::add");
121 msg += (doConnect ? "(server creation and connection) | " : "(server creation, but connection not performed now) | ");
122 msg += result->asString();
123 Logger::information(msg, ANNA_FILE_LOCATION)
126 if(doConnect) result->connect();
127 } catch(RuntimeException& ex) {