|
BCNP 3.2.1
Batched Command Network Protocol
|
Parses BCNP stream and dispatches packets to registered handlers. More...
#include <dispatcher.h>
Public Types | |
| using | Clock = std::chrono::steady_clock |
Public Member Functions | |
| PacketDispatcher (DispatcherConfig config={}) | |
| Construct a dispatcher with the given configuration. | |
| void | PushBytes (const uint8_t *data, std::size_t length) |
| Feed raw bytes from transport (thread-safe) | |
| template<typename MsgType > | |
| void | RegisterHandler (PacketHandler handler) |
| Register a handler for a message type (by type) | |
| void | RegisterHandler (MessageTypeId typeId, PacketHandler handler) |
| Register a handler for a message type (by ID) | |
| void | UnregisterHandler (MessageTypeId typeId) |
| Remove a handler. | |
| void | SetErrorHandler (ErrorHandler handler) |
| Set error callback. | |
| bool | IsConnected (Clock::time_point now) const |
| Check if any packets received recently. | |
| Clock::time_point | LastReceiveTime () const |
| Get last receive time. | |
| StreamParser & | Parser () |
| Access the parser (for diagnostics) | |
| const StreamParser & | Parser () const |
| void | SetWireSizeLookup (StreamParser::WireSizeLookup lookup) |
| Set wire size lookup for custom message types (for testing) | |
| template<typename... MsgTypes> | |
| void | RegisterMessageTypes () |
| Convenience: set wire size lookup from a list of message types. | |
| uint64_t | ParseErrorCount () const |
| Get parse error count. | |
Parses BCNP stream and dispatches packets to registered handlers.
PacketDispatcher doesn't own any queues. Robot code creates queues per subsystem and registers handlers to fill them.
Definition at line 49 of file dispatcher.h.
| using bcnp::PacketDispatcher::Clock = std::chrono::steady_clock |
Definition at line 51 of file dispatcher.h.
|
explicit |
Construct a dispatcher with the given configuration.
Creates internal StreamParser with callbacks wired to HandlePacket/HandleError.
| config | Dispatcher configuration (buffer size, timeouts) |
Definition at line 20 of file dispatcher.cpp.
| bool bcnp::PacketDispatcher::IsConnected | ( | Clock::time_point | now | ) | const |
Check if any packets received recently.
Check if the connection is active.
Returns true if a packet was received within the configured timeout period.
| now | Current time point for comparison |
Definition at line 78 of file dispatcher.cpp.
| PacketDispatcher::Clock::time_point bcnp::PacketDispatcher::LastReceiveTime | ( | ) | const |
Get last receive time.
Get the timestamp of the last received packet.
Definition at line 90 of file dispatcher.cpp.
| uint64_t bcnp::PacketDispatcher::ParseErrorCount | ( | ) | const |
Get parse error count.
Get the total number of parse errors encountered.
Definition at line 99 of file dispatcher.cpp.
|
inline |
Access the parser (for diagnostics)
Definition at line 80 of file dispatcher.h.
|
inline |
Definition at line 81 of file dispatcher.h.
| void bcnp::PacketDispatcher::PushBytes | ( | const uint8_t * | data, |
| std::size_t | length ) |
Feed raw bytes from transport (thread-safe)
Push raw bytes for parsing and dispatch.
Thread-safe: acquires mutex before accessing parser. Parsed packets are dispatched to registered handlers synchronously.
| data | Pointer to incoming byte data |
| length | Number of bytes to process |
Definition at line 36 of file dispatcher.cpp.
| void bcnp::PacketDispatcher::RegisterHandler | ( | MessageTypeId | typeId, |
| PacketHandler | handler ) |
Register a handler for a message type (by ID)
Register a handler for a specific message type.
| typeId | Message type ID to handle |
| handler | Callback to invoke when packets of this type arrive |
Definition at line 47 of file dispatcher.cpp.
|
inline |
Register a handler for a message type (by type)
Definition at line 60 of file dispatcher.h.
|
inline |
Convenience: set wire size lookup from a list of message types.
Definition at line 90 of file dispatcher.h.
| void bcnp::PacketDispatcher::SetErrorHandler | ( | ErrorHandler | handler | ) |
Set error callback.
Set the error callback for parse failures.
| handler | Callback to invoke on stream parsing errors |
Definition at line 65 of file dispatcher.cpp.
|
inline |
Set wire size lookup for custom message types (for testing)
Definition at line 84 of file dispatcher.h.
| void bcnp::PacketDispatcher::UnregisterHandler | ( | MessageTypeId | typeId | ) |
Remove a handler.
Remove a previously registered handler.
| typeId | Message type ID to stop handling |
Definition at line 56 of file dispatcher.cpp.