An interface for interacting with a GATT service on a peer device. More...
#include <client2.h>
Classes | |
struct | LongReadOptions |
struct | ReadByTypeResult |
A result returned by ReadByType . More... | |
struct | ReadValue |
Wrapper around a possible truncated value received from the server. More... | |
struct | WriteOptions |
Public Types | |
enum class | RemoteServiceError { kServiceRemoved = 0 , kPeerDisconnected = 1 } |
enum class | WriteMode : uint8_t { kDefault , kReliable , kWithoutResponse } |
using | Ptr = internal::RaiiPtr< RemoteService2, &RemoteService2::Disconnect > |
Public Member Functions | |
virtual async2::Poll< RemoteServiceError > | PendError (async2::Context &cx)=0 |
virtual void | DiscoverCharacteristics (async2::OnceRefSender< Vector< Characteristic2 > > characteristics_sender)=0 |
virtual async2::OnceReceiver< pw::expected< Vector< ReadByTypeResult, 5 >, Error > > | ReadByType (Uuid uuid)=0 |
virtual async2::OnceReceiver< pw::expected< ReadValue, Error > > | ReadCharacteristic (Handle handle, std::optional< LongReadOptions > options)=0 |
virtual async2::OnceReceiver< pw::expected< void, Error > > | WriteCharacteristic (Handle handle, pw::multibuf::MultiBuf &&value, WriteOptions options)=0 |
virtual async2::OnceReceiver< pw::expected< ReadValue, Error > > | ReadDescriptor (Handle handle, std::optional< LongReadOptions > options)=0 |
virtual async2::OnceReceiver< pw::expected< void, Error > > | WriteDescriptor (Handle handle, pw::multibuf::MultiBuf &&value)=0 |
virtual async2::OnceReceiver< pw::expected< void, Error > > | EnableNotifications (Handle handle)=0 |
virtual async2::Poll< ReadValue > | PendNotification (Handle handle, async2::Context &cx)=0 |
virtual async2::OnceReceiver< pw::expected< void, Error > > | StopNotifications (Handle handle)=0 |
Private Member Functions | |
virtual void | Disconnect ()=0 |
An interface for interacting with a GATT service on a peer device.
using pw::bluetooth::gatt::RemoteService2::Ptr = internal::RaiiPtr<RemoteService2, &RemoteService2::Disconnect> |
Movable RemoteService2
smart pointer. The remote server will remain connected until the returned RemoteService2::Ptr
is destroyed.
|
strong |
|
strong |
Represents the supported write modes for writing characteristics & descriptors to the server.
|
privatepure virtual |
Disconnect from the remote service. This method is called by the ~RemoteServicePtr() when it goes out of scope, the API client should never call this method.
|
pure virtual |
Asynchronously sends the characteristics in this service, up to Vector::.max_size()
. May perform service discovery if the characteristics are not yet known.
|
pure virtual |
Subscribe to notifications & indications from the characteristic with the given handle
.
Either notifications or indications will be enabled depending on characteristic properties. Indications will be preferred if they are supported. This operation fails if the characteristic does not have the "notify" or "indicate" property.
A write request will be issued to configure the characteristic for notifications/indications if it contains a Client Characteristic Configuration (CCC) descriptor. This method fails if an error occurs while writing to the descriptor.
On success, PendNotification
will return Ready when the peer sends a notification or indication. Indications are automatically confirmed.
Subscriptions can be canceled with StopNotifications
.
handle | the handle of the characteristic to subscribe to. |
handle
is invalid.
|
pure virtual |
Poll for an Error status on this service, waking cx
and returning Ready when there is an error condition. When an error condition is present, any previous RemoteService2
Waker
and OnceReceiver
instances may or may not be woken and all other methods will be no-ops. Only 1 waker can be set at a time (additional calls will replace the existing waker).
|
pure virtual |
After notifications have been enabled with EnableNotifications
, this method can be used to check for notifications. This method will safely return Pending when notifications are disabled.
handle | The handle of the characteristic to await for notifications. |
cx | The Context to awaken when a notification is available. Only one Waker per handle is supported at a time (subsequent calls will overwrite the old Waker). |
|
pure virtual |
Reads characteristics and descriptors with the specified type. This method is useful for reading values before discovery has completed, thereby reducing latency.
uuid | The UUID of the characteristics/descriptors to read. |
This may fail with the following errors:
kInvalidParameters
: if uuid
refers to an internally reserved descriptor type (e.g. the Client Characteristic Configuration descriptor).kTooManyResults
: More results were read than can fit in the Vector. Consider reading characteristics/descriptors individually after performing discovery.kFailure
: The server returned an error not specific to a single result.
|
pure virtual |
Reads the value of a characteristic.
handle | The handle of the characteristic to be read. |
options | If null, a short read will be performed, which may be truncated to what fits in a single message (at least 22 bytes). If long read options are present, performs a long read with the indicated options. |
handle
is invalid.options
is invalid.
|
pure virtual |
Reads the value of the characteristic descriptor with handle
and returns it in the reply.
handle | The descriptor handle to read. |
options | Options that apply to the read. |
result_sender | Set to a result containing the value of the descriptor on success. |
kInvalidHandle | handle is invalid. |
kInvalidParameters | options is invalid. |
kReadNotPermitted | |
kInsufficient* | The server rejected the request. |
kApplicationError* | An application error was returned by the GATT profile. |
kFailure | The server returned an error not covered by the above errors. |
|
pure virtual |
Stops notifications for the characteristic with the given handle
.
handle
is invalid.
|
pure virtual |
Writes value
to the characteristic with handle
using the provided options
.
handle | Handle of the characteristic to be written to |
value | The value to be written. |
options | Options that apply to the write. |
handle
is invalid.
|
pure virtual |
Writes value
to the descriptor with handle
using the provided. It is not recommended to send additional writes while a write is already in progress.
handle | Handle of the descriptor to be written to. |
value | The value to be written. |
handle
is invalid.