2009-04-04 03:34:33 +04:00
/* -------------------------------------------------------------------------- */
2013-01-24 19:18:30 +04:00
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
2009-04-04 03:34:33 +04:00
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
# ifndef HOOK_MANAGER_H_
# define HOOK_MANAGER_H_
# include "MadManager.h"
2009-04-06 00:34:33 +04:00
# include "ActionManager.h"
2009-04-04 03:34:33 +04:00
# include "HookManagerDriver.h"
# include "VirtualMachinePool.h"
using namespace std ;
2009-04-06 00:34:33 +04:00
extern " C " void * hm_action_loop ( void * arg ) ;
class HookManager : public MadManager , public ActionListener
2009-04-04 03:34:33 +04:00
{
public :
HookManager ( vector < const Attribute * > & _mads , VirtualMachinePool * _vmpool )
2010-07-08 20:49:37 +04:00
: MadManager ( _mads ) , vmpool ( _vmpool )
2009-04-06 00:34:33 +04:00
{
am . addListener ( this ) ;
} ;
2009-04-04 03:34:33 +04:00
~ HookManager ( ) { } ;
2009-04-06 00:34:33 +04:00
/**
2010-07-08 20:49:37 +04:00
* This functions starts the associated listener thread , and creates a
2009-04-06 00:34:33 +04:00
* new thread for the Hook Manager . This thread will wait in
* an action loop till it receives ACTION_FINALIZE .
* @ return 0 on success .
*/
int start ( ) ;
/**
* Gets the HookManager thread identification .
* @ return pthread_t for the manager thread ( that in the action loop ) .
*/
pthread_t get_thread_id ( ) const
{
return hm_thread ;
} ;
2009-04-04 03:34:33 +04:00
/**
2010-07-08 20:49:37 +04:00
*
2009-04-04 03:34:33 +04:00
*/
2013-10-25 17:16:44 +04:00
int load_mads ( int uid = 0 ) ;
2009-04-04 03:34:33 +04:00
2009-04-06 00:34:33 +04:00
/**
2010-07-08 20:49:37 +04:00
*
2009-04-06 00:34:33 +04:00
*/
void finalize ( )
{
am . trigger ( ACTION_FINALIZE , 0 ) ;
} ;
2009-04-04 03:34:33 +04:00
/**
2010-07-08 20:49:37 +04:00
* Returns a pointer to a Information Manager MAD . The driver is
2009-04-04 03:34:33 +04:00
* searched by its name and owned by oneadmin with uid = 0.
* @ param name of the driver
2010-07-08 20:49:37 +04:00
* @ return the Hook driver owned by uid 0 , with attribute " NAME " equal to
2009-04-04 03:34:33 +04:00
* name or 0 in not found
*/
const HookManagerDriver * get ( )
{
string name ( " NAME " ) ;
2010-07-08 20:49:37 +04:00
2009-04-04 03:34:33 +04:00
return static_cast < const HookManagerDriver * >
( MadManager : : get ( 0 , name , hook_driver_name ) ) ;
} ;
2010-07-08 20:49:37 +04:00
2009-04-04 03:34:33 +04:00
private :
2010-07-08 20:49:37 +04:00
/**
* Generic name for the Hook driver
*/
static const char * hook_driver_name ;
2009-04-04 03:34:33 +04:00
/**
* Pointer to the VirtualMachine Pool
*/
2009-04-06 00:34:33 +04:00
VirtualMachinePool * vmpool ;
2010-07-08 20:49:37 +04:00
2009-04-06 00:34:33 +04:00
/**
* Thread id for the HookManager
*/
pthread_t hm_thread ;
2010-07-08 20:49:37 +04:00
2009-04-06 00:34:33 +04:00
/**
* Action engine for the Manager
*/
ActionManager am ;
/**
2010-07-08 20:49:37 +04:00
* Function to execute the Manager action loop method within a new pthread
2009-04-06 00:34:33 +04:00
* ( requires C linkage )
*/
friend void * hm_action_loop ( void * arg ) ;
/**
* The action function executed when an action is triggered .
* @ param action the name of the action
* @ param arg arguments for the action function
*/
void do_action (
const string & action ,
void * arg ) ;
2009-04-04 03:34:33 +04:00
} ;
# endif /*HOOK_MANAGER_H*/