Home | History | Annotate | Download | only in binder
      1 //
      2 //  Copyright 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 
     30 using android::binder::Status;
     31 using android::String16;
     32 
     33 using android::bluetooth::BnBluetoothLeAdvertiser;
     34 using android::bluetooth::IBluetoothLeAdvertiserCallback;
     35 
     36 namespace bluetooth {
     37 class Adapter;
     38 }  // namespace bluetooth
     39 
     40 namespace ipc {
     41 namespace binder {
     42 
     43 // Implements the server side of the IBluetoothLowEnergy interface.
     44 class 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