Table of Contents

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

characteristic IBluetoothLocalCharacteristic

The local characteristic this descriptor belongs to.

id Guid

The unique identifier of the descriptor.

initialValue ReadOnlyMemory<byte>?

The initial value of the descriptor (optional).

name string

The name of the descriptor (optional).

logger ILogger<IBluetoothLocalDescriptor>

Optional logger for logging descriptor operations.

Properties

Characteristic

Gets the Bluetooth characteristic hosting this descriptor.

public IBluetoothLocalCharacteristic Characteristic { get; }

Property Value

IBluetoothLocalCharacteristic

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

Guid

Name

Gets the name of the descriptor.

public string Name { get; }

Property Value

string

Value

Gets the value of the descriptor as a read-only memory segment. Useful for asynchronous operations.

public ReadOnlyMemory<byte> Value { get; }

Property Value

ReadOnlyMemory<byte>

ValueSpan

Gets the value of the descriptor as a read-only span. Useful for high-performance scenarios.

public ReadOnlySpan<byte> ValueSpan { get; }

Property Value

ReadOnlySpan<byte>

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

ValueTask

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

value ReadOnlyMemory<byte>

The new value to set for the descriptor.

timeout TimeSpan?

An optional timeout for the operation.

cancellationToken CancellationToken

A 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

device IBluetoothConnectedDevice
offset int

Returns

DescriptorReadRequestEventArgs

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

device IBluetoothConnectedDevice
value ReadOnlyMemory<byte>
offset int
isPreparedWrite bool
responseNeeded bool

Returns

DescriptorWriteRequestEventArgs

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

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

value ReadOnlyMemory<byte>

The new value.

timeout TimeSpan?

The timeout for this operation

cancellationToken CancellationToken

A 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

EventHandler<DescriptorReadRequestEventArgs>

WriteRequested

Event raised when a client device requests to write to this descriptor.

public event EventHandler<DescriptorWriteRequestEventArgs>? WriteRequested

Event Type

EventHandler<DescriptorWriteRequestEventArgs>