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 15 #pragma once 16 17 #include <fuchsia/bluetooth/gatt/cpp/fidl.h> 18 19 #include "lib/fidl/cpp/binding.h" 20 #include "pw_bluetooth_sapphire/fuchsia/host/fidl/gatt_remote_service_server.h" 21 #include "pw_bluetooth_sapphire/fuchsia/host/fidl/server_base.h" 22 #include "pw_bluetooth_sapphire/internal/host/common/macros.h" 23 24 namespace bthost { 25 26 // Implements the gatt::Client FIDL interface. 27 class GattClientServer 28 : public GattServerBase<fuchsia::bluetooth::gatt::Client> { 29 public: 30 GattClientServer( 31 bt::gatt::PeerId peer_id, 32 bt::gatt::GATT::WeakPtr gatt, 33 fidl::InterfaceRequest<fuchsia::bluetooth::gatt::Client> request); 34 ~GattClientServer() override = default; 35 36 private: 37 // bluetooth::gatt::Client overrides: 38 void ListServices(::fidl::VectorPtr<::std::string> uuids, 39 ListServicesCallback callback) override; 40 void ConnectToService( 41 uint64_t id, 42 ::fidl::InterfaceRequest<fuchsia::bluetooth::gatt::RemoteService> request) 43 override; 44 45 // The ID of the peer that this client is attached to. 46 bt::gatt::PeerId peer_id_; 47 48 // Remote GATT services that were connected through this client. The value can 49 // be null while a ConnectToService request is in progress. 50 std::unordered_map<uint64_t, std::unique_ptr<GattRemoteServiceServer>> 51 connected_services_; 52 53 WeakSelf<GattClientServer> weak_self_; 54 55 BT_DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(GattClientServer); 56 }; 57 58 } // namespace bthost 59