Arman Uguray | 2202cd5 | 2015-08-13 15:49:47 -0700 | [diff] [blame] | 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 | |
Arman Uguray | 2202cd5 | 2015-08-13 15:49:47 -0700 | [diff] [blame] | 17 | #include <base/macros.h> |
Arman Uguray | 4fdadb6 | 2015-08-13 16:09:35 -0700 | [diff] [blame] | 18 | #include <base/observer_list.h> |
Arman Uguray | 2202cd5 | 2015-08-13 15:49:47 -0700 | [diff] [blame] | 19 | |
Arman Uguray | 9ded7b6 | 2015-08-31 16:29:07 -0700 | [diff] [blame] | 20 | #include "service/hal/bluetooth_interface.h" |
| 21 | |
Arman Uguray | 2202cd5 | 2015-08-13 15:49:47 -0700 | [diff] [blame] | 22 | namespace bluetooth { |
Arman Uguray | 2117e52 | 2015-08-14 17:23:47 -0700 | [diff] [blame] | 23 | namespace hal { |
Arman Uguray | 2202cd5 | 2015-08-13 15:49:47 -0700 | [diff] [blame] | 24 | |
Arman Uguray | 2117e52 | 2015-08-14 17:23:47 -0700 | [diff] [blame] | 25 | class FakeBluetoothInterface : public BluetoothInterface { |
Arman Uguray | 2202cd5 | 2015-08-13 15:49:47 -0700 | [diff] [blame] | 26 | public: |
Arman Uguray | 2117e52 | 2015-08-14 17:23:47 -0700 | [diff] [blame] | 27 | // A Fake HAL Bluetooth interface. This is kept as a global singleton as the |
| 28 | // Bluetooth HAL doesn't support anything otherwise. |
Arman Uguray | 9ded7b6 | 2015-08-31 16:29:07 -0700 | [diff] [blame] | 29 | // |
| 30 | // TODO(armansito): Use an abstract "TestHandler" interface instead. |
Arman Uguray | 2117e52 | 2015-08-14 17:23:47 -0700 | [diff] [blame] | 31 | 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 Uguray | 2202cd5 | 2015-08-13 15:49:47 -0700 | [diff] [blame] | 46 | |
Arman Uguray | 4fdadb6 | 2015-08-13 16:09:35 -0700 | [diff] [blame] | 47 | // Notifies the observers that the adapter state changed to |state|. |
| 48 | void NotifyAdapterStateChanged(bt_state_t state); |
Arman Uguray | 2202cd5 | 2015-08-13 15:49:47 -0700 | [diff] [blame] | 49 | |
Arman Uguray | 03b1f0f | 2015-08-17 17:23:42 -0700 | [diff] [blame] | 50 | // 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 Uguray | 10b54c4 | 2015-08-21 14:59:57 -0700 | [diff] [blame] | 55 | void NotifyAdapterLocalLeFeaturesPropertyChanged( |
| 56 | const bt_local_le_features_t* features); |
Arman Uguray | 0f29c00 | 2015-11-13 15:05:48 -0800 | [diff] [blame] | 57 | void NotifyAclStateChangedCallback( |
| 58 | bt_status_t status, |
| 59 | const bt_bdaddr_t& remote_bdaddr, |
| 60 | bt_acl_state_t state); |
Arman Uguray | 03b1f0f | 2015-08-17 17:23:42 -0700 | [diff] [blame] | 61 | |
Arman Uguray | 2202cd5 | 2015-08-13 15:49:47 -0700 | [diff] [blame] | 62 | // 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 Uguray | 4fdadb6 | 2015-08-13 16:09:35 -0700 | [diff] [blame] | 69 | base::ObserverList<Observer> observers_; |
Arman Uguray | 2117e52 | 2015-08-14 17:23:47 -0700 | [diff] [blame] | 70 | |
| 71 | DISALLOW_COPY_AND_ASSIGN(FakeBluetoothInterface); |
Arman Uguray | 2202cd5 | 2015-08-13 15:49:47 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Arman Uguray | 2117e52 | 2015-08-14 17:23:47 -0700 | [diff] [blame] | 74 | } // namespace hal |
Arman Uguray | 2202cd5 | 2015-08-13 15:49:47 -0700 | [diff] [blame] | 75 | } // namespace bluetooth |