Remove dynamic exceptions
[anna.git] / source / comm / ReceiverFactory.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/mt/Guard.hpp>
10
11 #include <anna/xml/Node.hpp>
12 #include <anna/xml/Attribute.hpp>
13
14 #include <anna/comm/ReceiverFactory.hpp>
15 #include <anna/comm/Receiver.hpp>
16
17 using namespace std;
18 using namespace anna;
19
20 comm::ReceiverFactory::ReceiverFactory(const char* name) :
21   a_name(name) {
22   WHEN_SINGLETHREAD(
23     a_receiver = NULL;
24   )
25 }
26
27 //---------------------------------------------------------------------------------------------
28 // En entornos ST solo habra una unica instancia compartida por todos los comm::ClientSocket
29 //---------------------------------------------------------------------------------------------
30 comm::Receiver* comm::ReceiverFactory::create()
31 noexcept(false) {
32   comm::Receiver* result(NULL);
33   WHEN_SINGLETHREAD(
34
35   if((result = a_receiver) == NULL) {
36   result = a_receiver = do_create();
37     result->initialize();
38   }
39   )
40   WHEN_MULTITHREAD(
41     Guard guard(*this, "comm::ReceiverFactory::create");
42     result = do_create();
43     result->initialize();
44   )
45   return result;
46 }
47
48 void comm::ReceiverFactory::release(comm::Receiver* receiver)
49 {
50   WHEN_MULTITHREAD(
51
52   try {
53     Guard guard(*this, "comm::ReceiverFactory::release");
54     do_release(receiver);
55   } catch(RuntimeException& ex) {
56   ex.trace();
57   }
58   );
59 }
60
61 xml::Node* comm::ReceiverFactory::asXML(xml::Node* parent) const
62 {
63   xml::Node* result = parent->createChild("Receiver");
64   result->createAttribute("Name", a_name);
65   return result;
66 }
67
68
69