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 &parameters) override#

Thread safe. The AdvertisedPeripheral2 returned on success is thread safe.

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 in ScanStartResult. 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 a ScanError otherwise. ScanHandle::PendResult can be called to get ScanResults for LE peers that satisfy the filters indicated in options. 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.

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 a uint32_t depending on whether tokenization is enabled.

Returns:

Code

Description

OK

A Lease was successfully created and returned.

UNAVAILABLE

A lease could not be created.

INVALID_ARGUMENT

The name was invalid (e.g. empty).

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 a uint32_t depending on whether tokenization is enabled.

Returns:

Code

Description

OK

A Lease was successfully created and returned.

UNAVAILABLE

A lease could not be created.

INVALID_ARGUMENT

The name was invalid (e.g. empty).

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 a uint32_t depending on whether tokenization is enabled.

Returns:

Code

Description

OK

A Lease was successfully created and returned.

UNAVAILABLE

A lease could not be created.

INVALID_ARGUMENT

The name was invalid (e.g. empty).

inline uint16_t lease_count() const#

Returns the number of active leases.

inline void set_acquire_status(Status status)#

Sets the status to return from the Acquire method.