Home | History | Annotate | Download | only in bluetooth
      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 <rapidjson/document.h>
     20 #include <service/common/bluetooth/binder/IBluetooth.h>
     21 #include <service/common/bluetooth/binder/IBluetoothLowEnergy.h>
     22 #include <tuple>
     23 
     24 // BluetoothBinderFacade provides simple wrappers to call Binder apis.
     25 // Each public function returns a tuple of the return type and an integer
     26 // representing the pass/fail value of the function. The functions check to see
     27 // if the API call is actually possible. If it is the function's tuple will
     28 // contain the actual result and an integer that indicates the value passed. If
     29 // the function is not possible then there will be a dummy return value in the
     30 // first position of the tuple and the second value in the tuple indicates the
     31 // value failed. Therefore it is up to the function to decide whether the
     32 // expected api call is actually possible before calling it.
     33 //
     34 // TODO(tturney): Instead of using an integer in the tuple to represent
     35 // pass/fail, create a class that properly represents the result of the
     36 // function.
     37 class BluetoothBinderFacade {
     38  public:
     39   BluetoothBinderFacade();
     40   std::tuple<bool, int> BluetoothBinderEnable();
     41   std::tuple<std::string, int> BluetoothBinderGetAddress();
     42   std::tuple<std::string, int> BluetoothBinderGetName();
     43   std::tuple<bool, int> BluetoothBinderInitInterface();
     44   std::tuple<bool, int> BluetoothBinderRegisterBLE();
     45   std::tuple<int, int> BluetoothBinderSetAdvSettings(
     46     int mode, int timeout_seconds, int tx_power_level, bool is_connectable);
     47   std::tuple<bool, int> BluetoothBinderSetName(std::string name);
     48 
     49  private:
     50   bool SharedValidator();
     51   // Returns a handle to the IBluetooth Binder from the Android ServiceManager.
     52   // Binder client code can use this to make calls to the service.
     53   android::sp<ipc::binder::IBluetooth> bt_iface;
     54 
     55   // Returns a handle to the IBluetoothLowEnergy Binder from the Android
     56   // ServiceManager. Binder client code can use this to make calls to the
     57   // service.
     58   android::sp<ipc::binder::IBluetoothLowEnergy> ble_iface;
     59   std::map<int, bluetooth::AdvertiseSettings> adv_settings_map;
     60   int adv_settings_count;
     61   int manu_data_count;
     62 };
     63