Reference#
pw_bluetooth_sapphire: Battle-tested Bluetooth with rock-solid reliability
C++ API reference#
-
class Peripheral : public pw::bluetooth::low_energy::Peripheral2#
Must only be constructed and destroyed on the Bluetooth thread.
Public Functions
-
Peripheral(bt::gap::Adapter::WeakPtr adapter, pw::async::Dispatcher &dispatcher)#
Must only be constructed on the Bluetooth thread.
-
~Peripheral() override#
Must only be destroyed on the Bluetooth thread.
-
virtual async2::OnceReceiver<AdvertiseResult> Advertise(const AdvertisingParameters ¶meters) override#
Thread safe. The AdvertisedPeripheral2 returned on success is thread safe.
-
Peripheral(bt::gap::Adapter::WeakPtr adapter, pw::async::Dispatcher &dispatcher)#
-
class Central : public pw::bluetooth::low_energy::Central2#
Must only be constructed and destroyed on the Bluetooth thread.
Public Functions
-
Central(bt::gap::Adapter::WeakPtr adapter, pw::async::Dispatcher &dispatcher, pw::multibuf::MultiBufAllocator &allocator)#
Must only be constructed on the Bluetooth thread.
- Parameters:
allocator – The allocator to use for advertising data buffers.
-
virtual async2::OnceReceiver<ScanStartResult> Scan(const ScanOptions &options) override#
Scans for nearby LE peripherals and broadcasters. The lifetime of the scan session is tied to the returned
ScanHandle
object inScanStartResult
. Once a scan is started,ScanHandle::PendResult
can be called to get scan results. Only 1 scan may be active at a time.- Parameters:
options – Options used to configure the scan session. These options are suggestions only, and the implementation may use different parameters to meet power or radio requirements.
- Returns:
Returns a
ScanHandle
object if the scan successfully starts, or aScanError
otherwise.ScanHandle::PendResult
can be called to getScanResult
s for LE peers that satisfy the filters indicated inoptions
. The initial results may report recently discovered peers. Subsequent results will be reported only when peers have been scanned or updated since the last call.
-
Central(bt::gap::Adapter::WeakPtr adapter, pw::async::Dispatcher &dispatcher, pw::multibuf::MultiBufAllocator &allocator)#
-
PW_SAPPHIRE_ACQUIRE_LEASE(lease_provider, name)#
Macro for obtaining a lease that supports tokenization properly.
- Parameters:
lease_provider – A
LeaseProvider&
name – The name of the lease (string literal)
-
class LeaseProvider#
Interface for acquiring leases. This interface is what backends implement.
Subclassed by pw::bluetooth_sapphire::NullLeaseProvider, pw::bluetooth_sapphire::testing::FakeLeaseProvider
Public Functions
-
virtual Result<Lease> Acquire(PW_SAPPHIRE_LEASE_TOKEN_TYPE name) = 0#
Try to acquire a lease. Prefer to use
PW_SAPPHIRE_ACQUIRE_LEASE
instead.- Parameters:
name – will be either a
const char*
or auint32_t
depending on whether tokenization is enabled.- Returns:
Code
Description
A Lease was successfully created and returned.
A lease could not be created.
The name was invalid (e.g. empty).
-
virtual Result<Lease> Acquire(PW_SAPPHIRE_LEASE_TOKEN_TYPE name) = 0#
-
class Lease#
A handle representing an active lease. The lease is released on destruction.
-
class NullLeaseProvider : private pw::bluetooth_sapphire::LeaseProvider#
A no-op LeaseProvider that always successfully returns an fake lease.
Public Functions
-
inline virtual Result<Lease> Acquire(PW_SAPPHIRE_LEASE_TOKEN_TYPE) override#
Try to acquire a lease. Prefer to use
PW_SAPPHIRE_ACQUIRE_LEASE
instead.- Parameters:
name – will be either a
const char*
or auint32_t
depending on whether tokenization is enabled.- Returns:
Code
Description
A Lease was successfully created and returned.
A lease could not be created.
The name was invalid (e.g. empty).
-
inline virtual Result<Lease> Acquire(PW_SAPPHIRE_LEASE_TOKEN_TYPE) override#
-
class FakeLeaseProvider : public pw::bluetooth_sapphire::LeaseProvider#
A fake LeaseProvider used for dependency injection in unit tests.
Public Functions
-
inline virtual Result<Lease> Acquire(PW_SAPPHIRE_LEASE_TOKEN_TYPE) override#
Try to acquire a lease. Prefer to use
PW_SAPPHIRE_ACQUIRE_LEASE
instead.- Parameters:
name – will be either a
const char*
or auint32_t
depending on whether tokenization is enabled.- Returns:
Code
Description
A Lease was successfully created and returned.
A lease could not be created.
The name was invalid (e.g. empty).
-
inline uint16_t lease_count() const#
Returns the number of active leases.
-
inline virtual Result<Lease> Acquire(PW_SAPPHIRE_LEASE_TOKEN_TYPE) override#