2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2011-02-25 16:34:44 +03:00
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
2008-06-17 20:27:32 +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 REQUEST_MANAGER_H_
# define REQUEST_MANAGER_H_
# include "ActionManager.h"
# include "VirtualMachinePool.h"
# include "HostPool.h"
2009-07-09 18:34:34 +04:00
# include "UserPool.h"
2008-11-13 19:21:17 +03:00
# include "VirtualNetworkPool.h"
2010-05-31 20:40:38 +04:00
# include "ImagePool.h"
2011-03-30 21:03:49 +04:00
# include "VMTemplatePool.h"
2011-05-10 20:45:15 +04:00
# include "GroupPool.h"
2008-06-17 20:27:32 +04:00
2011-05-25 14:13:17 +04:00
# include "AuthManager.h"
2008-06-17 20:27:32 +04:00
# include <xmlrpc-c/base.hpp>
# include <xmlrpc-c/registry.hpp>
# include <xmlrpc-c/server_abyss.hpp>
using namespace std ;
extern " C " void * rm_action_loop ( void * arg ) ;
extern " C " void * rm_xml_server_loop ( void * arg ) ;
class RequestManager : public ActionListener
{
public :
2011-05-24 17:36:40 +04:00
RequestManager ( int _port , const string _xml_log_file )
: port ( _port ) , socket_fd ( - 1 ) , xml_log_file ( _xml_log_file )
2008-06-17 20:27:32 +04:00
{
am . addListener ( this ) ;
} ;
2011-05-24 17:36:40 +04:00
~ RequestManager ( ) { } ;
2008-06-17 20:27:32 +04:00
/**
2010-08-05 21:28:28 +04:00
* This functions starts the associated listener thread ( XML server ) , and
2008-06-17 20:27:32 +04:00
* creates a new thread for the Request Manager . This thread will wait in
* an action loop till it receives ACTION_FINALIZE .
* @ return 0 on success .
*/
int start ( ) ;
/**
* Gets the thread identification .
* @ return pthread_t for the manager thread ( that in the action loop ) .
*/
pthread_t get_thread_id ( ) const
{
return rm_thread ;
} ;
/**
2010-08-05 21:28:28 +04:00
*
2008-06-17 20:27:32 +04:00
*/
void finalize ( )
{
am . trigger ( ACTION_FINALIZE , 0 ) ;
} ;
2011-05-24 16:32:39 +04:00
2008-06-17 20:27:32 +04:00
private :
//--------------------------------------------------------------------------
// Friends, thread functions require C-linkage
//--------------------------------------------------------------------------
friend void * rm_xml_server_loop ( void * arg ) ;
friend void * rm_action_loop ( void * arg ) ;
/**
* Thread id for the RequestManager
*/
pthread_t rm_thread ;
/**
* Thread id for the XML Server
*/
pthread_t rm_xml_server_thread ;
/**
* Port number where the connection will be open
*/
int port ;
2010-08-05 21:28:28 +04:00
2008-06-17 20:27:32 +04:00
/*
* FD for the XML server socket
2010-08-05 21:28:28 +04:00
*/
2008-06-17 20:27:32 +04:00
int socket_fd ;
/**
* Filename for the log of the xmlrpc server that listens
*/
string xml_log_file ;
/**
* Action engine for the Manager
*/
ActionManager am ;
/**
* To register XML - RPC methods
*/
xmlrpc_c : : registry RequestManagerRegistry ;
/**
* The XML - RPC server
*/
xmlrpc_c : : serverAbyss * AbyssServer ;
/**
* 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 ) ;
2010-07-15 14:43:27 +04:00
/**
2011-05-24 17:36:40 +04:00
* Register the XML - RPC API Calls
2010-08-05 21:28:28 +04:00
*/
2011-05-24 17:36:40 +04:00
void register_xml_methods ( ) ;
2010-06-01 21:35:42 +04:00
2011-05-24 17:36:40 +04:00
int setup_socket ( ) ;
2010-06-01 21:35:42 +04:00
} ;
2010-08-05 21:28:28 +04:00
2010-05-31 20:40:38 +04:00
2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
# endif