-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProtocolModule.cpp
More file actions
62 lines (44 loc) · 1.53 KB
/
ProtocolModule.cpp
File metadata and controls
62 lines (44 loc) · 1.53 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
#include "stdafx.h"
#include "ProtocolModule.h"
#include "LogMgr.h"
#include "ModuleMgr.h"
#include "echo_str.pb.h"
#include <iostream>
#include <sstream>
unsigned ProtocolModule::ModuleId = 0;
ProtocolModule::ProtocolModule()
{
GOOGLE_PROTOBUF_VERIFY_VERSION;
m_pNetworkModule = (NetworkModule*)ModuleMgr::getInstance()->getModuleById( NetworkModule::getStaticModuleId() );
m_pLogModule = (LogModule*)ModuleMgr::getInstance()->getModuleById( LogModule::getStaticModuleId() );
}
ProtocolModule::~ProtocolModule()
{
m_pNetworkModule = nullptr;
m_pLogModule = nullptr;
google::protobuf::ShutdownProtobufLibrary();
}
void ProtocolModule::install()
{
m_pDelegate = MakeDelegate( this, &ProtocolModule::onRecvPackageHandler );
m_pNetworkModule->Register( NetworkEvent::RECV_PACKAGE, m_pDelegate );
printf( "ProtocolModule install succeed!\n" );
}
void ProtocolModule::uninstall()
{
m_pNetworkModule->UnRegister( NetworkEvent::RECV_PACKAGE, m_pDelegate );
delete m_pDelegate;
m_pDelegate = nullptr;
printf( "ProtocolModule uninstall succeed!\n" );
}
void ProtocolModule::onRecvPackageHandler( const CBaseEvent& evt )
{
IO_COMPLETE_DATA* p_io_complete_data = (IO_COMPLETE_DATA*)evt.m_pArgs;
TEST::Echo_Str p;
p.ParseFromString( p_io_complete_data->buffer );
p.text();
std::cout << p_io_complete_data->usMsgId << "\t" << p.text() << std::endl;
std::ostringstream strStream;
strStream << "(MSG_ID):" << p_io_complete_data->usMsgId << ",(TEXT)" << p.text();
m_pLogModule->push_log( NetworkModule::getModuleName(), strStream.str() );
}