C/C++ API Reference
Loading...
Searching...
No Matches
client2.h
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include "pw_async2/dispatcher.h"
17#include "pw_async2/once_sender.h"
18#include "pw_bluetooth/gatt/constants.h"
19#include "pw_bluetooth/gatt/error.h"
20#include "pw_bluetooth/gatt/types.h"
21#include "pw_bluetooth/internal/raii_ptr.h"
22#include "pw_containers/vector.h"
23#include "pw_function/function.h"
24#include "pw_multibuf/multibuf.h"
25#include "pw_result/expected.h"
26
27namespace pw::bluetooth::gatt {
28
30
33 public:
34 enum class RemoteServiceError {
37
40 };
41
43 struct ReadValue {
45 Handle handle;
46
49
54 };
55
59 Handle handle;
60
63 pw::expected<ReadValue, Error> result;
64 };
65
72 uint16_t offset = 0;
73
75 uint16_t max_bytes = kMaxValueLength;
76 };
77
80 enum class WriteMode : uint8_t {
84
89
98 };
99
106
109 uint16_t offset = 0;
110 };
111
112 virtual ~RemoteService2() = default;
113
121
127 characteristics_sender) = 0;
128
146 ReadByType(Uuid uuid) = 0;
147
164 ReadCharacteristic(Handle handle, std::optional<LongReadOptions> options) = 0;
165
185 Handle handle, pw::multibuf::MultiBuf&& value, WriteOptions options) = 0;
186
202 Handle handle, std::optional<LongReadOptions> options) = 0;
203
221 Handle handle, pw::multibuf::MultiBuf&& value) = 0;
222
250 Handle handle) = 0;
251
260 async2::Context& cx) = 0;
261
271 Handle handle) = 0;
272
273 private:
277 virtual void Disconnect() = 0;
278
279 public:
282 using Ptr = internal::RaiiPtr<RemoteService2, &RemoteService2::Disconnect>;
283};
284
286class Client2 {
287 public:
291 ServiceHandle handle;
292
295
298 Uuid type;
299 };
300
301 virtual ~Client2() = default;
302
312 async2::Context& cx);
313
321
328 virtual pw::expected<RemoteService2::Ptr, Error> ConnectToService(
329 ServiceHandle handle) = 0;
330};
331
332} // namespace pw::bluetooth::gatt
Definition: vector.h:65
Definition: context.h:55
Definition: once_sender.h:43
Definition: once_sender.h:270
Definition: poll.h:60
Represents a GATT client that interacts with services on a GATT server.
Definition: client2.h:286
An interface for interacting with a GATT service on a peer device.
Definition: client2.h:32
Definition: multibuf_v1.h:248
pw::expected< ReadValue, Error > result
Definition: client2.h:63
RemoteServiceError
Definition: client2.h:34
virtual async2::OnceReceiver< pw::expected< ReadValue, Error > > ReadCharacteristic(Handle handle, std::optional< LongReadOptions > options)=0
virtual void DiscoverCharacteristics(async2::OnceRefSender< Vector< Characteristic2 > > characteristics_sender)=0
virtual async2::OnceReceiver< pw::expected< void, Error > > WriteDescriptor(Handle handle, pw::multibuf::MultiBuf &&value)=0
uint16_t offset
Definition: client2.h:109
ServiceHandle handle
Uniquely identifies this GATT service.
Definition: client2.h:291
multibuf::MultiBuf value
The value of the characteristic or descriptor.
Definition: client2.h:48
bool primary
Indicates whether this is a primary or secondary service.
Definition: client2.h:294
WriteMode mode
Definition: client2.h:105
bool maybe_truncated
Definition: client2.h:53
WriteMode
Definition: client2.h:80
virtual async2::Poll< ServiceHandle > PendServiceRemoved(async2::Context &cx)
virtual async2::Poll< RemoteServiceInfo > PendServiceUpdate(async2::Context &cx)
internal::RaiiPtr< RemoteService2, &RemoteService2::Disconnect > Ptr
Definition: client2.h:282
virtual async2::OnceReceiver< pw::expected< Vector< ReadByTypeResult, 5 >, Error > > ReadByType(Uuid uuid)=0
virtual pw::expected< RemoteService2::Ptr, Error > ConnectToService(ServiceHandle handle)=0
uint16_t max_bytes
The maximum number of bytes to read.
Definition: client2.h:75
virtual async2::OnceReceiver< pw::expected< ReadValue, Error > > ReadDescriptor(Handle handle, std::optional< LongReadOptions > options)=0
virtual async2::Poll< RemoteServiceError > PendError(async2::Context &cx)=0
virtual async2::Poll< ReadValue > PendNotification(Handle handle, async2::Context &cx)=0
Handle handle
Characteristic or descriptor handle.
Definition: client2.h:59
virtual async2::OnceReceiver< pw::expected< void, Error > > StopNotifications(Handle handle)=0
virtual async2::OnceReceiver< pw::expected< void, Error > > WriteCharacteristic(Handle handle, pw::multibuf::MultiBuf &&value, WriteOptions options)=0
virtual async2::OnceReceiver< pw::expected< void, Error > > EnableNotifications(Handle handle)=0
Handle handle
Characteristic or descriptor handle.
Definition: client2.h:45
@ kPeerDisconnected
The peer serving this service has disconnected.
@ kServiceRemoved
The service has been modified or removed.
Represents a remote GATT service.
Definition: client2.h:289
A result returned by ReadByType.
Definition: client2.h:57
Wrapper around a possible truncated value received from the server.
Definition: client2.h:43