Class SifiBridge
Manages the sifibridge CLI process for communicating with SiFi BLE devices.
Implements
Inherited Members
Namespace: MOSAIC.Components.Devices.SiFi
Assembly: MOSAIC.dll
Syntax
public sealed class SifiBridge : IDisposable
Remarks
This class owns the process lifecycle: starting, sending commands via stdin,
receiving responses via stdout/stderr, and terminating. It is used internally
by MOSAIC.Components.Devices.SiFi and has no dependency on BaseBlock or any MOSAIC
infrastructure — it is a pure process wrapper.
The bridge process is started lazily on the first call to EnsureRunning() and is killed on Dispose(). If the process exits unexpectedly, the Exited event is raised.
Constructors
SifiBridge(string)
Initializes a new SifiBridge wrapper.
Declaration
public SifiBridge(string bridgePath = "sifibridge")
Parameters
| Type | Name | Description |
|---|---|---|
| string | bridgePath | Path to the |
Fields
_bridgePath
Declaration
private readonly string _bridgePath
Field Value
| Type | Description |
|---|---|
| string |
_disposed
Declaration
private bool _disposed
Field Value
| Type | Description |
|---|---|
| bool |
_process
Declaration
private Process? _process
Field Value
| Type | Description |
|---|---|
| Process |
Properties
IsRunning
Whether the bridge process is currently running.
Declaration
public bool IsRunning { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
Dispose()
Shuts down the bridge process and releases resources.
Declaration
public void Dispose()
EnsureRunning()
Ensures the bridge process is running. Starts it if not already running.
Declaration
public void EnsureRunning()
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | Thrown if the wrapper has been disposed. |
SendAsync(string)
Sends a command string to the bridge's stdin.
Declaration
public Task SendAsync(string command)
Parameters
| Type | Name | Description |
|---|---|---|
| string | command | The CLI command to send (e.g. |
Returns
| Type | Description |
|---|---|
| Task |
SendSync(string)
Sends a command synchronously. Use for shutdown sequences where async is impractical.
Declaration
public void SendSync(string command)
Parameters
| Type | Name | Description |
|---|---|---|
| string | command | The CLI command to send. |
Shutdown(int)
Attempts a graceful shutdown: sends stop + disconnect, waits briefly, then kills if needed.
Declaration
public void Shutdown(int waitMs = 2000)
Parameters
| Type | Name | Description |
|---|---|---|
| int | waitMs | Maximum milliseconds to wait for the process to exit. Default: 2000. |
Events
ErrorReceived
Raised for each line of stderr from the bridge.
Declaration
public event Action<string>? ErrorReceived
Event Type
| Type | Description |
|---|---|
| Action<string> |
Exited
Raised when the bridge process exits (expected or unexpected).
Declaration
public event Action? Exited
Event Type
| Type | Description |
|---|---|
| Action |
OutputReceived
Raised for each line of stdout from the bridge (JSON packets, status, etc.).
Declaration
public event Action<string>? OutputReceived
Event Type
| Type | Description |
|---|---|
| Action<string> |