dbproxy.h
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <common.h>
class user_t;
#undef BIND_PROTO_CMD
#undef BIND_PROTO_CMD_NO_CB
#define BIND_PROTO_CMD(cmd, fun_name, proto_name)\
static const CMD_ID db_##proto_name##_cmd = cmd;
#define BIND_PROTO_CMD_NO_CB(cmd, fun_name, proto_name)\
static const CMD_ID db_##proto_name##_cmd = cmd;
#include <db_cmd.h>
#undef BIND_PROTO_CMD
#undef BIND_PROTO_CMD_NO_CB
#define DBPROXY_MSG_HANDLE_FUN_PAR el::lib_tcp_peer_info_t* peer_fd_info, google::protobuf::Message* msg, USER_ID uid, uint32_t sequence_generator, uint32_t ret, user_t* user
DEF_MSG_HANDLE_FUN(dbproxy_t, DBPROXY)
class dbproxy_t
{
public:
dbproxy_t();
virtual ~dbproxy_t();
//please fill the 'handle_callback_user' parameters need to deal with the returned message
int send_msg(google::protobuf::Message* msg, USER_ID uid, CMD_ID cmd,
user_t* handle_callback_user = NULL);
int on_recv(el::lib_tcp_peer_info_t* peer_fd_info, CMD_ID cmd, char* pdata,
int len, USER_ID uid, uint32_t seq, uint32_t ret);
void clear_handle_callback_user(user_t* user);
el::lib_tcp_peer_info_t* fd_info;
void offline();
protected:
#undef BIND_PROTO_CMD
#undef BIND_PROTO_CMD_NO_CB
#define BIND_PROTO_CMD(cmd, fun_name, proto_name)\
int fun_name##_res(DBPROXY_MSG_HANDLE_FUN_PAR)
#define BIND_PROTO_CMD_NO_CB(cmd, fun_name, proto_name)
#include <db_cmd.h>
#undef BIND_PROTO_CMD
#undef BIND_PROTO_CMD_NO_CB
private:
//return: sequence number
uint32_t add_handle_callback_user(user_t* user);
int send(const void* data, uint32_t len);
user_t* pop_handle_callback_user(uint32_t seq);
//key:sequence number, val:handle_callback_user
std::map<uint32_t, user_t*> handle_callback_user_map;
DBPROXY_MSG_MAP_T msg_map;
};
extern dbproxy_t* g_dbproxy;