summaryrefslogtreecommitdiff
path: root/sl4n/facades/bluetooth/bt_binder_facade.h
blob: 65ece71d438c8c4169644080c30a9a3684244cf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
//  Copyright (C) 2016 Google, Inc.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at:
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#pragma once

#include <rapidjson/document.h>
#include <android/bluetooth/IBluetooth.h>
#include <android/bluetooth/IBluetoothLowEnergy.h>
#include <tuple>

// BtBinderFacade provides simple wrappers to call Binder apis.
// Each public function returns a tuple of the return type and an integer
// representing the pass/fail value of the function. The functions check to see
// if the API call is actually possible. If it is the function's tuple will
// contain the actual result and an integer that indicates the value passed. If
// the function is not possible then there will be a mock return value in the
// first position of the tuple and the second value in the tuple indicates the
// value failed. Therefore it is up to the function to decide whether the
// expected api call is actually possible before calling it.
//
// TODO(tturney): Instead of using an integer in the tuple to represent
// pass/fail, create a class that properly represents the result of the
// function.
class BtBinderFacade {
 public:
  BtBinderFacade();
  std::tuple<bool, int> BtBinderEnable();
  std::tuple<std::string, int> BtBinderGetAddress();
  std::tuple<std::string, int> BtBinderGetName();
  std::tuple<bool, int> BtBinderInitInterface();
  std::tuple<bool, int> BtBinderRegisterBLE();
  std::tuple<int, int> BtBinderSetAdvSettings(
    int mode, int timeout_seconds, int tx_power_level, bool is_connectable);
  std::tuple<bool, int> BtBinderSetName(std::string name);

 private:
  bool SharedValidator();
  // Returns a handle to the IBluetooth Binder from the Android ServiceManager.
  // Binder client code can use this to make calls to the service.
  android::sp<android::bluetooth::IBluetooth> bt_iface;

  // Returns a handle to the IBluetoothLowEnergy Binder from the Android
  // ServiceManager. Binder client code can use this to make calls to the
  // service.
  android::sp<android::bluetooth::IBluetoothLowEnergy> ble_iface;
  std::map<int, bluetooth::AdvertiseSettings> adv_settings_map;
  int adv_settings_count;
  int manu_data_count;
};