1 // 2 // Copyright 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 #include <base/observer_list.h> 18 19 #include "abstract_observer_list.h" 20 #include "service/hal/bluetooth_interface.h" 21 #include "types/raw_address.h" 22 23 namespace bluetooth { 24 namespace hal { 25 26 class FakeBluetoothInterface : public BluetoothInterface { 27 public: 28 // A Fake HAL Bluetooth interface. This is kept as a global singleton as the 29 // Bluetooth HAL doesn't support anything otherwise. 30 // 31 // TODO(armansito): Use an abstract "TestHandler" interface instead. 32 struct Manager { 33 Manager(); 34 ~Manager() = default; 35 36 // Values that should be returned from bt_interface_t methods. 37 bool enable_succeed; 38 bool disable_succeed; 39 bool set_property_succeed; 40 }; 41 42 // Returns the global Manager. 43 static Manager* GetManager(); 44 45 FakeBluetoothInterface() = default; 46 FakeBluetoothInterface(const FakeBluetoothInterface&) = delete; 47 FakeBluetoothInterface& operator=(const FakeBluetoothInterface&) = delete; 48 49 ~FakeBluetoothInterface() override = default; 50 51 // Notifies the observers that the adapter state changed to |state|. 52 void NotifyAdapterStateChanged(bt_state_t state); 53 54 // Triggers an adapter property change event. 55 void NotifyAdapterPropertiesChanged(int num_properties, 56 bt_property_t* properties); 57 void NotifyAdapterNamePropertyChanged(const std::string& name); 58 void NotifyAdapterAddressPropertyChanged(const RawAddress* address); 59 void NotifyAdapterLocalLeFeaturesPropertyChanged( 60 const bt_local_le_features_t* features); 61 void NotifyAclStateChangedCallback(bt_status_t status, 62 const RawAddress& remote_bdaddr, 63 bt_acl_state_t state, 64 int transport_link_type, 65 bt_hci_error_code_t hci_reason); 66 67 // hal::BluetoothInterface overrides: 68 void AddObserver(Observer* observer) override; 69 void RemoveObserver(Observer* observer) override; 70 const bt_interface_t* GetHALInterface() const override; 71 bt_callbacks_t* GetHALCallbacks() const override; 72 73 private: 74 btbase::AbstractObserverList<Observer> observers_; 75 }; 76 77 } // namespace hal 78 } // namespace bluetooth 79