Motion Master
Loading...
Searching...
No Matches
proto_server.h
Go to the documentation of this file.
1#pragma once
2
3#include <uwebsockets/App.h>
4#include <atomic>
5#include <thread>
6
9
11
24 public:
33 std::string id;
34 };
35
49 explicit ProtoServer(
51 incomingMachineMessageQueue,
53 outgoingMachineMessageQueue,
54 uint16_t reqResPort = 63524, uint16_t pubSubPort = 63525);
55
62
77 void start();
78
97 void stop();
98
99 private:
120 void handleUpgrade(uWS::HttpResponse<false>* res, uWS::HttpRequest* req,
121 us_socket_context_t* context,
122 bool checkDuplicateClientIds = false);
123
150 void runReqRes();
151
175 void runPubSub();
176
178 std::atomic<bool> running_ = false;
179
181 uint16_t reqResPort_ = 63524;
183 std::thread reqResThread_;
185 uWS::Loop* reqResLoop_ = nullptr;
187 us_listen_socket_t* reqResListenToken_ = nullptr;
189 std::unordered_map<std::string,
190 uWS::WebSocket<false, true, ProtoServer::ConnectionData>*>
191 reqResConnectionIdToWebSocketMap_;
192
194 uint16_t pubSubPort_ = 63525;
196 std::thread pubSubThread_;
198 uWS::Loop* pubSubLoop_ = nullptr;
200 us_listen_socket_t* pubSubListenToken_ = nullptr;
202 std::unordered_map<std::string,
203 uWS::WebSocket<false, true, ProtoServer::ConnectionData>*>
204 pubSubConnectionIdToWebSocketMap_;
205
208 incomingMachineMessageQueue_;
211 outgoingMachineMessageQueue_;
212
214 std::thread serverThread_;
215
232 void runServer();
233
271 void sendOutgoingMachineMessages();
272
283 std::unordered_map<std::string,
284 std::tuple<std::string, std::set<std::string>>>
285 monitoringSubscriptionMap_;
286};
~ProtoServer()
Destructor for ProtoServer.
Definition proto_server.cc:18
ProtoServer(mm::core::containers::ThreadSafeQueue< IncomingMachineMessage > &incomingMachineMessageQueue, mm::core::containers::ThreadSafeQueue< OutgoingMachineMessage > &outgoingMachineMessageQueue, uint16_t reqResPort=63524, uint16_t pubSubPort=63525)
Construct a new ProtoServer object.
Definition proto_server.cc:7
void start()
Starts the ProtoServer by launching its main threads.
Definition proto_server.cc:20
void stop()
Stops the ProtoServer and performs a clean shutdown.
Definition proto_server.cc:36
Thread-safe FIFO queue with optional capacity limit.
Definition thread_safe_queue.h:23
Per-connection data for each WebSocket.
Definition proto_server.h:31
std::string id
Definition proto_server.h:33