Solve legacy problem with clear operation (coredump with running threads)
[anna.git] / source / comm / handler / BinderSocket.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 #include <anna/core/tracing/Logger.hpp>
10 #include <anna/core/functions.hpp>
11 #include <anna/core/mt/Guard.hpp>
12
13 #include <anna/xml/Node.hpp>
14 #include <anna/xml/Attribute.hpp>
15
16 #include <anna/comm/Communicator.hpp>
17 #include <anna/comm/internal/BinderSocket.hpp>
18
19 #include <anna/comm/handler/BinderSocket.hpp>
20
21 using namespace std;
22 using namespace anna;
23
24 //-----------------------------------------------------------------------
25 // La apertura de cierre de este Socket se hace desde el comm::Socket.
26 //-----------------------------------------------------------------------
27 void comm::handler::BinderSocket::initialize()
28 throw(RuntimeException) {
29   if(a_binderSocket == NULL) {
30     string msg(asString());
31     msg += " | comm::BinderSocket was not established";
32     throw RuntimeException(msg, ANNA_FILE_LOCATION);
33   }
34
35   setfd(a_binderSocket->getfd());
36 }
37
38 //---------------------------------------------------------------------------------------
39 // Cuando detecta actividad lo unico que hace es invocar al metodo del BinderSocket
40 // que deberia estar esperando la respuesta para saber el 'fd' del nuevo socket
41 // compartido que va a crear.
42 //---------------------------------------------------------------------------------------
43 void comm::handler::BinderSocket::apply()
44 throw(RuntimeException) {
45   Guard guard(a_binderSocket);
46   a_binderSocket->responseBind();
47 }
48
49 void comm::handler::BinderSocket::finalize()
50 throw() {
51   if(a_binderSocket == NULL)
52     return;
53
54   Guard guard(a_binderSocket);
55   a_binderSocket->close();
56   a_binderSocket = NULL;
57 }
58
59 string comm::handler::BinderSocket::asString() const
60 throw() {
61   string result("comm::handler::BinderSocket { ");
62   result += comm::Handler::asString();
63   result += " | ";
64   result += functions::asString(a_binderSocket);
65   return result += " }";
66 }
67
68 xml::Node* comm::handler::BinderSocket::asXML(xml::Node* parent) const
69 throw() {
70   xml::Node* result = parent->createChild("comm.handler.BinderSocket");
71   comm::Handler::asAttribute(result);
72
73   if(a_binderSocket)
74     a_binderSocket->asXML(result);
75
76   return result;
77 }
78
79