TransportManager, connects to the coordinator, and exposes typed publish/subscribe helpers. You subclass Unit (or SingleThreadedUnit) and implement Initialize() and, optionally, Update().
In generated code, Basis creates a concrete subclass for you.
HandlerPubSub structs and the handlers map are populated automatically by the code generator.struct UnitInitializeOptions
Passed to Unit::Initialize() to control which resources are created during startup.
When
true, the unit creates real transport subscribers for each declared input. Set to false during deterministic replay when subscriptions are driven externally.class Unit
basis::Unit — defined in cpp/unit/include/basis/unit.h
The abstract base class for all Basis units. Manages the transport manager, coordinator connection, publishers, subscribers, and the handler registry used by the code generator.
Constructor
Human-readable name for this unit. Used for logging and coordinator identification. A dedicated
spdlog logger is created under this name.WaitForCoordinatorConnection
CoordinatorConnector; the unit retains ownership.
Call this before
CreateTransportManager() when you need publisher/subscriber discovery across processes.CreateTransportManager
TransportManager (with inproc and TCP transports) and stores it internally. Returns a non-owning pointer.
Optional recorder. When non-null, all publishers created through this transport manager will write serialized messages to the recorder for every topic that matches the recorder’s filter.
Advertise
topic and registers it with the transport manager.
The message type to publish.
Serializer to use. Defaults to the serializer registered for
T_MSG.Topic name, e.g.
"/camera/rgb".Type metadata. Deduced automatically from
T_MSG and T_Serializer when omitted.std::shared_ptr<core::transport::Publisher<T_MSG>>. The [[nodiscard]] attribute means you must store the returned pointer; dropping it destroys the publisher.
Subscribe
The message type to receive.
Serializer used to deserialize incoming data.
Topic name to subscribe to.
Callback invoked with
std::shared_ptr<const T_MSG> for each message received.Thread pool used to deserialize and dispatch messages.
Optional queue that serializes callback delivery. Used by
SingleThreadedUnit to ensure mutual exclusion.Type metadata. Deduced automatically when omitted.
Initialize
main() before the update loop starts.
Controls subscriber creation behavior.
Update
StandardUpdate() which flushes the transport manager and coordinator connector. Override in subclasses to add polling logic.
When set to
true by an external thread, the update loop should terminate.Maximum wall time to block waiting for events. A zero duration means non-blocking.
Name
GetHandlers
DeterministicReplayer and UnitManager.
class SingleThreadedUnit
basis::SingleThreadedUnit — inherits from Unit
A unit where all handler callbacks are serialized through a single shared queue, preventing concurrent execution. Adds an overloaded Subscribe that automatically wires callbacks into this queue.
Overloaded Subscribe
thread_pool and routes callbacks through the shared overall_queue.
Topic name to subscribe to.
Callback invoked with
std::shared_ptr<const T_MSG>.Maximum number of pending messages to buffer per subscriber before dropping.
0 means unlimited.Type metadata. Deduced automatically when omitted.
Update (overridden)
Unit::Update(), then drains the callback queue. Blocks for up to max_execution_duration waiting for the first event, then processes all remaining buffered events.
struct HandlerPubSub
basis::HandlerPubSub — defined in cpp/unit/include/basis/unit.h
An abstract base populated entirely by generated code. Each declared handler in a unit’s schema produces one HandlerPubSub subclass. The Unit::handlers map holds non-owning pointers to these objects, keyed by handler name.
Maps each subscribed topic’s runtime name to a callback that accepts a type-erased message pointer. Used by
DeterministicReplayer to feed recorded messages into handlers without knowing their concrete type at the call site.List of topic names this handler publishes to. Populated by generated code.
When set, the handler fires on a timer at this period rather than on message receipt.
Free functions
CreateStandardTransportManager
TransportManager with the standard set of transports (inproc + TCP). Called internally by Unit::CreateTransportManager().
StandardUpdate
Unit::Update().