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
93 void stop();
94
95 private:
116 void handleUpgrade(uWS::HttpResponse<false>* res, uWS::HttpRequest* req,
117 us_socket_context_t* context,
118 bool checkDuplicateClientIds = false);
119
146 void runReqRes();
147
171 void runPubSub();
172
174 std::atomic<bool> running_ = false;
175
177 uint16_t reqResPort_ = 63524;
179 std::thread reqResThread_;
181 uWS::Loop* reqResLoop_ = nullptr;
183 us_listen_socket_t* reqResListenToken_ = nullptr;
185 std::unordered_map<std::string,
186 uWS::WebSocket<false, true, ProtoServer::ConnectionData>*>
187 reqResConnectionIdToWebSocketMap_;
188
190 uint16_t pubSubPort_ = 63525;
192 std::thread pubSubThread_;
194 uWS::Loop* pubSubLoop_ = nullptr;
196 us_listen_socket_t* pubSubListenToken_ = nullptr;
198 std::unordered_map<std::string,
199 uWS::WebSocket<false, true, ProtoServer::ConnectionData>*>
200 pubSubConnectionIdToWebSocketMap_;
201
204 incomingMachineMessageQueue_;
207 outgoingMachineMessageQueue_;
208
210 std::thread serverThread_;
211
234 void runServer();
235
273 void sendOutgoingMachineMessages();
274
285 std::unordered_map<std::string,
286 std::tuple<std::string, std::set<std::string>>>
287 monitoringSubscriptionMap_;
288};
~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:37
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