-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMS.ManagerListener.cpp
More file actions
69 lines (64 loc) · 2.53 KB
/
MS.ManagerListener.cpp
File metadata and controls
69 lines (64 loc) · 2.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
63
64
65
66
67
68
69
#include "MS.ManagerListener.hpp"
#include "Json.hpp"
#include "Utils/Log.hpp"
namespace elastos {
namespace MicroService {
ManagerListener::ManagerListener(std::weak_ptr<ManagerService> service)
: mService(service)
{
}
ManagerListener::~ManagerListener()
{
mService.reset();
}
void ManagerListener::onEvent(ElaphantContact::Listener::EventArgs& event)
{
switch (event.type) {
case ElaphantContact::Listener::EventType::StatusChanged:
{
auto statusEvent = dynamic_cast<ElaphantContact::Listener::StatusEvent*>(&event);
Log::I(ManagerService::NAME, "Service %s received %s status changed %u\n",
ManagerService::NAME,
event.humanCode.c_str(),
statusEvent->status);
break;
}
case ElaphantContact::Listener::EventType::FriendRequest:
{
auto requestEvent = dynamic_cast<ElaphantContact::Listener::RequestEvent*>(&event);
Log::I(ManagerService::NAME, "Service %s received %s friend request %s\n",
ManagerService::NAME,
event.humanCode.c_str(),
requestEvent->summary.c_str());
auto service = mService.lock();
if (service.get() == nullptr) {
Log::E(ManagerService::NAME, "Service has been deleted.");
break;
}
service->getConnector()->AcceptFriend(event.humanCode);
break;
}
case ElaphantContact::Listener::EventType::HumanInfoChanged:
{
auto infoEvent = dynamic_cast<ElaphantContact::Listener::InfoEvent*>(&event);
Log::I(ManagerService::NAME, "Service %s received %s info changed %s\n",
ManagerService::NAME,
event.humanCode.c_str(),
infoEvent->toString().c_str());
break;
}
default:
Log::E(ManagerService::NAME, "Unprocessed event: %d", static_cast<int>(event.type));
break;
}
}
void ManagerListener::onReceivedMessage(const std::string& humanCode, ElaphantContact::Channel channelType,
std::shared_ptr<ElaphantContact::Message> msgInfo)
{
Log::E(ManagerService::NAME, "Service %s received message %s from %s\n",
ManagerService::NAME,
msgInfo->data->toString().c_str(),
humanCode.c_str());
}
} // MicroService
} // elastos