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
broadcasterIBluetoothBroadcasterThe broadcaster that owns this service.
specIBluetoothLocalServiceFactory.BluetoothLocalServiceSpecThe factory spec containing service information.
characteristicFactoryIBluetoothLocalCharacteristicFactoryThe factory for creating local characteristics.
loggerILogger<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
broadcasterIBluetoothBroadcasterThe broadcaster that owns this service.
idGuidThe unique identifier of the service.
namestringThe name of the service (optional).
isPrimaryboolIndicates whether this service is a primary service (default: true).
loggerILogger<IBluetoothLocalService>The logger instance to use for logging (optional).
Properties
Broadcaster
Gets the Bluetooth broadcaster hosting this service.
public IBluetoothBroadcaster Broadcaster { get; }
Property Value
CharacteristicFactory
Gets the factory for creating local Bluetooth characteristics.
protected IBluetoothLocalCharacteristicFactory? CharacteristicFactory { get; }
Property Value
Id
Gets the service UUID.
public Guid Id { get; }
Property Value
IsPrimary
Gets a value indicating whether this service is a primary service.
public bool IsPrimary { get; }
Property Value
Name
Gets the name of the service.
public string Name { get; }
Property Value
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
idGuidThe UUID of the characteristic to add.
propertiesBluetoothCharacteristicPropertiesThe GATT properties supported by this characteristic (Read/Write/Notify/Indicate, etc.).
permissionsBluetoothCharacteristicPermissionsThe permissions of the characteristic.
namestringAn optional name for the characteristic. If not provided, a default name may be assigned based on the UUID or other heuristics.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA 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
GetCharacteristic(Func<IBluetoothLocalCharacteristic, bool>)
Gets a hosted GATT characteristic that matches the specified filter.
public IBluetoothLocalCharacteristic GetCharacteristic(Func<IBluetoothLocalCharacteristic, bool> filter)
Parameters
filterFunc<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
idGuidThe 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
filterFunc<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
idGuidThe 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
filterFunc<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
filterFunc<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
idGuidThe 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
idGuidpropertiesBluetoothCharacteristicPropertiespermissionsBluetoothCharacteristicPermissionsnamestringtimeoutTimeSpan?cancellationTokenCancellationToken
Returns
RemoveAllCharacteristicsAsync(TimeSpan?, CancellationToken)
Removes all hosted characteristics from the broadcaster.
public ValueTask RemoveAllCharacteristicsAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA 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
localCharacteristicIBluetoothLocalCharacteristicThe characteristic to remove.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA 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
idGuidThe UUID of the characteristic to remove.
timeoutTimeSpan?The timeout for this operation
cancellationTokenCancellationTokenA 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()