aboutsummaryrefslogtreecommitdiff
path: root/service/hal/fake_bluetooth_interface.h
blob: b7dc83259a5702b0af657159e1e9c331d92e58e6 (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
63
64
65
66
67
68
69
70
71
72
73
74
//
//  Copyright 2015 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.
//

#include <base/macros.h>
#include <base/observer_list.h>

#include "service/hal/bluetooth_interface.h"

namespace bluetooth {
namespace hal {

class FakeBluetoothInterface : public BluetoothInterface {
 public:
  // A Fake HAL Bluetooth interface. This is kept as a global singleton as the
  // Bluetooth HAL doesn't support anything otherwise.
  //
  // TODO(armansito): Use an abstract "TestHandler" interface instead.
  struct Manager {
    Manager();
    ~Manager() = default;

    // Values that should be returned from bt_interface_t methods.
    bool enable_succeed;
    bool disable_succeed;
    bool set_property_succeed;
  };

  // Returns the global Manager.
  static Manager* GetManager();

  FakeBluetoothInterface() = default;
  ~FakeBluetoothInterface() override = default;

  // Notifies the observers that the adapter state changed to |state|.
  void NotifyAdapterStateChanged(bt_state_t state);

  // Triggers an adapter property change event.
  void NotifyAdapterPropertiesChanged(int num_properties,
                                      bt_property_t* properties);
  void NotifyAdapterNamePropertyChanged(const std::string& name);
  void NotifyAdapterAddressPropertyChanged(const RawAddress* address);
  void NotifyAdapterLocalLeFeaturesPropertyChanged(
      const bt_local_le_features_t* features);
  void NotifyAclStateChangedCallback(bt_status_t status,
                                     const RawAddress& remote_bdaddr,
                                     bt_acl_state_t state);

  // hal::BluetoothInterface overrides:
  void AddObserver(Observer* observer) override;
  void RemoveObserver(Observer* observer) override;
  const bt_interface_t* GetHALInterface() const override;
  bt_callbacks_t* GetHALCallbacks() const override;

 private:
  base::ObserverList<Observer> observers_;

  DISALLOW_COPY_AND_ASSIGN(FakeBluetoothInterface);
};

}  // namespace hal
}  // namespace bluetooth