2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2022-04-07 20:49:58 +03:00
/* Copyright 2002-2022, OpenNebula Project, OpenNebula Systems */
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 <xmlrpc-c/base.hpp>
# include <xmlrpc-c/registry.hpp>
# include <xmlrpc-c/server_abyss.hpp>
2019-12-10 13:45:15 +03:00
# include <set>
2020-09-10 14:32:52 +03:00
# include <thread>
# include <atomic>
# include <mutex>
2019-12-10 13:45:15 +03:00
2020-09-10 14:32:52 +03:00
class ConnectionManager ;
2008-06-17 20:27:32 +04:00
2020-07-24 17:00:59 +03:00
class RequestManager
2008-06-17 20:27:32 +04:00
{
public :
2013-07-31 18:40:45 +04:00
RequestManager (
2020-07-02 23:42:10 +03:00
const std : : string & _port ,
2013-07-31 18:40:45 +04:00
int _max_conn ,
int _max_conn_backlog ,
int _keepalive_timeout ,
int _keepalive_max_conn ,
int _timeout ,
2020-07-02 23:42:10 +03:00
const std : : string & _xml_log_file ,
const std : : string & call_log_format ,
const std : : string & _listen_address ,
2015-02-20 17:10:57 +03:00
int message_size ) ;
2008-06-17 20:27:32 +04:00
2020-09-10 14:32:52 +03: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 ( ) ;
2020-07-24 17:00:59 +03:00
void finalize ( ) ;
2008-06-17 20:27:32 +04:00
2018-10-09 12:05:08 +03:00
/**
* @ return an AbyssServer to run xmlrpc connections
*/
xmlrpc_c : : serverAbyss * create_abyss ( ) ;
2011-05-24 16:32:39 +04:00
2020-07-02 23:42:10 +03:00
bool exist_method ( const std : : string & call )
2019-09-09 15:43:51 +03:00
{
return RequestManagerRegistry . exist ( call ) ;
}
2008-06-17 20:27:32 +04:00
private :
2019-09-09 15:43:51 +03:00
struct NebulaRegistry
{
std : : set < std : : string > registered_methods ;
xmlrpc_c : : registry registry ;
void addMethod ( std : : string const name , xmlrpc_c : : methodPtr const methodP )
{
registered_methods . insert ( name ) ;
registry . addMethod ( name , methodP ) ;
} ;
2020-07-02 23:42:10 +03:00
bool exist ( const std : : string & call )
2019-09-09 15:43:51 +03:00
{
return registered_methods . find ( call ) ! = registered_methods . end ( ) ;
}
} ;
2020-09-10 14:32:52 +03:00
/**
* XML Server main thread loop . Waits for client connections and starts
* a new thread to handle the request .
*/
void xml_server_loop ( ) ;
2008-06-17 20:27:32 +04:00
/**
* Thread id for the XML Server
*/
2020-09-10 14:32:52 +03:00
std : : thread xml_server_thread ;
/**
* Manage the number of connections to the RM
*/
std : : unique_ptr < ConnectionManager > cm ;
/**
* Flag to end the main server loop
*/
std : : mutex end_lock ;
std : : atomic < bool > end ;
2008-06-17 20:27:32 +04:00
/**
* Port number where the connection will be open
*/
2020-07-02 23:42:10 +03:00
std : : string 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 ;
2013-07-31 14:28:13 +04:00
/**
* Max connections
*/
int max_conn ;
/*
* Max backlog connections
*/
int max_conn_backlog ;
/*
* Keepalive timeout
*/
int keepalive_timeout ;
/*
* Keepalive max conn
*/
int keepalive_max_conn ;
/*
* Timeout
*/
int timeout ;
2008-06-17 20:27:32 +04:00
/**
* Filename for the log of the xmlrpc server that listens
*/
2020-07-02 23:42:10 +03:00
std : : string xml_log_file ;
2008-06-17 20:27:32 +04:00
2015-07-07 00:34:47 +03:00
/**
* Specifies the address xmlrpc server will bind to
*/
2020-07-02 23:42:10 +03:00
std : : string listen_address ;
2015-07-07 00:34:47 +03:00
2008-06-17 20:27:32 +04:00
/**
* To register XML - RPC methods
*/
2019-09-09 15:43:51 +03:00
NebulaRegistry RequestManagerRegistry ;
2008-06-17 20:27:32 +04:00
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 ( ) ;
2017-02-03 16:19:15 +03:00
} ;
2010-05-31 20:40:38 +04:00
2008-06-17 20:27:32 +04:00
# endif