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 <memory> 20 21#include <base/macros.h> 22 23#include <android/bluetooth/IBluetoothLeAdvertiserCallback.h> 24#include "android/bluetooth/BnBluetoothLeAdvertiser.h" 25 26#include "service/common/bluetooth/low_energy_constants.h" 27#include "service/ipc/binder/interface_with_instances_base.h" 28#include "service/low_energy_advertiser.h" 29 30using android::binder::Status; 31using android::String16; 32 33using android::bluetooth::BnBluetoothLeAdvertiser; 34using android::bluetooth::IBluetoothLeAdvertiserCallback; 35 36namespace bluetooth { 37class Adapter; 38} // namespace bluetooth 39 40namespace ipc { 41namespace binder { 42 43// Implements the server side of the IBluetoothLowEnergy interface. 44class BluetoothLeAdvertiserBinderServer : public BnBluetoothLeAdvertiser, 45 public InterfaceWithInstancesBase { 46 public: 47 explicit BluetoothLeAdvertiserBinderServer(bluetooth::Adapter* adapter); 48 ~BluetoothLeAdvertiserBinderServer() override; 49 50 // IBluetoothLowEnergy overrides: 51 Status RegisterAdvertiser( 52 const android::sp<IBluetoothLeAdvertiserCallback>& callback, 53 bool* _aidl_return) override; 54 Status UnregisterAdvertiser(int advertiser_id) override; 55 Status UnregisterAll() override; 56 Status StartMultiAdvertising( 57 int advertiser_id, 58 const android::bluetooth::AdvertiseData& advertise_data, 59 const android::bluetooth::AdvertiseData& scan_response, 60 const android::bluetooth::AdvertiseSettings& settings, 61 bool* _aidl_return) override; 62 Status StopMultiAdvertising(int advertiser_id, bool* _aidl_return) override; 63 64 private: 65 // Returns a pointer to the IBluetoothLeAdvertiserCallback instance associated 66 // with |advertiser_id|. Returns NULL if such a callback cannot be found. 67 android::sp<IBluetoothLeAdvertiserCallback> GetLECallback(int advertiser_id); 68 69 // Returns a pointer to the LowEnergyAdvertiser instance associated with 70 // |advertiser_id|. Returns NULL if such a advertiser cannot be found. 71 std::shared_ptr<bluetooth::LowEnergyAdvertiser> GetLEAdvertiser( 72 int advertiser_id); 73 74 // InterfaceWithInstancesBase override: 75 void OnRegisterInstanceImpl(bluetooth::BLEStatus status, 76 android::sp<IInterface> callback, 77 bluetooth::BluetoothInstance* instance) override; 78 79 bluetooth::Adapter* adapter_; // weak 80 81 DISALLOW_COPY_AND_ASSIGN(BluetoothLeAdvertiserBinderServer); 82}; 83 84} // namespace binder 85} // namespace ipc 86