1 // 2 // Copyright (C) 2015 Google, Inc. 3 // 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: 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 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. 15 // 16 17 #pragma once 18 19 #include <base/macros.h> 20 21 #include "service/gatt_client.h" 22 #include "service/common/bluetooth/binder/IBluetoothGattClient.h" 23 #include "service/common/bluetooth/binder/IBluetoothGattClientCallback.h" 24 #include "service/ipc/binder/interface_with_instances_base.h" 25 26 namespace bluetooth { 27 class Adapter; 28 } // namespace bluetooth 29 30 namespace ipc { 31 namespace binder { 32 33 // Implements the server side of the IBluetoothGattClient interface. 34 class BluetoothGattClientBinderServer : public BnBluetoothGattClient, 35 public InterfaceWithInstancesBase { 36 public: 37 explicit BluetoothGattClientBinderServer(bluetooth::Adapter* adapter); 38 ~BluetoothGattClientBinderServer() override = default; 39 40 // IBluetoothGattClient overrides: 41 bool RegisterClient( 42 const android::sp<IBluetoothGattClientCallback>& callback) override; 43 void UnregisterClient(int client_id) override; 44 void UnregisterAll() override; 45 46 private: 47 // Returns a pointer to the IBluetoothGattClientCallback instance 48 // associated with |client_id|. Returns NULL if such a callback cannot be 49 // found. 50 android::sp<IBluetoothGattClientCallback> 51 GetGattClientCallback(int client_id); 52 53 // Returns a pointer to the GattClient instance associated with |client_id|. 54 // Returns NULL if such a client cannot be found. 55 std::shared_ptr<bluetooth::GattClient> GetGattClient(int client_id); 56 57 // InterfaceWithInstancesBase override: 58 void OnRegisterInstanceImpl( 59 bluetooth::BLEStatus status, 60 android::sp<IInterface> callback, 61 bluetooth::BluetoothInstance* instance) override; 62 63 bluetooth::Adapter* adapter_; // weak 64 65 DISALLOW_COPY_AND_ASSIGN(BluetoothGattClientBinderServer); 66 }; 67 68 } // namespace binder 69 } // namespace ipc 70