-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathecho_role.cpp
94 lines (76 loc) · 1.48 KB
/
echo_role.cpp
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
#include "echo_role.h"
#include "cmd_msg.h"
#include "cmd_parse_protocol.h"
echo_role::echo_role()
{
}
echo_role::~echo_role()
{
}
/*调用时机--》被添加到kernel中时被调用*/
bool echo_role::Init()
{
//代表初始化成功
return true;
}
//回显消息处理函数
/*调用时机:原始数据转换成用户请求后*/
//参数来自于协议对象raw2request的返回值
UserData * echo_role::ProcMsg(UserData & _poUserData)
{
//取出待回显的内容
GET_REF2DATA(cmd_msg, input, _poUserData);
std::string echo_string = input.echo_string;
//构建待发送消息
cmd_msg *pout = new cmd_msg();
pout->echo_string = echo_string;
//发送出去
ZinxKernel::Zinx_SendOut(*pout, *(cmd_parse_protocol::GetInstance()));
//没有后续环节
return nullptr;
}
/*在摘出kernel时被调用*/
void echo_role::Fini()
{
}
bool exit_framework_role::Init()
{
return true;
}
UserData * exit_framework_role::ProcMsg(UserData & _poUserData)
{
GET_REF2DATA(cmd_msg, cmd, _poUserData);
if (cmd.is_frame_exit) {
ZinxKernel::Zinx_Exit();
}
return nullptr;
}
void exit_framework_role::Fini()
{
}
bool output_mng_role::Init()
{
return true;
}
UserData * output_mng_role::ProcMsg(UserData & _poUserData)
{
GET_REF2DATA(cmd_msg, cmd, _poUserData);
if (NULL == m_channle)
{
m_channle = ZinxKernel::Zinx_GetChannel_ByInfo("stdout_channel");
}
if (cmd.output_open == true)
{
/*打开输出通道*/
ZinxKernel::Zinx_Add_Channel(*m_channle);
}
else
{
/*关闭输出通道*/
ZinxKernel::Zinx_Del_Channel(*m_channle);
}
return nullptr;
}
void output_mng_role::Fini()
{
}