OSDN Git Service

trunk整理
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / include / module_base.h
1 /*
2  *    @file    module_base.h
3  *    @brief    shared object module abstract class
4  *
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6  * Copyright (C) 2009  NTT COMWARE Corporation.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  **********************************************************************/
24 #ifndef    MODULE_BASE_H
25 #define    MODULE_BASE_H
26
27 #include <string>
28 #include <boost/asio.hpp>
29 #include <boost/function.hpp>
30
31 #include "logger.h"
32
33 namespace l7vs
34 {
35
36 //! @class    module_base
37 //! @brief    protocol module and schedule module base class
38 //! @brief    all module class is extend this class.
39 class module_base
40 {
41 public:
42         //! loglevel get function object type
43         typedef    boost::function< LOG_LEVEL_TAG(void) >
44         getloglevel_func_type;
45         //! log output function object type
46         typedef    boost::function< void (const unsigned int, const std::string &, const char *, int) >
47         logger_func_type;
48         //! replication payment memory function object type
49         typedef    boost::function< void*(const std::string &, unsigned int *) >
50         replicationpaymemory_func_type;
51 protected:
52         std::string                        name;            //!< module name string
53         getloglevel_func_type            getloglevel;    //!< get loglevel function object
54         logger_func_type                putLogFatal;    //!< fatal log output function object
55         logger_func_type                putLogError;    //!< error log output function object
56         logger_func_type                putLogWarn;        //!< warn log output function object
57         logger_func_type                putLogInfo;        //!< info log output function object
58         logger_func_type                putLogDebug;    //!< debug log output function object
59
60         //! replication memory payment method
61         replicationpaymemory_func_type    replication_pay_memory;
62
63         //! replication area lock function object
64         boost::function< void(void) >    replication_area_lock;
65         //! replication area unlock function object
66         boost::function< void(void) >    replication_area_unlock;
67
68         //! virtual service endpoint tcp
69         boost::asio::ip::tcp::endpoint virtual_service_endpoint_tcp;
70         //! virtual service endpoint udp
71         boost::asio::ip::udp::endpoint virtual_service_endpoint_udp;
72
73 public:
74         //! constructor
75         module_base(std::string in_modulename) {
76                 name = in_modulename;
77         }
78         //! destructor
79         virtual ~module_base() {}
80         //! tcp protocol support check
81         //! @return tcp support is true
82         //! @return tcp not-support is false
83         virtual    bool    is_tcp() = 0;
84         //! udp protocol support check
85         //! @return udp support is true
86         //! @return udp not-support is false
87         virtual    bool    is_udp() = 0;
88         //! module name getter
89         //! @return module name
90         const std::string    &get_name() {
91                 return name;
92         }
93
94         //! logger function setter
95         //! @param[in]    loglevel get function object
96         //! @param[in]    fatal log output function object
97         //! @param[in]    error log output function object
98         //!    @param[in]    warn log output function object
99         //!    @param[in]    info log output function object
100         //! @param[in]    debug log output function object
101         void    init_logger_functions(
102                 getloglevel_func_type    ingetloglevel,
103                 logger_func_type        inputLogFatal,
104                 logger_func_type        inputLogError,
105                 logger_func_type        inputLogWarn,
106                 logger_func_type        inputLogInfo,
107                 logger_func_type        inputLogDebug) {
108                 getloglevel = ingetloglevel;
109                 putLogFatal = inputLogFatal;
110                 putLogError = inputLogError;
111                 putLogWarn    = inputLogWarn;
112                 putLogInfo    = inputLogInfo;
113                 putLogDebug = inputLogDebug;
114         }
115
116         //! replication function object setter.
117         //! @param[in]    replication pay memory function object
118         //! @param[in]    replication lock function object
119         //! @param[in]    replication unlock function object
120         //! @param[in]    virtual service endpoint tcp
121         //! @param[in]    virtual service endpoint udp
122         void    init_replication_functions(
123                 replicationpaymemory_func_type  inreplication_pay_memory,
124                 boost::function< void(void) > inlock_func,
125                 boost::function< void(void) > inunlock_func,
126                 const boost::asio::ip::tcp::endpoint &invirtual_service_endpoint_tcp,
127                 const boost::asio::ip::udp::endpoint &invirtual_service_endpoint_udp) {
128                 replication_pay_memory = inreplication_pay_memory;
129                 replication_area_lock = inlock_func;
130                 replication_area_unlock = inunlock_func;
131                 virtual_service_endpoint_tcp = invirtual_service_endpoint_tcp;
132                 virtual_service_endpoint_udp = invirtual_service_endpoint_udp;
133         }
134
135         // For replication interface
136         // when call this function, write data to replication area.
137         // Caution: Not need loop inside.
138         //      Because Loop and Timer control is in virtual_service.
139         //      virtual_service call replication_interrupt in specified time at once.
140         //      when called, replication_interrupt write data at once.
141         //! replication interval interrupt
142         //! timer thread call this function. from virtualservice.
143         virtual    void    replication_interrupt() = 0;
144 };
145
146 }    //namespace l7vsd
147
148 #endif //MODULE_BASE_H