blob: 553d4e01ee72208d491cadbe1605d7fcd2d13fe5 [file] [log] [blame]
Arman Uguray2202cd52015-08-13 15:49:47 -07001//
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
Arman Uguray2202cd52015-08-13 15:49:47 -070017#include <base/macros.h>
Arman Uguray4fdadb62015-08-13 16:09:35 -070018#include <base/observer_list.h>
Arman Uguray2202cd52015-08-13 15:49:47 -070019
Arman Uguray9ded7b62015-08-31 16:29:07 -070020#include "service/hal/bluetooth_interface.h"
21
Arman Uguray2202cd52015-08-13 15:49:47 -070022namespace bluetooth {
Arman Uguray2117e522015-08-14 17:23:47 -070023namespace hal {
Arman Uguray2202cd52015-08-13 15:49:47 -070024
Arman Uguray2117e522015-08-14 17:23:47 -070025class FakeBluetoothInterface : public BluetoothInterface {
Arman Uguray2202cd52015-08-13 15:49:47 -070026 public:
Arman Uguray2117e522015-08-14 17:23:47 -070027 // A Fake HAL Bluetooth interface. This is kept as a global singleton as the
28 // Bluetooth HAL doesn't support anything otherwise.
Arman Uguray9ded7b62015-08-31 16:29:07 -070029 //
30 // TODO(armansito): Use an abstract "TestHandler" interface instead.
Arman Uguray2117e522015-08-14 17:23:47 -070031 struct Manager {
32 Manager();
33 ~Manager() = default;
34
35 // Values that should be returned from bt_interface_t methods.
36 bool enable_succeed;
37 bool disable_succeed;
38 bool set_property_succeed;
39 };
40
41 // Returns the global Manager.
42 static Manager* GetManager();
43
44 FakeBluetoothInterface() = default;
45 ~FakeBluetoothInterface() override = default;
Arman Uguray2202cd52015-08-13 15:49:47 -070046
Arman Uguray4fdadb62015-08-13 16:09:35 -070047 // Notifies the observers that the adapter state changed to |state|.
48 void NotifyAdapterStateChanged(bt_state_t state);
Arman Uguray2202cd52015-08-13 15:49:47 -070049
Arman Uguray03b1f0f2015-08-17 17:23:42 -070050 // Triggers an adapter property change event.
51 void NotifyAdapterPropertiesChanged(int num_properties,
52 bt_property_t* properties);
53 void NotifyAdapterNamePropertyChanged(const std::string& name);
54 void NotifyAdapterAddressPropertyChanged(const bt_bdaddr_t* address);
Arman Uguray10b54c42015-08-21 14:59:57 -070055 void NotifyAdapterLocalLeFeaturesPropertyChanged(
56 const bt_local_le_features_t* features);
Arman Uguray0f29c002015-11-13 15:05:48 -080057 void NotifyAclStateChangedCallback(
58 bt_status_t status,
59 const bt_bdaddr_t& remote_bdaddr,
60 bt_acl_state_t state);
Arman Uguray03b1f0f2015-08-17 17:23:42 -070061
Arman Uguray2202cd52015-08-13 15:49:47 -070062 // hal::BluetoothInterface overrides:
63 void AddObserver(Observer* observer) override;
64 void RemoveObserver(Observer* observer) override;
65 const bt_interface_t* GetHALInterface() const override;
66 const bluetooth_device_t* GetHALAdapter() const override;
67
68 private:
Arman Uguray4fdadb62015-08-13 16:09:35 -070069 base::ObserverList<Observer> observers_;
Arman Uguray2117e522015-08-14 17:23:47 -070070
71 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothInterface);
Arman Uguray2202cd52015-08-13 15:49:47 -070072};
73
Arman Uguray2117e522015-08-14 17:23:47 -070074} // namespace hal
Arman Uguray2202cd52015-08-13 15:49:47 -070075} // namespace bluetooth