BoB robotics
The Brains on Board robotics library
BoBRobotics::Net::Connection Class Reference

An abstract class representing a network connection, inherited by Server and Client classes. More...

#include <connection.h>

Inheritance diagram for BoBRobotics::Net::Connection:
BoBRobotics::Threadable BoBRobotics::Net::Client

Classes

class  SocketWriter
 Provides a thread-safe interface for writing to Sockets. More...
 

Public Member Functions

template<typename... Ts>
 Connection (Ts &&... args)
 Default listening port.
 
bool isOpen () const
 
void setCommandHandler (const std::string &commandName, const CommandHandler &handler)
 Add a handler for a specified type of command. More...
 
void read (void *buffer, size_t length)
 Read a specified number of bytes into a buffer.
 
SocketWriter getSocketWriter ()
 Return a transaction object for writing to this Connection's Socket.
 
std::string readNextCommand ()
 
- Public Member Functions inherited from BoBRobotics::Threadable
virtual void run ()
 Run on the current thread, blocking until process ends.
 
virtual bool isRunning ()
 Check if the run() function has been called.
 
virtual void runInBackground ()
 Run the process on a background thread.
 
virtual void stop ()
 Stop the background thread.
 

Static Public Attributes

static constexpr size_t DefaultBufferSize = 1024 * 8
 
static constexpr int DefaultListenPort = 2000
 Default buffer size, in bytes.
 

Protected Member Functions

SocketgetSocket ()
 
virtual void runInternal () override
 
virtual void runInternal ()=0
 

Detailed Description

An abstract class representing a network connection, inherited by Server and Client classes.

Member Function Documentation

◆ runInternal()

void BoBRobotics::Net::Connection::runInternal ( )
overrideprotectedvirtual

◆ setCommandHandler()

void BoBRobotics::Net::Connection::setCommandHandler ( const std::string &  commandName,
const CommandHandler handler 
)

Add a handler for a specified type of command.

e.g. if it's an IMG command, it should be handled by Video::NetSource. Set to nullptr to disable and ignore these commands.


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