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>
11 #include <anna/app/functions.hpp>
13 #include <anna/timex/Engine.hpp>
15 #include <anna/ldap/TimerManager.hpp>
16 #include <anna/ldap/internal/Timer.hpp>
17 #include <anna/ldap/Response.hpp>
18 #include <anna/ldap/Session.hpp>
23 ldap::TimerManager::TimerManager() :
24 timex::TimeEventObserver("anna::ldap::TimerManager"),
25 a_timeController(NULL) {
28 //-------------------------------------------------------------------------------------------------------
29 // (1) Bloquea el TimerManager el primero para mantener siempre el mismo orden de acceso a la
30 // seccion critica, lo que evita interbloqueos.
31 //-------------------------------------------------------------------------------------------------------
32 ldap::Timer* ldap::TimerManager::createTimer(Response* response)
33 throw(RuntimeException) {
36 if(a_timeController == NULL)
37 a_timeController = app::functions::component <timex::Engine> (ANNA_FILE_LOCATION);
39 Guard guard(a_timeController, "anna::ldap::TimerManager::createTimer"); // (1)
40 result = a_timers.create();
41 const ClassCode::_v v = response->getClassCode();
42 result->setId((timex::TimeEvent::Id) response);
43 result->setObserver(this);
44 result->setResponse(response);
45 result->setTimeout(response->getSession()->getTimeout(v));
47 string msg("anna::ldap::TimerManager::createTimer | ");
48 msg += result->asString();
49 Logger::debug(msg, ANNA_FILE_LOCATION);
51 a_timeController->activate(result);
55 void ldap::TimerManager::cancel(ldap::Timer* timer)
61 string msg("anna::ldap::TimerManager::cancel | ");
62 msg += timer->asString();
63 Logger::debug(msg, ANNA_FILE_LOCATION);
67 if(a_timeController == NULL)
68 a_timeController = app::functions::component <timex::Engine> (ANNA_FILE_LOCATION);
70 a_timeController->cancel(timer);
71 } catch(RuntimeException& ex) {
76 //------------------------------------------------------------------------------------------
77 // Se invoca automaticamente desde timex::Engine
78 //------------------------------------------------------------------------------------------
79 void ldap::TimerManager::release(timex::TimeEvent* timeEvent)
81 Timer* timer = static_cast <Timer*>(timeEvent);
82 timer->setResponse(NULL);
83 a_timers.release(timer);