1 // Copyright 2023 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 
15 #pragma once
16 #include "pw_bluetooth_sapphire/internal/host/common/weak_self.h"
17 #include "pw_bluetooth_sapphire/internal/host/gatt/remote_service.h"
18 
19 namespace bt::gap::internal {
20 
21 // This is a helper for reading characteristics of a remote Generic Access GATT
22 // service. Characteristics are not cached and read requests are not multiplexed
23 // because this is already taken care of in gatt::RemoteService. Destroying
24 // GenericAccessClient will cancel any read requests and callbacks will not be
25 // called.
26 class GenericAccessClient : private WeakSelf<GenericAccessClient> {
27  public:
28   // |peer_id| is the id of the peer serving the service.
29   // The UUID of |generic_access_service| must be kGenericAccessService.
30   GenericAccessClient(PeerId peer_id,
31                       gatt::RemoteService::WeakPtr generic_access_service);
32 
33   // Discover and read the device name characteristic, if present.
34   using DeviceNameCallback = fit::callback<void(att::Result<std::string>)>;
35   void ReadDeviceName(DeviceNameCallback callback);
36 
37   // Discover and read the appearance characteristic, if present.
38   using AppearanceCallback = fit::callback<void(att::Result<uint16_t>)>;
39   void ReadAppearance(AppearanceCallback callback);
40 
41   // Discover and read the peripheral preferred connections characteristic, if
42   // present.
43   using ConnectionParametersCallback = fit::callback<void(
44       att::Result<hci_spec::LEPreferredConnectionParameters>)>;
45   void ReadPeripheralPreferredConnectionParameters(
46       ConnectionParametersCallback callback);
47 
48  private:
49   gatt::RemoteService::WeakPtr service_;
50   PeerId peer_id_;
51 };
52 
53 }  // namespace bt::gap::internal
54