Class BaseBluetoothConnectedDevice
- Namespace
- Bluetooth.Core.Broadcasting
- Assembly
- Bluetooth.Core.Broadcasting.dll
Base class for Bluetooth broadcaster devices.
public abstract class BaseBluetoothConnectedDevice : BaseBindableObject, IBluetoothConnectedDevice, INotifyPropertyChanged, IAsyncDisposable
- Inheritance
-
BaseBluetoothConnectedDevice
- Implements
- Derived
- Inherited Members
Constructors
BaseBluetoothConnectedDevice(IBluetoothBroadcaster, BluetoothConnectedDeviceSpec, ILogger<IBluetoothConnectedDevice>?)
Initializes a new instance using a factory spec.
protected BaseBluetoothConnectedDevice(IBluetoothBroadcaster broadcaster, IBluetoothConnectedDeviceFactory.BluetoothConnectedDeviceSpec spec, ILogger<IBluetoothConnectedDevice>? logger = null)
Parameters
broadcasterIBluetoothBroadcasterThe broadcaster that owns this client device.
specIBluetoothConnectedDeviceFactory.BluetoothConnectedDeviceSpecThe factory spec containing connected device information.
loggerILogger<IBluetoothConnectedDevice>The logger for logging operations.
BaseBluetoothConnectedDevice(IBluetoothBroadcaster, string, ILogger<IBluetoothConnectedDevice>?)
Initializes a new instance of the BaseBluetoothConnectedDevice class.
protected BaseBluetoothConnectedDevice(IBluetoothBroadcaster broadcaster, string id, ILogger<IBluetoothConnectedDevice>? logger = null)
Parameters
broadcasterIBluetoothBroadcasterThe broadcaster that owns this client device.
idstringThe unique identifier for the connected device, typically a UUID or MAC address.
loggerILogger<IBluetoothConnectedDevice>The logger for logging operations.
Properties
Broadcaster
Gets the Bluetooth broadcaster hosting this service.
public IBluetoothBroadcaster Broadcaster { get; }
Property Value
Id
Gets the unique identifier of the connected client device. This is typically a string that distinguishes this client device from others in the Bluetooth broadcasting context, such as a MAC address or a custom identifier assigned by the platform.
public string Id { get; }
Property Value
IsConnected
Indicates whether the client device is currently connected.
public bool IsConnected { get; protected set; }
Property Value
Mtu
Gets the current Maximum Transmission Unit (MTU) for this client connection. The MTU determines the maximum size of a single packet that can be sent.
public int Mtu { get; protected set; }
Property Value
Name
Gets the name of the connected client device.
public string Name { get; }
Property Value
SubscribedCharacteristics
Gets the list of broadcast characteristics this client device is subscribed to.
public IReadOnlyList<IBluetoothLocalCharacteristic> SubscribedCharacteristics { get; }
Property Value
Methods
AddCharacteristicSubscription(IBluetoothLocalCharacteristic)
Adds a subscription to a broadcast characteristic for this client device.
public void AddCharacteristicSubscription(IBluetoothLocalCharacteristic localCharacteristic)
Parameters
localCharacteristicIBluetoothLocalCharacteristic
DisconnectAsync(TimeSpan?, CancellationToken)
Disconnects the client device from the broadcaster.
public ValueTask DisconnectAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
timeoutTimeSpan?An optional timeout for the disconnection operation.
cancellationTokenCancellationTokenAn optional cancellation token to cancel the disconnection operation.
Returns
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
DisposeAsyncCore()
Disposes the resources asynchronously.
protected virtual ValueTask DisposeAsyncCore()
Returns
NativeDisconnectAsync(TimeSpan?, CancellationToken)
Performs the native disconnection logic for the client device.
protected abstract ValueTask NativeDisconnectAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
timeoutTimeSpan?cancellationTokenCancellationToken
Returns
OnConnectionStatusChanged(bool)
Called when the connection status of the client device changes.
protected void OnConnectionStatusChanged(bool isConnected)
Parameters
isConnectedbool
OnMtuChanged(int)
Called when MTU changes for this client connection.
protected void OnMtuChanged(int mtu)
Parameters
mtuint
RemoveAllCharacteristicSubscriptions()
Removes all characteristic subscriptions for this client device.
public void RemoveAllCharacteristicSubscriptions()
RemoveCharacteristicSubscription(IBluetoothLocalCharacteristic)
Removes a subscription to a broadcast characteristic for this client device.
public void RemoveCharacteristicSubscription(IBluetoothLocalCharacteristic localCharacteristic)
Parameters
localCharacteristicIBluetoothLocalCharacteristic
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
Events
Connected
Event raised when the client device successfully connects to the broadcaster.
public event EventHandler? Connected
Event Type
Disconnected
Event raised when the client device disconnects from the broadcaster.
public event EventHandler? Disconnected
Event Type
MtuChanged
Event raised when the MTU changes for this client connection.
public event EventHandler<MtuChangedEventArgs>? MtuChanged