-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwall.cpp
More file actions
64 lines (53 loc) · 1.65 KB
/
wall.cpp
File metadata and controls
64 lines (53 loc) · 1.65 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
#include <iostream>
#include <string>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include "serverthread.h"
#include "xcbutil.h"
#include "mouse.h"
#include "enforcer.h"
using boost::asio::ip::tcp;
using namespace std;
// Perform all necessary initializations
void initialize ( ) {
xcbInit ( );
}
// Cleanup at the end of the program
void cleanup ( ) {
xcbDestroy ( );
}
// Send the resolution of the wall to the user over a socket
void sendWindowDim(tcp::socket & sock){
pair<int,int> dim = getResolution(); // Get the resolution
std::vector<uint16_t> vec(2, 0);
vec[0] = htons(dim.first); // x of resolution
vec[1] = htons(dim.second); // y of resolution
int num = sock.send ( boost::asio::buffer(vec) ); // Send resolution to user
}
// Start the wall and all necessary components
int main ( int argc, char * argv[] ) {
boost::thread_group serverThreads;
initialize ( );
try {
boost::asio::io_service io_service;
MouseEvent event;
tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), MC_PORT));
// Loop forever waiting for new connections
while ( 1 ) {
// Create a new socket
tcp::socket * pSocket = new tcp::socket (io_service);
// Accept the connection
acceptor.accept(*pSocket);
cout << "Accepted remote mouse connection" << endl;
// Give the connection its own thread
serverThreads.create_thread (ServerThread(*pSocket));
}
serverThreads.join_all ( );
}
catch (std::exception& exc)
{
cerr << exc.what() << endl;
}
cleanup ( ); // Cleanup connection
return 0;
}