Transport types¶
An adapter declares one transport.type in adapter-registration.yaml. It says how the framework connects
to devices and how many devices one transport instance serves. The generator emits the matching Transport
base for you.
transport.type |
Serves | Generated base | Use when |
|---|---|---|---|
tcp |
one device per socket | SingleTcpTransportBase<TFrame, TEvent> |
the device speaks a framed request/reply protocol over TCP |
custom |
one device | SingleDeviceTransportBase<TAddress, TEvent> |
you own the connection (HTTP, SDK, …) and it talks to a single device |
multiplex |
many devices at once | MultiplexTransportBase<TAddress, TEvent> |
one connection or driver carries several devices, each identified by an address it puts in every event |
tcp is covered in TCP Transport. This page covers the two custom transports.
Choosing single vs multi¶
- One device per transport instance — your adapter connects to a single controller, NVR, or panel, and
every event implicitly belongs to that device. Use
custom. - One connection or driver, many devices — a single session fans out to several root devices, and each
incoming event carries an address that says which device it came from. Use
multiplex.
Most adapters are single-device. Choose multiplex only when one transport instance genuinely serves more
than one root device.
custom — single device¶
SingleDeviceTransportBase<TAddress, TEvent> serves the one device it is connected to, so routing needs no
address. From your Transport:
| Member | Purpose |
|---|---|
Bind(router) |
bind the device's event router after connect |
Unbind() |
clear the binding on disconnect |
BoundRouter |
the bound router, to dispatch an incoming event |
NotifyDisconnected(reason) |
signal that the device dropped |
Bind(nvr.Functions.Connection);
// ...dispatch an incoming event:
if (BoundRouter is not ConnectionFunction connection)
return;
await connection.Dispatch(alert, ct);
// ...on a dropped stream:
NotifyDisconnected();
address_type still types the protocol address your Protocol uses (ProtocolId, addressed Enqueue); the
single-device transport itself does not route by it.
multiplex — many devices¶
MultiplexTransportBase<TAddress, TEvent> keys each device by the protocol address it carries. From your
Transport:
| Member | Purpose |
|---|---|
Bind(address, router) |
bind a device's router when it connects |
Unbind(address) |
remove a device's binding |
Resolve(address) |
the router for an incoming event's address |
NotifyDisconnected(address, reason) |
signal that one device dropped |
transport:
type: multiplex
protocol:
address_type: uint # the id type your device carries
event_type: YourEvent
Two contracts:
- Unbind before you rebind a reused address (e.g. a device reconnecting under the same id). Binding over an address that is still bound logs a warning.
NotifyDisconnected(address)does not unbind. It signals the drop and keeps the binding, so you can tear the device's own state down afterwards; callUnbind(address)when done.