Class BluetoothRemoteDescriptor
Unified Bluetooth remote descriptor facade providing extension points for client customization.
public class BluetoothRemoteDescriptor : IBluetoothRemoteDescriptor, INotifyPropertyChanged, IAsyncDisposable
- Inheritance
-
BluetoothRemoteDescriptor
- Implements
- Inherited Members
Constructors
BluetoothRemoteDescriptor(IBluetoothRemoteDescriptor, IBluetoothRemoteCharacteristic)
Initializes a new instance of the BluetoothRemoteDescriptor class.
public BluetoothRemoteDescriptor(IBluetoothRemoteDescriptor platformDescriptor, IBluetoothRemoteCharacteristic characteristic)
Parameters
platformDescriptorIBluetoothRemoteDescriptorThe platform descriptor to wrap.
characteristicIBluetoothRemoteCharacteristicThe wrapped parent characteristic.
Properties
CanRead
Gets a value indicating whether the descriptor can be read.
public bool CanRead { get; }
Property Value
CanWrite
Gets a value indicating whether the descriptor can be written to.
public bool CanWrite { get; }
Property Value
Characteristic
Gets the Bluetooth characteristic associated with this descriptor.
public IBluetoothRemoteCharacteristic Characteristic { get; }
Property Value
Id
Gets the unique identifier of the descriptor. This is typically a UUID that identifies the type of descriptor (e.g., Client Characteristic Configuration Descriptor has a well-known UUID).
public Guid Id { get; }
Property Value
IsReadingValue
Gets a value indicating whether the descriptor is currently reading its value.
public bool IsReadingValue { get; }
Property Value
IsWritingValue
Gets a value indicating whether the descriptor is currently writing its value.
public bool IsWritingValue { get; }
Property Value
Name
The name of the Bluetooth descriptor. This is typically used for debugging and logging purposes, and may not be available for all descriptor. If the descriptor is not recognized, this will default to "Unknown Descriptor".
public string Name { get; }
Property Value
PlatformDescriptor
Gets the wrapped platform descriptor.
public IBluetoothRemoteDescriptor PlatformDescriptor { get; }
Property Value
Value
Gets the value of the descriptor as a read-only memory segment. Useful for asynchronous operations.
public ReadOnlyMemory<byte> Value { get; }
Property Value
ValueSpan
Gets the value of the descriptor as a read-only span. Useful for high-performance scenarios.
public ReadOnlySpan<byte> ValueSpan { get; }
Property Value
Methods
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.
OnAfterWriteValueAsync(ReadOnlyMemory<byte>, CancellationToken)
Called after writing descriptor value.
protected virtual ValueTask OnAfterWriteValueAsync(ReadOnlyMemory<byte> value, CancellationToken cancellationToken)
Parameters
valueReadOnlyMemory<byte>cancellationTokenCancellationToken
Returns
OnBeforeWriteValueAsync(ReadOnlyMemory<byte>, CancellationToken)
Called before writing descriptor value.
protected virtual ValueTask OnBeforeWriteValueAsync(ReadOnlyMemory<byte> value, CancellationToken cancellationToken)
Parameters
valueReadOnlyMemory<byte>cancellationTokenCancellationToken
Returns
ReadValueAsync(bool, TimeSpan?, CancellationToken)
Reads the value of the descriptor asynchronously.
public ValueTask<ReadOnlyMemory<byte>> ReadValueAsync(bool skipIfPreviouslyRead = false, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
skipIfPreviouslyReadboolIf true, skips reading if the value was previously read.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA cancellation token to cancel this operation.
Returns
- ValueTask<ReadOnlyMemory<byte>>
A task that represents the asynchronous read operation. The task result contains the value read.
Exceptions
- DeviceNotConnectedException
Thrown when the device is not connected.
- DescriptorCantReadException
Thrown when the descriptor doesn't support read operations.
- DescriptorException
Thrown when the read operation fails.
- TimeoutException
Thrown when the operation times out.
- OperationCanceledException
Thrown when the operation is cancelled.
WaitForValueChangeAsync(Func<ReadOnlyMemory<byte>, bool>?, TimeSpan?, CancellationToken)
Waits for the value of the descriptor to change asynchronously.
public ValueTask<ReadOnlyMemory<byte>> WaitForValueChangeAsync(Func<ReadOnlyMemory<byte>, bool>? valueFilter = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
valueFilterFunc<ReadOnlyMemory<byte>, bool>An optional filter function to apply to the value changes. If provided, the task completes only when the filter returns true.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA cancellation token to cancel this operation.
Returns
- ValueTask<ReadOnlyMemory<byte>>
A task that represents the asynchronous operation. The task result contains the new value of the descriptor.
WriteValueAsync(ReadOnlyMemory<byte>, bool, TimeSpan?, CancellationToken)
Writes a value to the descriptor asynchronously.
public virtual ValueTask WriteValueAsync(ReadOnlyMemory<byte> value, bool skipIfOldValueMatchesNewValue = false, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
valueReadOnlyMemory<byte>The value to write.
skipIfOldValueMatchesNewValueboolIf true, skips writing if the old value matches the new value.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA cancellation token to cancel this operation.
Returns
- ValueTask
A task that represents the asynchronous write operation.
Exceptions
- ArgumentNullException
Thrown when
valueis null.- DeviceNotConnectedException
Thrown when the device is not connected.
- DescriptorCantWriteException
Thrown when the descriptor doesn't support write operations.
- DescriptorException
Thrown when the write operation fails.
- TimeoutException
Thrown when the operation times out.
- OperationCanceledException
Thrown when the operation is cancelled.
Events
PropertyChanged
Occurs when a property value changes.
public event PropertyChangedEventHandler? PropertyChanged
Event Type
ValueUpdated
Event raised when the value of the descriptor is updated, only triggered when IsListening is true.
public event EventHandler<ValueUpdatedEventArgs> ValueUpdated