From dedf181a11afd2b79c266be9f3026dddc2006133 Mon Sep 17 00:00:00 2001 From: nakai Date: Thu, 8 Jan 2009 08:11:26 +0000 Subject: [PATCH] =?utf8?q?session=5Fthread=5Fcontrol.h=E3=82=92=E8=BF=BD?= =?utf8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://10.144.169.20/repos/um/branches/l7vsd-3.x-shamshel@5741 1ed66053-1c2d-0410-8867-f7571e6e31d3 --- include/l7vsadm.h | 200 +++++++++++++++++++++++++-------------- include/session_thread_control.h | 44 +++++++++ 2 files changed, 174 insertions(+), 70 deletions(-) create mode 100644 include/session_thread_control.h diff --git a/include/l7vsadm.h b/include/l7vsadm.h index a3dfbf5b..20dc658f 100644 --- a/include/l7vsadm.h +++ b/include/l7vsadm.h @@ -1,96 +1,156 @@ // -// @file l7vsadm -// @brief main module of l7vsadm +// l7vsadm.h +// ^^^^^^^^^ +// l7vsd control application. // -// l7vsadm : virtual server administration program for l7vsd -// copyright(c) sdy corporation.2008 -// mail: n.nakai at sdy.co.jp -// Copyright (c) 2008 norihisa nakai (n dot nakai at sdy dot co do jp) +// Copyright (c) Norihisa Nakai ( n dot nakai at sdy dot co dot jp ) // -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef L7VSADM_H #define L7VSADM_H - #include #include -#include -#include -#include "l7command.h" +#include +#include +#include "l7vs_command.h" -#ifndef MAXBUFFER_SIZE - #define MAXBUFFER_SIZE (65535) -#endif +namespace l7vs{ -namespace l7vsd{ +template < class T > +typename T::endpoint string_to_endpoint( std::string& str ){ + std::string::size_type pos = str.find( ":" ); + std::string hostname = str.substr( 0, pos ); + std::string portname = str.substr( pos+1, str.length() ); + boost::asio::io_service io_service; + typename T::resolver resolver(io_service); + typename T::resolver::query query( hostname, portname ); + typename T::resolver::iterator end; + typename T::resolver::iterator itr = resolver.resolve( query ); + if( itr == end ) return typename T::endpoint(); + return *itr; +} class l7vsadm{ protected: + // + // command parse functions. + // + //! list command parse function + bool parse_list_func( l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); + //! virtualservice command parse function + bool parse_vs_func( l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); + //! realserver_command parse function + bool parse_rs_func( l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); + //! replication command parse function + bool parse_replication_func( l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); + //! log command parse function + bool parse_log_func( l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); + //! snmpagent command parse function + bool parse_snmp_func( l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); + //! help command parse func + bool parse_help_func( l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); - typedef std::map< std::string, boost::function< bool (l7vsadm_request::COMMAND_CODE_TAG, int, char*[] )> > - command_func_map_type; - typedef std::map< std::string, boost::function< bool (int&, int, char*[] ) > > - option_func_map_type; - - command_func_map_type command_dic; - - boost::array send_data; - boost::array recv_data; - l7vsadm_request request; - l7vsadm_response response; - - bool cmd_list_parse( const l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); - option_func_map_type option_list_dic; - bool option_list_numeric_parse( int&, int, char*[] ); + // + // option parse functions. + // + // + // list option functions. + bool parse_opt_list_numeric_func( int&, int, char*[] ); + // + // virtualservice option functions. + bool parse_opt_vs_target_func( int&, int, char*[] ); + bool parse_opt_vs_module_func( int&, int, char*[] ); + bool parse_opt_vs_scheduler_func( int&, int, char*[] ); + bool parse_opt_vs_upper_func( int&, int, char*[] ); + bool parse_opt_vs_bypass_func( int&, int, char*[] ); + bool parse_opt_vs_flag_func( int&, int, char*[] ); + bool parse_opt_vs_qosup_func( int&, int, char*[] ); + bool parse_opt_vs_qosdown_func( int&, int, char*[] ); + bool parse_opt_vs_udp_func( int&, int, char*[] ); + // realserver option function + bool parse_opt_rs_weight_func( int&, int, char*[] ); + bool parse_opt_rs_realserver_func( int&, int, char*[] ); + // replication option function + bool parse_opt_replication_switch_func( int&, int, char*[] ); + bool parse_opt_replication_force_func( int&, int, char*[] ); + bool parse_opt_replication_dump_func( int&, int, char*[] ); + // log option function + bool parse_opt_log_category_func( int&, int, char*[] ); + bool parse_opt_log_level_func( int&, int, char*[] ); + // snmp option function + bool parse_opt_snmp_category_func( int&, int, char*[] ); + bool parse_opt_snmp_level_func( int&, int, char*[] ); + // parameter option function + bool parse_opt_parameter_reload_func( int&, int, char*[] ); - bool cmd_vs_parse( const l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); - option_func_map_type option_vs_dic; - bool option_vs_flag_parsr( int&, int, char*[] ); - bool option_vs_target_parse( int&, int, char*[] ); - bool option_vs_module_parse( int&, int, char*[] ); - bool option_vs_scheduler_parse( int&, int, char*[] ); - bool option_vs_upper_parse( int&, int, char*[] ); - bool option_vs_bypass_parse( int&, int, char*[] ); - bool option_vs_qos_service_parse( int&, int, char*[] ); - bool option_vs_qos_client_parse( int&, int, char*[] ); - bool option_vs_udp_parse( int&, int, char*[] ); + // command parse function object.type. + typedef boost::function< bool ( l7vsadm_request::COMMAND_CODE_TAG, int, char* [] ) > + parse_cmd_func_type; + // command string - parse function object map type. + typedef std::map< std::string, parse_cmd_func_type > + parse_cmd_map_type; + // command function map dictionary. + parse_cmd_map_type command_dic; - bool cmd_rs_parse( const l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); - option_func_map_type option_rs_dic; - bool option_rs_weight( int&, int, char*[] ); + // option parse function object type. + typedef boost::function< bool ( int&, int, char*[] ) > + parse_opt_func_type; + // option string - parse function object map type + typedef std::map< std::string, parse_opt_func_type > + parse_opt_map_type; + // list option function map dictionary. + parse_opt_map_type list_option_dic; + // virtualservice option function map dictionary + parse_opt_map_type vs_option_dic; + // realserver option function map dictionary + parse_opt_map_type rs_option_dic; + // replication option function map dictionary + parse_opt_map_type replication_option_dic; + // log option function map dictionary + parse_opt_map_type log_option_dic; + // snmp option_function map dictionary + parse_opt_map_type snmp_option_dic; + // parameter option function map dictionary + parse_opt_map_type parameter_option_dic; - bool cmd_replicaton_parse( const l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); - option_func_map_type option_replication_dic; - bool option_replication_switch( int&, int, char*[] ); - bool option_replication_force( int&, int, char*[] ); - bool option_replication_dump( int&, int, char*[] ); + // log category string -> log category enum convert map type. + typedef std::map< std::string, LOG_CATEGORY_TAG > string_logcategory_map_type; + // log category string to log category enum dictionary. + string_logcategory_map_type string_logcategory_dic; + // snmp log category string to snmp log category enum dictionary. + string_logcategory_map_type string_snmp_logcategory_dic; + // log level string -> log level enum convert map type + typedef std::map< std::string, LOG_LEVEL_TAG > string_loglevel_map_type; + // log level string to log level enum dictionary + string_loglevel_map_type string_loglevel_dic; + // parameter category string -> parameter category enum convert map type + typedef std::map< std::string, PARAMETER_COMPONENT_TAG > string_parameter_map_type; + string_parameter_map_type string_parameter_dic; - bool cmd_log_parse( const l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); - option_func_map_type option_log_dic; - bool option_log_category( int&, int, char*[] ); - bool option_log_level( int&, int, char*[] ); + // constractor + l7vsadm(); - bool cmd_snmp_parse( const l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); - option_func_map_type option_snmp_dic; - bool option_snmp_category( int&, int, char*[] ); - bool option_snmp_level( int&, int, char*[] ); + // usage function + std::string usage(); - bool cmd_paramter_parse( const l7vsadm_request::COMMAND_CODE_TAG, int, char*[] ); - option_func_map_type option_parameter_dic; - bool option_parameter_reload( int&, int, char*[] ); + // + // l7vsd request data + l7vsadm_request request; + l7vsd_response response; - bool cmd_help_parse( const l7vsadm_request::COMMAND_CODE_TAG, int ,char*[] ); + // + // l7vsadm using datas. + bool numeric_flag; //! numeric flag + boost::asio::io_service io_service; //! io_service - bool request_send(); - bool response_recv(); - void usage(FILE* fp); - bool pase_command( int argc, char* argv[] ); public: - l7vsadm(); - ~l7vsadm(); + //! execute function + bool execute( int, char*[] ); }; -};//namespace l7vsd - +} //namespace l7vs + + #endif //L7VSADM_H diff --git a/include/session_thread_control.h b/include/session_thread_control.h new file mode 100644 index 00000000..f6408c76 --- /dev/null +++ b/include/session_thread_control.h @@ -0,0 +1,44 @@ +#ifndef SESSION_THRAED_CONTROL_H +#define SESSION_THREAD_CONTROL_H +#include +#include +#include +#include +#include "session.h" + +namespace l7vs{ + +class session_thread_control : private boost::noncopyable{ +public: + typedef boost::shared_ptr< boost::thread > thread_ptr; + typedef boost::shared_ptr< session > session_ptr; +protected: + enum condition_tag{ + INIT = 0, + WAIT, + RUNNING, + FINISHING, + EXIT + }; + + thread_ptr upthread; + thread_ptr downthread; + boost::mutex condition_mutex; + session_ptr session; + void upstream_run(); + void downstream_run(); +public: + friend class session; + friend class virtualservice; + + session_thread_control( session_ptr ); + void startupstream(); // virtualserviceのmapに入れるときにstartを呼ぶ + void startdownstream(); // sessionからリクエストがあったときに呼ばれる + void stopupstream(); // thread_pool mapに入れるときにstopupstream()を呼ぶ + void stopdownstream(); // thread_pool mapに入れるときにstopdownstream()を呼ぶ + void join(); // 全てのthreadを停止状態にするときにjoin()を呼ぶ +}; + +}// namespace l7vs + +#endif //SESSION_THREAD_CONTROL_H \ No newline at end of file -- 2.11.0