1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/observer_list.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/bluetooth_adapter_client.h"
15 #include "dbus/object_path.h"
16 #include "dbus/property.h"
20 // FakeBluetoothAdapterClient simulates the behavior of the Bluetooth Daemon
21 // adapter objects and is used both in test cases in place of a mock and on
23 class CHROMEOS_EXPORT FakeBluetoothAdapterClient
24 : public BluetoothAdapterClient
{
26 struct Properties
: public BluetoothAdapterClient::Properties
{
27 explicit Properties(const PropertyChangedCallback
& callback
);
28 ~Properties() override
;
30 // dbus::PropertySet override
31 void Get(dbus::PropertyBase
* property
,
32 dbus::PropertySet::GetCallback callback
) override
;
33 void GetAll() override
;
34 void Set(dbus::PropertyBase
* property
,
35 dbus::PropertySet::SetCallback callback
) override
;
38 FakeBluetoothAdapterClient();
39 ~FakeBluetoothAdapterClient() override
;
41 // BluetoothAdapterClient overrides
42 void Init(dbus::Bus
* bus
) override
;
43 void AddObserver(Observer
* observer
) override
;
44 void RemoveObserver(Observer
* observer
) override
;
45 std::vector
<dbus::ObjectPath
> GetAdapters() override
;
46 Properties
* GetProperties(const dbus::ObjectPath
& object_path
) override
;
47 void StartDiscovery(const dbus::ObjectPath
& object_path
,
48 const base::Closure
& callback
,
49 const ErrorCallback
& error_callback
) override
;
50 void StopDiscovery(const dbus::ObjectPath
& object_path
,
51 const base::Closure
& callback
,
52 const ErrorCallback
& error_callback
) override
;
53 void RemoveDevice(const dbus::ObjectPath
& object_path
,
54 const dbus::ObjectPath
& device_path
,
55 const base::Closure
& callback
,
56 const ErrorCallback
& error_callback
) override
;
57 void SetDiscoveryFilter(const dbus::ObjectPath
& object_path
,
58 const DiscoveryFilter
& discovery_filter
,
59 const base::Closure
& callback
,
60 const ErrorCallback
& error_callback
) override
;
62 // Sets the current simulation timeout interval.
63 void SetSimulationIntervalMs(int interval_ms
);
65 // Mark the adapter and second adapter as visible or invisible.
66 void SetVisible(bool visible
);
67 void SetSecondVisible(bool visible
);
69 // Object path, name and addresses of the adapters we emulate.
70 static const char kAdapterPath
[];
71 static const char kAdapterName
[];
72 static const char kAdapterAddress
[];
74 static const char kSecondAdapterPath
[];
75 static const char kSecondAdapterName
[];
76 static const char kSecondAdapterAddress
[];
79 // Property callback passed when we create Properties* structures.
80 void OnPropertyChanged(const std::string
& property_name
);
82 // Posts the delayed task represented by |callback| onto the current
83 // message loop to be executed after |simulation_interval_ms_| milliseconds.
84 void PostDelayedTask(const base::Closure
& callback
);
86 // List of observers interested in event notifications from us.
87 ObserverList
<Observer
> observers_
;
89 // Static properties we return.
90 scoped_ptr
<Properties
> properties_
;
91 scoped_ptr
<Properties
> second_properties_
;
93 // Whether the adapter and second adapter should be visible or not.
97 // Number of times we've been asked to discover.
98 int discovering_count_
;
100 // Current timeout interval used when posting delayed tasks.
101 int simulation_interval_ms_
;
104 } // namespace chromeos
106 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_