Table of Contents

Class BaseBluetoothLocalService

Namespace
Bluetooth.Core.Broadcasting
Assembly
Bluetooth.Core.Broadcasting.dll

Base class for Bluetooth broadcaster services.

public abstract class BaseBluetoothLocalService : BaseBindableObject, IBluetoothLocalService, INotifyPropertyChanged, IAsyncDisposable
Inheritance
BaseBluetoothLocalService
Implements
Derived
Inherited Members

Constructors

BaseBluetoothLocalService(IBluetoothBroadcaster, BluetoothLocalServiceSpec, IBluetoothLocalCharacteristicFactory, ILogger<IBluetoothLocalService>?)

Initializes a new instance using a factory spec.

protected BaseBluetoothLocalService(IBluetoothBroadcaster broadcaster, IBluetoothLocalServiceFactory.BluetoothLocalServiceSpec spec, IBluetoothLocalCharacteristicFactory characteristicFactory, ILogger<IBluetoothLocalService>? logger = null)

Parameters

broadcaster IBluetoothBroadcaster

The broadcaster that owns this service.

spec IBluetoothLocalServiceFactory.BluetoothLocalServiceSpec

The factory spec containing service information.

characteristicFactory IBluetoothLocalCharacteristicFactory

The factory for creating local characteristics.

logger ILogger<IBluetoothLocalService>

The logger instance to use for logging (optional).

BaseBluetoothLocalService(IBluetoothBroadcaster, Guid, string?, bool, ILogger<IBluetoothLocalService>?)

Initializes a new instance of the BaseBluetoothLocalService class.

protected BaseBluetoothLocalService(IBluetoothBroadcaster broadcaster, Guid id, string? name = null, bool isPrimary = true, ILogger<IBluetoothLocalService>? logger = null)

Parameters

broadcaster IBluetoothBroadcaster

The broadcaster that owns this service.

id Guid

The unique identifier of the service.

name string

The name of the service (optional).

isPrimary bool

Indicates whether this service is a primary service (default: true).

logger ILogger<IBluetoothLocalService>

The logger instance to use for logging (optional).

Properties

Broadcaster

Gets the Bluetooth broadcaster hosting this service.

public IBluetoothBroadcaster Broadcaster { get; }

Property Value

IBluetoothBroadcaster

CharacteristicFactory

Gets the factory for creating local Bluetooth characteristics.

protected IBluetoothLocalCharacteristicFactory? CharacteristicFactory { get; }

Property Value

IBluetoothLocalCharacteristicFactory

Id

Gets the service UUID.

public Guid Id { get; }

Property Value

Guid

IsPrimary

Gets a value indicating whether this service is a primary service.

public bool IsPrimary { get; }

Property Value

bool

Name

Gets the name of the service.

public string Name { get; }

Property Value

string

Methods

CreateCharacteristicAsync(Guid, BluetoothCharacteristicProperties, BluetoothCharacteristicPermissions, string?, TimeSpan?, CancellationToken)

Adds a GATT characteristic to be hosted by the broadcaster.

public ValueTask<IBluetoothLocalCharacteristic> CreateCharacteristicAsync(Guid id, BluetoothCharacteristicProperties properties, BluetoothCharacteristicPermissions permissions, string? name = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

id Guid

The UUID of the characteristic to add.

properties BluetoothCharacteristicProperties

The GATT properties supported by this characteristic (Read/Write/Notify/Indicate, etc.).

permissions BluetoothCharacteristicPermissions

The permissions of the characteristic.

name string

An optional name for the characteristic. If not provided, a default name may be assigned based on the UUID or other heuristics.

timeout TimeSpan?

The timeout for this operation

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<IBluetoothLocalCharacteristic>

The added characteristic.

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

GetCharacteristic(Func<IBluetoothLocalCharacteristic, bool>)

Gets a hosted GATT characteristic that matches the specified filter.

public IBluetoothLocalCharacteristic GetCharacteristic(Func<IBluetoothLocalCharacteristic, bool> filter)

Parameters

filter Func<IBluetoothLocalCharacteristic, bool>

A function to filter characteristics. Should return true for the desired characteristic.

Returns

IBluetoothLocalCharacteristic

The matching characteristic.

Exceptions

CharacteristicNotFoundException

Thrown if no characteristic matches the specified filter.

MultipleCharacteristicsFoundException

Thrown if multiple characteristics match the specified filter.

GetCharacteristic(Guid)

Gets a hosted GATT characteristic by its UUID.

public IBluetoothLocalCharacteristic GetCharacteristic(Guid id)

Parameters

id Guid

The UUID of the characteristic to retrieve.

Returns

IBluetoothLocalCharacteristic

The matching characteristic.

Exceptions

CharacteristicNotFoundException

Thrown if no characteristic matches the specified filter.

MultipleCharacteristicsFoundException

Thrown if multiple characteristics match the specified filter.

GetCharacteristicOrDefault(Func<IBluetoothLocalCharacteristic, bool>)

Gets a hosted GATT characteristic that matches the specified filter.

public IBluetoothLocalCharacteristic? GetCharacteristicOrDefault(Func<IBluetoothLocalCharacteristic, bool> filter)

Parameters

filter Func<IBluetoothLocalCharacteristic, bool>

A function to filter characteristics. Should return true for the desired characteristic.

Returns

IBluetoothLocalCharacteristic

The matching characteristic, or null if not found.

GetCharacteristicOrDefault(Guid)

Gets a hosted GATT characteristic by its UUID.

public IBluetoothLocalCharacteristic? GetCharacteristicOrDefault(Guid id)

Parameters

id Guid

The UUID of the characteristic to retrieve.

Returns

IBluetoothLocalCharacteristic

The matching characteristic, or null if not found.

GetCharacteristics(Func<IBluetoothLocalCharacteristic, bool>?)

Gets all hosted GATT characteristics.

public IEnumerable<IBluetoothLocalCharacteristic> GetCharacteristics(Func<IBluetoothLocalCharacteristic, bool>? filter = null)

Parameters

filter Func<IBluetoothLocalCharacteristic, bool>

An optional filter to apply to the characteristics.

Returns

IEnumerable<IBluetoothLocalCharacteristic>

A collection of all hosted characteristics.

HasCharacteristic(Func<IBluetoothLocalCharacteristic, bool>)

Checks if a hosted GATT characteristic that matches the specified filter exists.

public bool HasCharacteristic(Func<IBluetoothLocalCharacteristic, bool> filter)

Parameters

filter Func<IBluetoothLocalCharacteristic, bool>

A function to filter characteristics. Should return true for the desired characteristic.

Returns

bool

True if a matching characteristic exists, false otherwise.

HasCharacteristic(Guid)

Checks if a hosted GATT characteristic with the specified UUID exists.

public bool HasCharacteristic(Guid id)

Parameters

id Guid

The UUID of the characteristic to check for.

Returns

bool

True if a matching characteristic exists, false otherwise.

NativeCreateCharacteristicAsync(Guid, BluetoothCharacteristicProperties, BluetoothCharacteristicPermissions, string?, TimeSpan?, CancellationToken)

Creates a new local Bluetooth characteristic with the specified parameters.

protected abstract ValueTask<IBluetoothLocalCharacteristic> NativeCreateCharacteristicAsync(Guid id, BluetoothCharacteristicProperties properties, BluetoothCharacteristicPermissions permissions, string? name = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

id Guid
properties BluetoothCharacteristicProperties
permissions BluetoothCharacteristicPermissions
name string
timeout TimeSpan?
cancellationToken CancellationToken

Returns

ValueTask<IBluetoothLocalCharacteristic>

RemoveAllCharacteristicsAsync(TimeSpan?, CancellationToken)

Removes all hosted characteristics from the broadcaster.

public ValueTask RemoveAllCharacteristicsAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

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.

RemoveCharacteristicAsync(IBluetoothLocalCharacteristic, TimeSpan?, CancellationToken)

Removes a hosted GATT characteristic from the broadcaster.

public ValueTask RemoveCharacteristicAsync(IBluetoothLocalCharacteristic localCharacteristic, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

localCharacteristic IBluetoothLocalCharacteristic

The characteristic to remove.

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.

RemoveCharacteristicAsync(Guid, TimeSpan?, CancellationToken)

Removes a hosted GATT characteristic from the broadcaster.

public ValueTask RemoveCharacteristicAsync(Guid id, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

id Guid

The UUID of the characteristic to remove.

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.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string