statisitcs_srv.cpp
2.89 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "statisitcs_srv.h"
#include <statisitcs.pb.h>
#include <proto_header.h>
statisitcs_t* g_statisitcs;
int statisitcs_t::send_msg( google::protobuf::Message* msg, USER_ID uid, CMD_ID cmd )
{
proto_head_t proto_head;
proto_head.cmd = cmd;
proto_head.id = uid;
try{
static void* sb = this->send_msg_buf.send_data + proto_head_t::PROTO_HEAD_LEN;
static const int sb_len = sizeof(this->send_msg_buf.send_data) - proto_head_t::PROTO_HEAD_LEN;
msg->SerializeToArray(sb, sb_len);
uint32_t body_len = msg->ByteSize();
// TRACE_LOG("======>s2center msg [uid:%" PRIu64 ", cmd:0x%x, body_len:%u]", uid, cmd, body_len);
this->send_msg_buf.add_body_len(body_len);
this->send_msg_buf.set_head(&proto_head);
int ret = this->send(this->send_msg_buf.send_data, body_len + proto_head_t::PROTO_HEAD_LEN);
// if (!msg->Utf8DebugString().empty()){
// TRACE_LOG("%s", msg->Utf8DebugString().c_str());
// }
return ret;
} catch (...){
ERROR_LOG("[uid:%" PRIu64 ", cmd:%u, seq:%u]", uid, (uint32_t)cmd, proto_head.seq);
}
return 0;
}
int statisitcs_t::send( const void* data, uint32_t len )
{
if (NULL == this->fd_info){
auto ip = g_bench_conf->get_strval("statisitcs", "ip");
uint16_t port = ::atoi(g_bench_conf->get_strval("statisitcs", "port").c_str());
fd_info = el_async::connect(ip, port);
if (fd_info == NULL){
WARN_LOG("connet to center fail |%s|%u", ip.c_str(), port);
return ERR;
}
}
// TRACE_MSG_HEX_LOG(data, len);
return el_async::s2peer(fd_info, data, len);
}
statisitcs_t::statisitcs_t()
{
this->fd_info = NULL;
}
statisitcs_t::~statisitcs_t()
{
}
void statisitcs_t::offline()
{
this->fd_info = NULL;
}
void statisitcs_t::log( USER_ID uid, common_msg::E_STATISTICS_TYPE type )
{
statisitcs_msg::save_msg out;
out.set_platform(g_gen_platform(uid));
out.set_event_id(type);
this->send_msg(&out, uid, statisitcs_save_msg_cmd);
}
void statisitcs_t::log( USER_ID uid, common_msg::E_STATISTICS_TYPE type, uint32_t expand_param1 )
{
statisitcs_msg::save_msg out;
out.set_platform(g_gen_platform(uid));
out.set_event_id(type);
out.add_expand_param(expand_param1);
this->send_msg(&out, uid, statisitcs_save_msg_cmd);
}
void statisitcs_t::log( USER_ID uid, common_msg::E_STATISTICS_TYPE type, uint32_t expand_param1, uint32_t expand_param2 )
{
statisitcs_msg::save_msg out;
out.set_platform(g_gen_platform(uid));
out.set_event_id(type);
out.add_expand_param(expand_param1);
out.add_expand_param(expand_param2);
this->send_msg(&out, uid, statisitcs_save_msg_cmd);
}
void statisitcs_t::log( USER_ID uid, common_msg::E_STATISTICS_TYPE type, uint32_t expand_param1, uint32_t expand_param2, uint32_t expand_param3 )
{
statisitcs_msg::save_msg out;
out.set_platform(g_gen_platform(uid));
out.set_event_id(type);
out.add_expand_param(expand_param1);
out.add_expand_param(expand_param2);
out.add_expand_param(expand_param3);
this->send_msg(&out, uid, statisitcs_save_msg_cmd);
}