-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.cpp
More file actions
149 lines (130 loc) · 4.04 KB
/
Copy pathcore.cpp
File metadata and controls
149 lines (130 loc) · 4.04 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "core.h"
Core::Core() : ptrIoServiceHandler(new IOServiceHandler(NUM_THREADS)),
ptrOscEndpoint(new UdpOscEndpoint(ptrIoServiceHandler->getIoService()))
{
LOG(__PRETTY_FUNCTION__);
messaging::attach<Server::STATE>(ptrOscEndpoint.get(), this);
messaging::attach<BufferMessage>(ptrOscEndpoint.get(),&bufferReader);
messaging::attach<OscDeviceMessage>(&bufferReader, &mapper);
messaging::attach<DeviceAddedMessage>(&mapper, this);
messaging::attach<DeviceStateMessage>(&mapper, this);
messaging::attach<DeviceRemovedMessage>(&mapper,this);
}
Core::~Core()
{
LOG(__PRETTY_FUNCTION__);
ptrOscEndpoint->stop();
}
//slots
void Core::startServer(const uint16_t &_port)
{
LOG(__PRETTY_FUNCTION__);
ptrOscEndpoint->start(_port);
}
void Core::stopServer()
{
LOG(__PRETTY_FUNCTION__);
ptrOscEndpoint->stop();
}
void Core::addDevice(const std::string& _name, const std::string& _host, const int _port)
{
LOG(__PRETTY_FUNCTION__);
std::shared_ptr<TcpDevice> dev(new TcpDevice(ptrIoServiceHandler->getIoService(), _host, _port));
mapper.addDevice(_name,dev);
}
void Core::removeDevice(const char *_device)
{
LOG(__PRETTY_FUNCTION__);
mapper.removeDevice(std::string(_device));
}
void Core::checkName(const char *_name)
{
LOG(__PRETTY_FUNCTION__);
emit isNameAvailable(mapper.nameValid(std::string(_name)));
}
void Core::connect(const char *_name)
{
LOG(__PRETTY_FUNCTION__);
try{
mapper.getDevice(_name)->start();
} catch (const std::out_of_range &e) {
LOG_ERR(__PRETTY_FUNCTION__, " Cant connect device with name \"", _name,"\"");
}
}
void Core::disconnect(const char *_name)
{
LOG(__PRETTY_FUNCTION__);
try{
mapper.getDevice(_name)->stop();
} catch (const std::out_of_range &e) {
LOG_ERR(__PRETTY_FUNCTION__, " Cant disconnect device with name \"", _name,"\"");
}
}
//Listener Methods
void Core::handleMessage(const UdpOscEndpoint::STATE& _state)
{
LOG(__PRETTY_FUNCTION__);
switch(_state){
case UdpOscEndpoint::STATE::RUNNING:
LOG(__PRETTY_FUNCTION__, " running");
emit serverStatusChanged("Running");
break;
case UdpOscEndpoint::STATE::STOPPED:
LOG(__PRETTY_FUNCTION__, " stopped");
emit serverStatusChanged("Stopped");
break;
case UdpOscEndpoint::STATE::ERROR:
LOG(__PRETTY_FUNCTION__, " error");
emit serverStatusChanged("Error");
break;
}
}
void Core::handleMessage(const DeviceStateMessage &_msg)
{
LOG(__PRETTY_FUNCTION__);
switch(_msg.state){
case DEVICE_STATE::CONNECTED:
LOG(__PRETTY_FUNCTION__, "Connected");
emit deviceStateChanged(_msg.name.c_str(), "Connected");
break;
case DEVICE_STATE::CONNECTING:
LOG(__PRETTY_FUNCTION__, "Connecting");
emit deviceStateChanged(_msg.name.c_str(), "Connecting");
break;
case DEVICE_STATE::DISCONNECTED:
LOG(__PRETTY_FUNCTION__, "Disconnected");
emit deviceStateChanged(_msg.name.c_str(), "Disconnected");
break;
case DEVICE_STATE::ERROR:
LOG(__PRETTY_FUNCTION__, "Error");
emit deviceStateChanged(_msg.name.c_str(), "Error");
break;
}
}
void Core::handleMessage(const DeviceAddedMessage &_msg)
{
LOG(__PRETTY_FUNCTION__);
switch(_msg.state){
case DEVICE_STATE::CONNECTED:
LOG(__PRETTY_FUNCTION__, "Connected");
emit deviceAdded(_msg.name.c_str(), "Connected");
break;
case DEVICE_STATE::CONNECTING:
LOG(__PRETTY_FUNCTION__, "Connecting");
emit deviceAdded(_msg.name.c_str(), "Connecting");
break;
case DEVICE_STATE::DISCONNECTED:
LOG(__PRETTY_FUNCTION__, "Disconnected");
emit deviceAdded(_msg.name.c_str(), "Disonnected");
break;
case DEVICE_STATE::ERROR:
LOG(__PRETTY_FUNCTION__, "Error");
emit deviceAdded(_msg.name.c_str(), "Error");
break;
}
}
void Core::handleMessage(const DeviceRemovedMessage &_msg)
{
LOG(__PRETTY_FUNCTION__);
emit deviceRemoved(_msg.name.c_str());
}