OSDN Git Service

formatted all files with 'astyle -A8 -HUpc -k3 -z2 -r ./*.cpp ./*.c ./*.h'
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / module / protocol / ip_replication_data_processor.h
1 /*
2  * @file  ip_replication_data_processor.h
3  * @brief ip replication data processor header file.
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
25 #ifndef IP_REPLICATION_DATA_PROCESSOR_H
26 #define IP_REPLICATION_DATA_PROCESSOR_H
27
28 #include <boost/asio.hpp>
29 #include <boost/thread/condition.hpp>
30 #include "logger_enum.h"
31
32 #define IP_MAXLENGTH (40)
33 #define IP_SERVICE_NUMBER (128)
34 #define IP_REPLICATION_MAXLENGTH (256)
35 #define MAX_IP_SESSION_TEMPLIST_SIZE (20000)
36
37 namespace l7vs
38 {
39
40 struct ip_replication_data_header {
41         char virtualserver_ip[IP_MAXLENGTH];
42         unsigned short virtualserver_port;
43         size_t offset;
44         size_t size;
45 };
46
47 struct ip_replication_data {
48         char realserver_ip[IP_MAXLENGTH];
49         unsigned short realserver_port;
50         time_t last_time;
51         int valid;
52 };
53
54 struct ip_replication_temp_data {
55         char op_code;
56         int ip_hash;
57         time_t last_time;
58         boost::asio::ip::tcp::endpoint rs_endpoint;
59 };
60
61 class ip_replication_data_processor
62 {
63 public:
64         //! loglevel get function object type
65         typedef    boost::function< LOG_LEVEL_TAG(void) >
66         getloglevel_func_type;
67         //! log output function object type
68         typedef    boost::function< void (const unsigned int, const std::string &, const char *, int) >
69         logger_func_type;
70
71 public:
72         ip_replication_data_processor(char *ip_replication_area_begin,
73                                       int ip_replication_area_size,
74                                       const boost::asio::ip::tcp::endpoint &virtual_service_endpoint,
75                                       getloglevel_func_type ingetloglevel,
76                                       logger_func_type inputLogFatal,
77                                       logger_func_type inputLogError,
78                                       logger_func_type inputLogWarn,
79                                       logger_func_type inputLogInfo,
80                                       logger_func_type inputLogDebug);
81
82         virtual ~ip_replication_data_processor();
83
84         void put_into_temp_list(const ip_replication_temp_data &data);
85
86         void write_replication_area();
87
88         ip_replication_data *get_replication_area();
89
90         void register_replication_area_lock(boost::function<void(void)> intable_lock);
91
92         void register_replication_area_unlock(boost::function<void(void)> intable_unlock);
93
94 protected:
95         int get_from_temp_list(ip_replication_temp_data &data);
96
97 protected:
98         std::deque<ip_replication_temp_data> temp_list;
99         boost::mutex temp_list_mutex;
100         boost::condition temp_list_condition;
101         ip_replication_data *replication_area;
102         boost::function<void(void)> replication_area_lock;
103         boost::function<void(void)> replication_area_unlock;
104         boost::asio::ip::tcp::endpoint virtual_service_endpoint;
105         getloglevel_func_type getloglevel;        //! get loglevel function object
106         logger_func_type putLogFatal;             //! fatal log output function object
107         logger_func_type putLogError;             //! error log output function object
108         logger_func_type putLogWarn;              //! warn log output function object
109         logger_func_type putLogInfo;              //! info log output function object
110         logger_func_type putLogDebug;             //! debug log output function object
111 };
112
113 }
114
115 #endif // IP_REPLICATION_DATA_PROCESSOR_H