2 // Copyright 2015 Google, Inc.
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at:
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
20 #include <unordered_map>
22 #include <base/macros.h>
23 #include <bluetooth/uuid.h>
25 #include "service/bluetooth_instance.h"
26 #include "service/hal/bluetooth_gatt_interface.h"
30 // A GattClient instance represents an application's handle to perform GATT
31 // client-role operations. Instances cannot be created directly and should be
32 // obtained through the factory.
33 class GattClient : public BluetoothInstance {
35 ~GattClient() override;
37 // BluetoothClientInstace overrides:
38 const Uuid& GetAppIdentifier() const override;
39 int GetInstanceId() const override;
42 friend class GattClientFactory;
44 // Constructor shouldn't be called directly as instances are meant to be
45 // obtained from the factory.
46 GattClient(const Uuid& uuid, int client_id);
48 // See getters above for documentation.
52 DISALLOW_COPY_AND_ASSIGN(GattClient);
55 // GattClientFactory is used to register and obtain a per-application GattClient
56 // instance. Users should call RegisterClient to obtain their own unique
57 // GattClient instance that has been registered with the Bluetooth stack.
58 class GattClientFactory : public BluetoothInstanceFactory,
59 private hal::BluetoothGattInterface::ClientObserver {
61 // Don't construct/destruct directly except in tests. Instead, obtain a handle
62 // from an Adapter instance.
64 ~GattClientFactory() override;
66 // BluetoothInstanceFactory override:
67 bool RegisterInstance(const Uuid& uuid,
68 const RegisterCallback& callback) override;
71 // hal::BluetoothGattInterface::ClientObserver override:
72 void RegisterClientCallback(hal::BluetoothGattInterface* gatt_iface,
73 int status, int client_id,
74 const Uuid& app_uuid) override;
76 // Map of pending calls to register.
77 std::mutex pending_calls_lock_;
78 std::unordered_map<Uuid, RegisterCallback> pending_calls_;
80 DISALLOW_COPY_AND_ASSIGN(GattClientFactory);
83 } // namespace bluetooth