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 <string>
     20 
     21 #include <base/macros.h>
     22 #include <binder/IBinder.h>
     23 #include <binder/IInterface.h>
     24 
     25 #include <bluetooth/binder/IBluetoothGattClientCallback.h>
     26 #include <bluetooth/gatt_identifier.h>
     27 
     28 namespace ipc {
     29 namespace binder {
     30 
     31 // This class defines the Binder IPC interface for interacting with Bluetooth
     32 // GATT client-role features.
     33 // TODO(armansito): This class was written based on a new design doc proposal.
     34 // We need to add an AIDL for this to the framework code.
     35 //
     36 // NOTE: KEEP THIS FILE UP-TO-DATE with the corresponding AIDL, otherwise this
     37 // won't be compatible with the Android framework.
     38 class IBluetoothGattClient : public android::IInterface {
     39  public:
     40   DECLARE_META_INTERFACE(BluetoothGattClient);
     41 
     42   static const char kServiceName[];
     43 
     44   // Transaction codes for interface methods.
     45   enum {
     46     REGISTER_CLIENT_TRANSACTION = android::IBinder::FIRST_CALL_TRANSACTION,
     47     UNREGISTER_CLIENT_TRANSACTION,
     48     UNREGISTER_ALL_TRANSACTION,
     49     REFRESH_DEVICE_TRANSACTION,
     50     DISCOVER_SERVICES_TRANSACTION,
     51     READ_CHARACTERISTIC_TRANSACTION,
     52     WRITE_CHARACTERISTIC_TRANSACTION,
     53     READ_DESCRIPTOR_TRANSACTION,
     54     WRITE_DESCRIPTOR_TRANSACTION,
     55     REGISTER_FOR_NOTIFICATIONS_TRANSACTION,
     56     UNREGISTER_FOR_NOTIFICATIONS_TRANSACTION,
     57     BEGIN_RELIABLE_WRITE_TRANSACTION,
     58     END_RELIABLE_WRITE_TRANSACTION,
     59   };
     60 
     61   virtual bool RegisterClient(
     62       const android::sp<IBluetoothGattClientCallback>& callback) = 0;
     63   virtual void UnregisterClient(int client_id) = 0;
     64   virtual void UnregisterAll() = 0;
     65 
     66   // TODO(armansito): Complete interface definition.
     67 
     68  private:
     69   DISALLOW_COPY_AND_ASSIGN(IBluetoothGattClient);
     70 };
     71 
     72 // The Binder server interface to IBluetoothGattClient. A class that implements
     73 // IBluetoothGattClient must inherit from this class.
     74 class BnBluetoothGattClient
     75     : public android::BnInterface<IBluetoothGattClient> {
     76  public:
     77   BnBluetoothGattClient() = default;
     78   virtual ~BnBluetoothGattClient() = default;
     79 
     80  private:
     81   virtual android::status_t onTransact(
     82       uint32_t code,
     83       const android::Parcel& data,
     84       android::Parcel* reply,
     85       uint32_t flags = 0);
     86 
     87   DISALLOW_COPY_AND_ASSIGN(BnBluetoothGattClient);
     88 };
     89 
     90 // The Binder client interface to IBluetoothGattClient.
     91 class BpBluetoothGattClient
     92     : public android::BpInterface<IBluetoothGattClient> {
     93  public:
     94   explicit BpBluetoothGattClient(const android::sp<android::IBinder>& impl);
     95   virtual ~BpBluetoothGattClient() = default;
     96 
     97   // IBluetoothGattClient overrides:
     98   bool RegisterClient(
     99       const android::sp<IBluetoothGattClientCallback>& callback) override;
    100   void UnregisterClient(int client_id) override;
    101   void UnregisterAll() override;
    102 
    103  private:
    104   DISALLOW_COPY_AND_ASSIGN(BpBluetoothGattClient);
    105 };
    106 
    107 }  // namespace binder
    108 }  // namespace ipc
    109