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/Logger.hpp>
10 #include <anna/core/functions.hpp>
11 #include <anna/core/mt/Guard.hpp>
13 #include <anna/xml/Node.hpp>
14 #include <anna/xml/Attribute.hpp>
16 #include <anna/comm/ClientSocket.hpp>
17 #include <anna/comm/Communicator.hpp>
18 #include <anna/comm/Device.hpp>
19 #include <anna/comm/Receiver.hpp>
21 #include <anna/comm/handler/ClientSocket.hpp>
26 void comm::handler::ClientSocket::initialize()
28 if(a_clientSocket == NULL) {
29 string msg(asString());
30 msg += " | comm::ClientSocket was not established";
31 throw RuntimeException(msg, ANNA_FILE_LOCATION);
34 if(a_clientSocket->isConnected() == false)
35 a_clientSocket->connect();
37 setfd(a_clientSocket->getfd());
41 * Se invoca desde Communicator::detach.
43 * [Tx] -> Communicator
45 void comm::handler::ClientSocket::finalize()
47 if(a_clientSocket == NULL)
52 if((receiver = a_clientSocket->getReceiver()) != NULL)
53 receiver->eventBreakConnection(*a_clientSocket);
55 a_clientSocket->close();
56 a_communicator->eventBreakConnection(*a_clientSocket);
57 a_clientSocket = NULL;
60 void comm::handler::ClientSocket::clone()
62 if(a_clientSocket->isConnected() == true)
63 a_clientSocket->close();
65 a_clientSocket->connect();
66 const int fd = a_clientSocket->getfd();
69 string msg("comm::handler::ClientSocket::clone | ");
71 msg += " | Cloning error";
72 throw RuntimeException(msg, ANNA_FILE_LOCATION);
78 string comm::handler::ClientSocket::asString() const
80 string result("comm::handler::ClientSocket { ");
81 result += comm::Handler::asString();
83 result += functions::asString(a_clientSocket);
84 return result += " }";
87 xml::Node* comm::handler::ClientSocket::asXML(xml::Node* parent) const
89 xml::Node* result = parent->createChild("comm.handler.ClientSocket");
90 comm::Handler::asAttribute(result);
93 a_clientSocket->asXML(result);