-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb_server_worker.cpp
More file actions
116 lines (108 loc) · 3.77 KB
/
web_server_worker.cpp
File metadata and controls
116 lines (108 loc) · 3.77 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
//
// Created by biba_bo on 2020-08-18.
//
#include "web_server_worker.h"
#include <zconf.h>
WebServerWorker::WebServerWorker() {
// creating an object of TurtleManager with connecting throw COM-port
turtle_manager = make_shared<SmoothTurtleManager>();
// starting the iron turtle moving processing thread
//*> turtle_manager->restart_processing_thread();
#ifdef MY_PURSUIT_TESTING
init_pursuit();
pursuit_processor = get_pursuit_processor();
pursuit_processor->restart_processing_thread(cv::Rect(START_PURSUIT_X, START_PURSUIT_Y, START_PURSUIT_WIDTH, START_PURSUIT_HEIGHT));
#endif //MY_PURSUIT_TESTING
// starting web-server
this->startServer();
// this thread sleeps for 1 seconds for avoiding bugs and errors
sleep(1);
// staring processing the server.
this->processServer();
}
void WebServerWorker::startServer() {
// creating a new thread for the web-server
this->server_thread = std::thread([this]() {
// creating a new object of PrintfLogger for possibility to log working process
logger = std::make_shared<PrintfLogger>();
// creating a new object of MyServer and adding here a logger
ws_server = make_shared<MyServer>(logger);
// creating a new object of MyHandler for handling events from web-client (onConnect, onDisconnect, onMessage)
handler = std::make_shared<MyHandler>(ws_server.get());
// adding a page handler for working with web-pages
ws_server->addPageHandler(std::make_shared<MyAuthHandler>());
// added a socket handler
ws_server->addWebSocketHandler("/chart", handler);
// starting webserver
ws_server->serve("src/server_files", 56778);
});
}
void WebServerWorker::processServer() {
// still nothing works here
}
void WebServerWorker::joinServerTread() {
// like a feature for avoiding bugs
if (server_thread.joinable())
server_thread.join();
}
void WebServerWorker::handleEventWS(std::shared_ptr<EventWS> event) {
// handling events by the event code
switch(event->getEventID()) {
case EVENT_MOVE_FORWARD:
turtle_manager->move_forward();
break;
case EVENT_MOVE_BACK:
turtle_manager->move_backward();
break;
case EVENT_MOVE_LEFTER:
turtle_manager->move_lefter();
break;
case EVENT_MOVE_RIGHTER:
turtle_manager->move_righter();
break;
case EVENT_STOP_MOVING:
turtle_manager->stop_moving();
break;
case EVENT_CAM_ZM:
on_zoom_minus_processor();
break;
case EVENT_CAM_ZP:
on_zoom_plus_processor();
break;
case EVENT_CAM_UP:
on_move_up_processor();
break;
case EVENT_CAM_DOWN:
on_move_down_processor();
break;
case EVENT_CAM_LEFT:
on_move_left_processor();
break;
case EVENT_CAM_RIGHT:
on_move_right_processor();
break;
case EVENT_CLIENT_CONNECTED:
turtle_manager->say_server_here();
#ifdef MY_PURSUIT_TESTING
pursuit_processor->say_server_here();
#endif //MY_PURSUIT_TESTING
break;
case EVENT_CLIENT_DISCONNECTED:
turtle_manager->say_server_leave();
break;
#ifdef MY_PURSUIT_TESTING
case EVENT_PURSUIT_ZOOM_PLUS:
increase_object_rectangle();
break;
case EVENT_PURSUIT_ZOOM_MINUS:
decrease_object_rectangle();
break;
case EVENT_PURSUIT_LEFTER:
move_lefter_object_rectangle();
break;
case EVENT_PURSUIT_RIGHTER:
move_righter_object_rectangle();
break;
#endif //MY_PURSUIT_TESTING
}
}