Class BaseBluetoothLocalDescriptor
- Namespace
- Bluetooth.Core.Broadcasting
- Assembly
- Bluetooth.Core.Broadcasting.dll
Base class for Bluetooth broadcast descriptors.
public abstract class BaseBluetoothLocalDescriptor : BaseBindableObject, IBluetoothLocalDescriptor, INotifyPropertyChanged, IAsyncDisposable
- Inheritance
-
BaseBluetoothLocalDescriptor
- Implements
- Derived
- Inherited Members
Constructors
BaseBluetoothLocalDescriptor(IBluetoothLocalCharacteristic, Guid, ReadOnlyMemory<byte>?, string?, ILogger<IBluetoothLocalDescriptor>?)
Initializes a new instance of the BaseBluetoothLocalDescriptor class.
protected BaseBluetoothLocalDescriptor(IBluetoothLocalCharacteristic characteristic, Guid id, ReadOnlyMemory<byte>? initialValue = null, string? name = null, ILogger<IBluetoothLocalDescriptor>? logger = null)
Parameters
characteristicIBluetoothLocalCharacteristicThe local characteristic this descriptor belongs to.
idGuidThe unique identifier of the descriptor.
initialValueReadOnlyMemory<byte>?The initial value of the descriptor (optional).
namestringThe name of the descriptor (optional).
loggerILogger<IBluetoothLocalDescriptor>Optional logger for logging descriptor operations.
Properties
Characteristic
Gets the Bluetooth characteristic hosting this descriptor.
public IBluetoothLocalCharacteristic Characteristic { get; }
Property Value
Id
Gets the unique identifier of the descriptor. This is typically a UUID that distinguishes this descriptor from others in the Bluetooth broadcasting context.
public Guid Id { get; }
Property Value
Name
Gets the name of the descriptor.
public string Name { 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.
DisposeAsyncCore()
Disposes the resources asynchronously.
protected virtual ValueTask DisposeAsyncCore()
Returns
NativeUpdateValueAsync(ReadOnlyMemory<byte>, TimeSpan?, CancellationToken)
Updates the value of the descriptor in the native Bluetooth stack.
protected abstract ValueTask NativeUpdateValueAsync(ReadOnlyMemory<byte> value, TimeSpan? timeout, CancellationToken cancellationToken)
Parameters
valueReadOnlyMemory<byte>The new value to set for the descriptor.
timeoutTimeSpan?An optional timeout for the operation.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- ValueTask
A task that represents the asynchronous update operation.
OnReadRequested(IBluetoothConnectedDevice, int)
Handles a read request from a client device.
protected DescriptorReadRequestEventArgs OnReadRequested(IBluetoothConnectedDevice device, int offset)
Parameters
deviceIBluetoothConnectedDeviceoffsetint
Returns
OnWriteRequested(IBluetoothConnectedDevice, ReadOnlyMemory<byte>, int, bool, bool)
Handles a write request from a client device.
protected DescriptorWriteRequestEventArgs OnWriteRequested(IBluetoothConnectedDevice device, ReadOnlyMemory<byte> value, int offset, bool isPreparedWrite, bool responseNeeded)
Parameters
deviceIBluetoothConnectedDevicevalueReadOnlyMemory<byte>offsetintisPreparedWriteboolresponseNeededbool
Returns
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
UpdateValueAsync(ReadOnlyMemory<byte>, TimeSpan?, CancellationToken)
Updates the value of a hosted descriptor.
public ValueTask UpdateValueAsync(ReadOnlyMemory<byte> value, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
valueReadOnlyMemory<byte>The new value.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA cancellation token to cancel this operation.
Returns
- ValueTask
A task that represents the asynchronous operation.
Events
ReadRequested
Event raised when a client device requests to read this descriptor.
public event EventHandler<DescriptorReadRequestEventArgs>? ReadRequested
Event Type
WriteRequested
Event raised when a client device requests to write to this descriptor.
public event EventHandler<DescriptorWriteRequestEventArgs>? WriteRequested