diff --git a/include/ActionManager.h b/include/ActionManager.h index 80ccf6edb4..08d05756c5 100644 --- a/include/ActionManager.h +++ b/include/ActionManager.h @@ -35,7 +35,6 @@ public: */ enum Type { - NONE, FINALIZE, TIMER, USER @@ -48,7 +47,12 @@ public: ActionRequest(Type __type): _type(__type){}; - ActionRequest(): _type(NONE){}; + virtual ~ActionRequest(){}; + + virtual ActionRequest * clone() const + { + return new ActionRequest(_type); + } protected: Type _type; @@ -108,9 +112,6 @@ private: case ActionRequest::USER: user_action(ar); break; - - case ActionRequest::NONE: - break; } } }; @@ -188,7 +189,7 @@ private: /** * Queue of pending actions, processed in a FIFO manner */ - std::queue actions; + std::queue actions; /** * Action synchronization is implemented using the pthread library, diff --git a/include/AuthManager.h b/include/AuthManager.h index c331c6961e..a31e03b623 100644 --- a/include/AuthManager.h +++ b/include/AuthManager.h @@ -46,6 +46,9 @@ public: AMAction(Actions a, AuthRequest *r):ActionRequest(ActionRequest::USER), _action(a), _request(r){}; + AMAction(const AMAction& o):ActionRequest(o._type), _action(o._action), + _request(o._request){}; + Actions action() const { return _action; @@ -56,6 +59,11 @@ public: return _request; } + ActionRequest * clone() const + { + return new AMAction(*this); + } + private: Actions _action; diff --git a/include/DispatchManager.h b/include/DispatchManager.h index 2532b6634c..4ba713c83c 100644 --- a/include/DispatchManager.h +++ b/include/DispatchManager.h @@ -53,6 +53,9 @@ public: DMAction(Actions a, int v):ActionRequest(ActionRequest::USER), _action(a), _vm_id(v){}; + DMAction(const DMAction& o):ActionRequest(o._type), _action(o._action), + _vm_id(o._vm_id){}; + Actions action() const { return _action; @@ -63,6 +66,11 @@ public: return _vm_id; } + ActionRequest * clone() const + { + return new DMAction(*this); + } + private: Actions _action; diff --git a/include/IPAMManager.h b/include/IPAMManager.h index f43fcbf454..455e28f59f 100644 --- a/include/IPAMManager.h +++ b/include/IPAMManager.h @@ -45,6 +45,9 @@ public: IPMAction(Actions a, IPAMRequest *r):ActionRequest(ActionRequest::USER), _action(a), _request(r){}; + IPMAction(const IPMAction& o):ActionRequest(o._type), _action(o._action), + _request(o._request){}; + Actions action() const { return _action; @@ -55,6 +58,11 @@ public: return _request; } + ActionRequest * clone() const + { + return new IPMAction(*this); + } + private: Actions _action; diff --git a/include/LifeCycleManager.h b/include/LifeCycleManager.h index 193b106931..655e28f70b 100644 --- a/include/LifeCycleManager.h +++ b/include/LifeCycleManager.h @@ -107,6 +107,9 @@ public: ActionRequest(ActionRequest::USER), _action(a), _vm_id(v), _uid(u), _gid(g), _req_id(r){}; + LCMAction(const LCMAction& o):ActionRequest(o._type), _action(o._action), + _vm_id(o._vm_id), _uid(o._uid), _gid(o._gid), _req_id(o._req_id){}; + Actions action() const { return _action; @@ -132,6 +135,11 @@ public: return _req_id; } + ActionRequest * clone() const + { + return new LCMAction(*this); + } + private: Actions _action; diff --git a/include/TransferManager.h b/include/TransferManager.h index ef646c5cc2..ae10ce0369 100644 --- a/include/TransferManager.h +++ b/include/TransferManager.h @@ -61,6 +61,9 @@ public: TMAction(Actions a, int v):ActionRequest(ActionRequest::USER), _action(a), _vm_id(v){}; + TMAction(const TMAction& o):ActionRequest(o._type), _action(o._action), + _vm_id(o._vm_id){}; + Actions action() const { return _action; @@ -71,6 +74,11 @@ public: return _vm_id; } + ActionRequest * clone() const + { + return new TMAction(*this); + } + private: Actions _action; diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index 3bd7234b1e..ff8d943b87 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -65,6 +65,9 @@ public: VMMAction(Actions a, int v):ActionRequest(ActionRequest::USER), _action(a), _vm_id(v){}; + VMMAction(const VMMAction& o):ActionRequest(o._type), _action(o._action), + _vm_id(o._vm_id){}; + Actions action() const { return _action; @@ -75,6 +78,11 @@ public: return _vm_id; } + ActionRequest * clone() const + { + return new VMMAction(*this); + } + private: Actions _action; diff --git a/src/authm/AuthManager.cc b/src/authm/AuthManager.cc index a5d6e7f3f0..f1c2cfc691 100644 --- a/src/authm/AuthManager.cc +++ b/src/authm/AuthManager.cc @@ -160,7 +160,7 @@ int AuthManager::start() void AuthManager::user_action(const ActionRequest& ar) { const AMAction& auth_ar = static_cast(ar); - AuthRequest * request = auth_ar.request(); + AuthRequest * request = auth_ar.request(); if ( request == 0 ) { diff --git a/src/common/ActionManager.cc b/src/common/ActionManager.cc index 66ea46af3e..2a081118e6 100644 --- a/src/common/ActionManager.cc +++ b/src/common/ActionManager.cc @@ -45,7 +45,7 @@ void ActionManager::trigger(const ActionRequest& ar ) { lock(); - actions.push(ar); + actions.push(ar.clone()); pthread_cond_signal(&cond); @@ -62,7 +62,7 @@ void ActionManager::loop(time_t timer, const ActionRequest& trequest) int finalize = 0; int rc; - ActionRequest action; + ActionRequest * action; timeout.tv_sec = time(NULL) + timer; timeout.tv_nsec = 0; @@ -79,7 +79,7 @@ void ActionManager::loop(time_t timer, const ActionRequest& trequest) rc = pthread_cond_timedwait(&cond,&mutex, &timeout); if ( rc == ETIMEDOUT ) - actions.push(trequest); + actions.push(trequest.clone()); } else pthread_cond_wait(&cond,&mutex); @@ -90,9 +90,9 @@ void ActionManager::loop(time_t timer, const ActionRequest& trequest) unlock(); - listener->_do_action(action); + listener->_do_action(*action); - switch(action.type()) + switch(action->type()) { case ActionRequest::TIMER: timeout.tv_sec = time(NULL) + timer; @@ -106,6 +106,8 @@ void ActionManager::loop(time_t timer, const ActionRequest& trequest) default: break; } + + delete action; } }