Přeskočit obsah

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
http one HTTP channel per device connection HttpTransportBase<TEvent> the device answers HTTP requests (REST, RPC over HTTP, XML)
custom one device SingleDeviceTransportBase<TAddress, TEvent> you own the connection (SDK, streaming, …) 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 http, the two custom transports and TLS.

http — request/reply over HTTP

The framework owns the HTTP client. Each device connection opens its own channel, so one device's drop or restart never touches another. The channel runs one operation at a time, enforces a timeout per request, writes the trace and exchange lines, and after FailuresToOffline timeouts or lost requests in a row reports the device offline. The framework then reconnects as for TCP.

A request is an HttpOperation<T> record named by the vendor documentation:

public sealed record GetState() : HttpOperation<UnitState>("getState")
{
    public override HttpRequestMessage Build(Uri root) => Get(root, "getState");

    public override UnitState Parse(HttpReply reply) => StateParser.Parse(reply.Body);
}

// Protocol.Connect
AttachChannel(Transport.OpenChannel(new HttpEndpoint(new Uri($"https://{ip}/sup/")), router, new HttpChannelOptions { Signer = signer }));
var state = await Send(new GetState(), ct);

Send returns HttpResult<T> without exceptions: Ok (2xx, parsed), NotModified (304), Refused (401/403), DeviceError (other status), CertificateRejected (TLS), Timeout, Lost. An IHttpSigner adds per-request authentication (a Basic header, a signature over the body). CloseChannel() closes the channel on an intentional disconnect.

The framework sets the AuthenticatedProtocol slot from every exchange (RULE-058): Ok and NotModified → authenticated, Refused → authentication failed, CertificateRejected → handshake failed, Timeout and Lost → default. An http adapter never sets the slot itself.

TLS

transport.tls: true adds the CertificateTrust function to every connection Thing: trust on first use of a self-signed device certificate, the operator command pq.command.connection.certificate.trust, audit events, and the client certificate properties tls_client_certificate and tls_client_certificate_password.

transport:
  type: http        # or tcp
  tls: true
Transport Turn TLS on for a connection
http an https:// address in HttpEndpoint
tcp new TcpConnectionOptions { UseTls = true } in ConnectChannel

On tcp a failed handshake throws AuthenticationException from ConnectChannel and sets the slot to handshake failed; a finished handshake clears it. Whether the device accepts the protocol login stays the adapter's verdict. Without transport.tls a TLS connection uses the system validation only.

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; call Unbind(address) when done.