BCNP 3.2.1
Batched Command Network Protocol
Loading...
Searching...
No Matches
controller_driver.cpp
Go to the documentation of this file.
2
3#include "bcnp/packet.h"
4
5namespace bcnp {
6
8 : m_dispatcher(dispatcher), m_adapter(adapter) {
9 // Allocate buffer on heap to prevent stack overflow
10 m_rxScratch.resize(8192);
11 }
12
14 // Limit iterations to prevent starvation if data arrives faster than we can process
15 constexpr std::size_t kMaxChunksPerPoll = 10;
16 for (std::size_t i = 0; i < kMaxChunksPerPoll; ++i) {
17 const std::size_t received = m_adapter.ReceiveChunk(m_rxScratch.data(), m_rxScratch.size());
18 if (received == 0) {
19 break;
20 }
21 m_dispatcher.PushBytes(m_rxScratch.data(), received);
22 }
23}
24
25bool DispatcherDriver::SendBytes(const uint8_t* data, std::size_t length) {
26 return m_adapter.SendBytes(data, length);
27}
28
29} // namespace bcnp
virtual std::size_t ReceiveChunk(uint8_t *buffer, std::size_t maxLength)=0
Receive available bytes from the transport (non-blocking).
virtual bool SendBytes(const uint8_t *data, std::size_t length)=0
Send bytes over the transport.
DispatcherDriver(PacketDispatcher &dispatcher, DuplexAdapter &adapter)
bool SendBytes(const uint8_t *data, std::size_t length)
Send raw bytes through the adapter.
void PollOnce()
Poll transport and feed data to dispatcher.
Combined send/receive interface for bidirectional transports.
Definition adapter.h:43
Parses BCNP stream and dispatches packets to registered handlers.
Definition dispatcher.h:49
void PushBytes(const uint8_t *data, std::size_t length)
Feed raw bytes from transport (thread-safe)
BCNP packet structures, encoding, and decoding utilities.