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_SHILL_DEVICE_CLIENT_STUB_H_
6 #define CHROMEOS_DBUS_SHILL_DEVICE_CLIENT_STUB_H_
10 #include "base/basictypes.h"
11 #include "chromeos/dbus/shill_device_client.h"
15 // A stub implementation of ShillDeviceClient.
16 // Implemented: Stub cellular device for SMS testing.
17 class ShillDeviceClientStub
: public ShillDeviceClient
,
18 public ShillDeviceClient::TestInterface
{
20 ShillDeviceClientStub();
21 virtual ~ShillDeviceClientStub();
23 // ShillDeviceClient overrides.
24 virtual void AddPropertyChangedObserver(
25 const dbus::ObjectPath
& device_path
,
26 ShillPropertyChangedObserver
* observer
) OVERRIDE
;
27 virtual void RemovePropertyChangedObserver(
28 const dbus::ObjectPath
& device_path
,
29 ShillPropertyChangedObserver
* observer
) OVERRIDE
;
30 virtual void GetProperties(const dbus::ObjectPath
& device_path
,
31 const DictionaryValueCallback
& callback
) OVERRIDE
;
32 virtual void ProposeScan(const dbus::ObjectPath
& device_path
,
33 const VoidDBusMethodCallback
& callback
) OVERRIDE
;
35 virtual void SetProperty(const dbus::ObjectPath
& device_path
,
36 const std::string
& name
,
37 const base::Value
& value
,
38 const base::Closure
& callback
,
39 const ErrorCallback
& error_callback
) OVERRIDE
;
40 virtual void ClearProperty(const dbus::ObjectPath
& device_path
,
41 const std::string
& name
,
42 const VoidDBusMethodCallback
& callback
) OVERRIDE
;
43 virtual void AddIPConfig(
44 const dbus::ObjectPath
& device_path
,
45 const std::string
& method
,
46 const ObjectPathDBusMethodCallback
& callback
) OVERRIDE
;
47 virtual void RequirePin(const dbus::ObjectPath
& device_path
,
48 const std::string
& pin
,
50 const base::Closure
& callback
,
51 const ErrorCallback
& error_callback
) OVERRIDE
;
52 virtual void EnterPin(const dbus::ObjectPath
& device_path
,
53 const std::string
& pin
,
54 const base::Closure
& callback
,
55 const ErrorCallback
& error_callback
) OVERRIDE
;
56 virtual void UnblockPin(const dbus::ObjectPath
& device_path
,
57 const std::string
& puk
,
58 const std::string
& pin
,
59 const base::Closure
& callback
,
60 const ErrorCallback
& error_callback
) OVERRIDE
;
61 virtual void ChangePin(const dbus::ObjectPath
& device_path
,
62 const std::string
& old_pin
,
63 const std::string
& new_pin
,
64 const base::Closure
& callback
,
65 const ErrorCallback
& error_callback
) OVERRIDE
;
66 virtual void Register(const dbus::ObjectPath
& device_path
,
67 const std::string
& network_id
,
68 const base::Closure
& callback
,
69 const ErrorCallback
& error_callback
) OVERRIDE
;
70 virtual void SetCarrier(const dbus::ObjectPath
& device_path
,
71 const std::string
& carrier
,
72 const base::Closure
& callback
,
73 const ErrorCallback
& error_callback
) OVERRIDE
;
74 virtual void Reset(const dbus::ObjectPath
& device_path
,
75 const base::Closure
& callback
,
76 const ErrorCallback
& error_callback
) OVERRIDE
;
77 virtual ShillDeviceClient::TestInterface
* GetTestInterface() OVERRIDE
;
79 // ShillDeviceClient::TestInterface overrides.
80 virtual void AddDevice(const std::string
& device_path
,
81 const std::string
& type
,
82 const std::string
& object_path
) OVERRIDE
;
83 virtual void RemoveDevice(const std::string
& device_path
) OVERRIDE
;
84 virtual void ClearDevices() OVERRIDE
;
85 virtual void SetDeviceProperty(const std::string
& device_path
,
86 const std::string
& name
,
87 const base::Value
& value
) OVERRIDE
;
88 virtual std::string
GetDevicePathForType(const std::string
& type
) OVERRIDE
;
91 typedef ObserverList
<ShillPropertyChangedObserver
> PropertyObserverList
;
93 void SetDefaultProperties();
94 void PassStubDeviceProperties(const dbus::ObjectPath
& device_path
,
95 const DictionaryValueCallback
& callback
) const;
97 // Posts a task to run a void callback with status code |status|.
98 void PostVoidCallback(const VoidDBusMethodCallback
& callback
,
99 DBusMethodCallStatus status
);
101 void NotifyObserversPropertyChanged(const dbus::ObjectPath
& device_path
,
102 const std::string
& property
);
103 base::DictionaryValue
* GetDeviceProperties(const std::string
& device_path
);
104 PropertyObserverList
& GetObserverList(const dbus::ObjectPath
& device_path
);
106 // Dictionary of <device_name, Dictionary>.
107 base::DictionaryValue stub_devices_
;
108 // Observer list for each device.
109 std::map
<dbus::ObjectPath
, PropertyObserverList
*> observer_list_
;
111 // Note: This should remain the last member so it'll be destroyed and
112 // invalidate its weak pointers before any other members are destroyed.
113 base::WeakPtrFactory
<ShillDeviceClientStub
> weak_ptr_factory_
;
115 DISALLOW_COPY_AND_ASSIGN(ShillDeviceClientStub
);
118 } // namespace chromeos
120 #endif // CHROMEOS_DBUS_SHILL_DEVICE_CLIENT_STUB_H_