Remove dynamic exceptions
[anna.git] / source / ldap / Response.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/functions.hpp>
10 #include <anna/core/tracing/Logger.hpp>
11
12 #include <anna/ldap/Response.hpp>
13 #include <anna/ldap/Attribute.hpp>
14 #include <anna/ldap/TimerManager.hpp>
15
16 using namespace std;
17 using namespace anna;
18
19 ldap::Response::response_pool ldap::Response::st_responses;
20
21 //----------------------------------------------------------------------------------------
22 // Se invocan desde ldap::Session
23 //----------------------------------------------------------------------------------------
24 ldap::Response* ldap::Response::instance(const ClassCode::_v classCode, const IdMessage idMessage)
25 noexcept(false) {
26   ldap::Response* result = st_responses.create();
27   result->a_classCode = classCode;
28   result->a_idMessage = idMessage;
29   result->clear();
30   LOGDEBUG(
31     string msg("anna::ldap::Response::instance | ");
32     msg += result->asString();
33     Logger::debug(msg, ANNA_FILE_LOCATION);
34   );
35   return result;
36 }
37
38 void ldap::Response::release(ldap::Response* response)
39 {
40   try {
41     st_responses.release(response);
42   } catch(Exception& ex) {
43     ex.trace();
44   }
45 }
46
47 ldap::Response::Response() :
48   a_classCode(ClassCode::Undefined),
49   a_idMessage(0),
50   a_session(NULL),
51   a_timer(NULL),
52   a_request(NULL) {
53 }
54
55 void ldap::Response::clear()
56 {
57   a_session = NULL;
58   a_resultCode.clear();
59   a_name.clear();
60
61   for(attribute_iterator ii = attribute_begin(), maxii = attribute_end(); ii != maxii; ii ++)
62     attribute(ii)->clear();
63
64   a_attributes.clear();
65   a_referrals.clear();
66   a_timer = NULL;
67   a_request = NULL;
68 }
69
70 void ldap::Response::activateTimer()
71 noexcept(false) {
72   a_timer = TimerManager::instantiate().createTimer(this);
73 }
74
75 void ldap::Response::cancelTimer()
76 {
77   if(a_timer != NULL) {
78     try {
79       TimerManager::instantiate().cancel(a_timer);
80     } catch(RuntimeException& ex) {
81       ex.trace();
82     }
83
84     a_timer = NULL;
85   }
86 }
87
88 ldap::Attribute* ldap::Response::createAttribute(const string& name)
89 noexcept(false) {
90   Attribute* result = a_attributes.create();
91   result->setName(name);
92   return result;
93 }
94
95 string ldap::Response::asString() const
96 {
97   string result("ldap::Response { ");
98   result += ClassCode::asString(a_classCode);
99   result += functions::asText(" | IdMessage: ", a_idMessage);
100   result += " | ";
101   result += a_resultCode.asString();
102   return result += " }";
103 }
104