-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
59 lines (43 loc) · 1.35 KB
/
Copy pathmain.cpp
File metadata and controls
59 lines (43 loc) · 1.35 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.cpp
* Author: kubatek94
*
* Created on 16 March 2016, 10:28
*/
#include "DiscoveryServer.h"
#include "TcpServer.h"
#include "TcpSocket.h"
#include "Message.h"
#include "VirtualInput.h"
#include <vector>
#include <iostream>
#include <functional>
#include <memory>
int main(int argc, char** argv) {
DiscoveryServer discovery;
discovery.start(DiscoveryServer::Type::ASYNC);
VirtualInput input;
input.openDevice();
std::vector<std::unique_ptr<TcpSocket>> clients;
TcpServer server;
server.onClientConnected([&input, &clients](std::unique_ptr<TcpSocket> client) {
std::cout << "Client connected: " << client->getAddress() << std::endl;
client->onMessage([&input](TcpSocket* client, std::unique_ptr<Message::Message> message) {
message->action(input);
});
client->start();
//this prevents smart pointer going out of scope
clients.push_back(std::move(client));
});
server.start();
discovery.stop();
//stop any client threads if still running
clients.clear();
input.closeDevice();
return 0;
}