1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #include <anna/core/mt/Guard.hpp>
39 #include <anna/comm/handler/Manager.hpp>
42 using namespace anna::comm;
44 template <> comm::Communicator* handler::Manager::BinderSocketAllocator::st_communicator = NULL;
45 template <> comm::Communicator* handler::Manager::ServerSocketAllocator::st_communicator = NULL;
46 template <> comm::Communicator* handler::Manager::LocalConnectionAllocator::st_communicator = NULL;
47 template <> comm::Communicator* handler::Manager::RemoteConnectionAllocator::st_communicator = NULL;
48 template <> comm::Communicator* handler::Manager::DatagramSocketAllocator::st_communicator = NULL;
49 template <> comm::Communicator* handler::Manager::ClientSocketAllocator::st_communicator = NULL;
51 void handler::Manager::initialize(Communicator* communicator)
53 BinderSocketAllocator::st_communicator = communicator;
54 ServerSocketAllocator::st_communicator = communicator;
55 LocalConnectionAllocator::st_communicator = communicator;
56 RemoteConnectionAllocator::st_communicator = communicator;
57 DatagramSocketAllocator::st_communicator = communicator;
58 ClientSocketAllocator::st_communicator = communicator;
61 Handler* handler::Manager::createHandler(comm::BinderSocket* binderSocket)
62 throw(RuntimeException) {
63 handler::BinderSocket* result = a_binderSockets.create();
64 result->setup(binderSocket);
68 Handler* handler::Manager::createHandler(comm::ServerSocket* serverSocket)
69 throw(RuntimeException) {
70 handler::ServerSocket* result = a_serverSockets.create();
71 result->setup(serverSocket);
75 Handler* handler::Manager::createHandler(comm::LocalConnection* localConnection)
76 throw(RuntimeException) {
77 handler::LocalConnection* result = a_localConnections.create();
78 result->setup(localConnection);
82 Handler* handler::Manager::createHandler(comm::RemoteConnection* remoteConnection)
83 throw(RuntimeException) {
84 handler::RemoteConnection* result = a_remoteConnections.create();
85 result->setup(remoteConnection);
89 Handler* handler::Manager::createHandler(comm::DatagramSocket* datagramSocket)
90 throw(RuntimeException) {
91 handler::DatagramSocket* result = a_datagramSockets.create();
92 result->setup(datagramSocket);
96 Handler* handler::Manager::createHandler(comm::ClientSocket* clientSocket)
97 throw(RuntimeException) {
98 handler::ClientSocket* result = a_clientSockets.create();
99 result->setup(clientSocket);
103 void handler::Manager::releaseHandler(Handler* handler)
108 switch(handler->getType()) {
109 case Handler::Type::BinderSocket:
110 a_binderSockets.release(static_cast <BinderSocket*>(handler));
112 case Handler::Type::ServerSocket:
113 a_serverSockets.release(static_cast <ServerSocket*>(handler));
115 case Handler::Type::LocalConnection:
116 a_localConnections.release(static_cast <LocalConnection*>(handler));
118 case Handler::Type::RemoteConnection:
119 a_remoteConnections.release(static_cast <RemoteConnection*>(handler));
121 case Handler::Type::DatagramSocket:
122 a_datagramSockets.release(static_cast <DatagramSocket*>(handler));
124 case Handler::Type::ClientSocket:
125 a_clientSockets.release(static_cast <ClientSocket*>(handler));