Motion Master
Loading...
Searching...
No Matches
ProtoServer Class Reference

WebSocket server for Motion Master Proto (Protocol Buffer) messages. More...

#include <proto_server.h>

Classes

struct  ConnectionData
 Per-connection data for each WebSocket. More...

Public Member Functions

 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.
 ~ProtoServer ()
 Destructor for ProtoServer.
void start ()
 Starts the ProtoServer by launching its main threads.
void stop ()
 Stops the ProtoServer and performs a clean shutdown.

Detailed Description

WebSocket server for Motion Master Proto (Protocol Buffer) messages.

Manages two WebSocket servers: one for request/response and one for publish/subscribe communication. Handles connection management, unique connection identification, threading, and event loop control for both server types. Provides thread-safe message queues for incoming and outgoing machine messages.

See also
https://github.com/synapticon/motion-master-proto

Constructor & Destructor Documentation

◆ ProtoServer()

ProtoServer::ProtoServer ( mm::core::containers::ThreadSafeQueue< IncomingMachineMessage > & incomingMachineMessageQueue,
mm::core::containers::ThreadSafeQueue< OutgoingMachineMessage > & outgoingMachineMessageQueue,
uint16_t reqResPort = 63524,
uint16_t pubSubPort = 63525 )
explicit

Construct a new ProtoServer object.

Parameters
incomingMachineMessageQueueReference to the thread-safe queue of incoming machine messages.
outgoingMachineMessageQueueReference to the thread-safe queue of outgoing machine messages.
reqResPortTCP port for REQ/RES WebSocket connections.
pubSubPortTCP port for PUB/SUB WebSocket connections.
Note
The lifetime of the provided queues must outlive this ProtoServer instance, as the constructor stores references.

◆ ~ProtoServer()

ProtoServer::~ProtoServer ( )

Destructor for ProtoServer.

Stops the server and ensures all resources and threads are cleaned up.

Member Function Documentation

◆ start()

void ProtoServer::start ( )

Starts the ProtoServer by launching its main threads.

This function launches three threads:

  1. REQ/RES thread (runReqRes)
  2. PUB/SUB thread (runPubSub)
  3. Main server thread (runServer)

If the server is already running, this function does nothing.

Threads are created using std::thread and run the corresponding event loops. If thread creation fails, the program will terminate with a std::system_error.

◆ stop()

void ProtoServer::stop ( )

Stops the ProtoServer and performs a clean shutdown.

This function will:

  • Mark the server as not running.
  • Close the REQ/RES and PUB/SUB listen sockets to unblock their event loops.
  • Wake up any active uWebSockets event loops.
  • Join all server-related threads (REQ/RES, PUB/SUB, main server loop) to ensure a clean shutdown.

Multiple calls to this function are safe; if the server is already stopped, the function returns immediately.


The documentation for this class was generated from the following files: