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 <android/bluetooth/BnBluetoothGattClient.h> 22#include <android/bluetooth/IBluetoothGattClientCallback.h> 23 24#include "service/gatt_client.h" 25#include "service/ipc/binder/interface_with_instances_base.h" 26 27using android::bluetooth::BnBluetoothGattClient; 28using android::bluetooth::IBluetoothGattClientCallback; 29 30using ::android::binder::Status; 31 32namespace bluetooth { 33class Adapter; 34} // namespace bluetooth 35 36namespace ipc { 37namespace binder { 38 39// Implements the server side of the IBluetoothGattClient interface. 40class BluetoothGattClientBinderServer : public BnBluetoothGattClient, 41 public InterfaceWithInstancesBase { 42 public: 43 explicit BluetoothGattClientBinderServer(bluetooth::Adapter* adapter); 44 ~BluetoothGattClientBinderServer() override = default; 45 46 // IBluetoothGattClient overrides: 47 Status RegisterClient( 48 const android::sp<IBluetoothGattClientCallback>& callback, 49 bool* _aidl_return) override; 50 Status UnregisterClient(int client_id) override; 51 Status UnregisterAll() override; 52 53 private: 54 // Returns a pointer to the IBluetoothGattClientCallback instance 55 // associated with |client_id|. Returns NULL if such a callback cannot be 56 // found. 57 android::sp<IBluetoothGattClientCallback> GetGattClientCallback( 58 int client_id); 59 60 // Returns a pointer to the GattClient instance associated with |client_id|. 61 // Returns NULL if such a client cannot be found. 62 std::shared_ptr<bluetooth::GattClient> GetGattClient(int client_id); 63 64 // InterfaceWithInstancesBase override: 65 void OnRegisterInstanceImpl(bluetooth::BLEStatus status, 66 android::sp<IInterface> callback, 67 bluetooth::BluetoothInstance* instance) override; 68 69 bluetooth::Adapter* adapter_; // weak 70 71 DISALLOW_COPY_AND_ASSIGN(BluetoothGattClientBinderServer); 72}; 73 74} // namespace binder 75} // namespace ipc 76