Home | History | Annotate | Download | only in binder
      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 #include <binder/IBinder.h>
     21 #include <binder/IInterface.h>
     22 
     23 #include <bluetooth/advertise_data.h>
     24 #include <bluetooth/advertise_settings.h>
     25 #include <bluetooth/scan_result.h>
     26 
     27 namespace ipc {
     28 namespace binder {
     29 
     30 // This class defines the Binder IPC interface for receiving callbacks related
     31 // to Bluetooth Low Energy operations.
     32 // TODO(armansito): This class was written based on a new design doc proposal.
     33 // We need to add an AIDL for this to the framework code.
     34 //
     35 // NOTE: KEEP THIS FILE UP-TO-DATE with the corresponding AIDL, otherwise this
     36 // won't be compatible with the Android framework.
     37 /* oneway */ class IBluetoothLowEnergyCallback : public android::IInterface {
     38  public:
     39   DECLARE_META_INTERFACE(BluetoothLowEnergyCallback);
     40 
     41   static const char kServiceName[];
     42 
     43   // Transaction codes for interface methods.
     44   enum {
     45     ON_CLIENT_REGISTERED_TRANSACTION = android::IBinder::FIRST_CALL_TRANSACTION,
     46     ON_CONNECTION_STATE_TRANSACTION,
     47     ON_MTU_CHANGED_TRANSACTION,
     48     ON_SCAN_RESULT_TRANSACTION,
     49     ON_BATCH_SCAN_RESULTS_TRANSACTION,
     50     ON_READ_REMOTE_RSSI_TRANSACTION,
     51     ON_MULTI_ADVERTISE_CALLBACK_TRANSACTION,
     52     ON_SCAN_MANAGER_ERROR_CALLBACK_TRANSACTION,
     53     ON_CONFIGURE_ATT_MTU_TRANSACTION,
     54     ON_ATT_MTU_CHANGED_TRANSACTION,
     55     ON_FOUND_OR_LOST_TRANSACTION,
     56   };
     57 
     58   virtual void OnClientRegistered(int status, int client_if) = 0;
     59   virtual void OnConnectionState(int status, int client_id, const char* address,
     60                                  bool connected) = 0;
     61   virtual void OnMtuChanged(int status, const char* address, int mtu) = 0;
     62   virtual void OnScanResult(const bluetooth::ScanResult& scan_result) = 0;
     63   virtual void OnMultiAdvertiseCallback(
     64       int status, bool is_start,
     65       const bluetooth::AdvertiseSettings& settings) = 0;
     66 
     67   // TODO(armansito): Complete the API definition.
     68 
     69  private:
     70   DISALLOW_COPY_AND_ASSIGN(IBluetoothLowEnergyCallback);
     71 };
     72 
     73 // The Binder server interface to allback. A class that
     74 // implements IBluetoothLowEnergyCallback must inherit from this class.
     75 class BnBluetoothLowEnergyCallback
     76     : public android::BnInterface<IBluetoothLowEnergyCallback> {
     77  public:
     78   BnBluetoothLowEnergyCallback() = default;
     79   virtual ~BnBluetoothLowEnergyCallback() = default;
     80 
     81  private:
     82   virtual android::status_t onTransact(
     83       uint32_t code,
     84       const android::Parcel& data,
     85       android::Parcel* reply,
     86       uint32_t flags = 0);
     87 
     88   DISALLOW_COPY_AND_ASSIGN(BnBluetoothLowEnergyCallback);
     89 };
     90 
     91 // The Binder client interface to IBluetoothLowEnergyCallback.
     92 class BpBluetoothLowEnergyCallback
     93     : public android::BpInterface<IBluetoothLowEnergyCallback> {
     94  public:
     95   BpBluetoothLowEnergyCallback(const android::sp<android::IBinder>& impl);
     96   virtual ~BpBluetoothLowEnergyCallback() = default;
     97 
     98   // IBluetoothLowEnergyCallback overrides:
     99   void OnClientRegistered(int status, int client_if) override;
    100   void OnConnectionState(int status, int client_id, const char* address,
    101                          bool connected) override;
    102   void OnMtuChanged(int status, const char* address, int mtu) override;
    103   void OnScanResult(const bluetooth::ScanResult& scan_result) override;
    104   void OnMultiAdvertiseCallback(
    105       int status, bool is_start,
    106       const bluetooth::AdvertiseSettings& settings) override;
    107 
    108  private:
    109   DISALLOW_COPY_AND_ASSIGN(BpBluetoothLowEnergyCallback);
    110 };
    111 
    112 }  // namespace binder
    113 }  // namespace ipc
    114