• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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.
4 
5 #ifndef CHROMEOS_DBUS_SHILL_DEVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_SHILL_DEVICE_CLIENT_H_
7 
8 #include <string>
9 
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/dbus_client.h"
14 #include "chromeos/dbus/shill_client_helper.h"
15 
16 namespace base {
17 
18 class Value;
19 class DictionaryValue;
20 
21 }  // namespace base
22 
23 namespace dbus {
24 
25 class ObjectPath;
26 
27 }  // namespace dbus
28 
29 namespace chromeos {
30 
31 class ShillPropertyChangedObserver;
32 
33 // ShillDeviceClient is used to communicate with the Shill Device service.
34 // All methods should be called from the origin thread which initializes the
35 // DBusThreadManager instance.
36 class CHROMEOS_EXPORT ShillDeviceClient : public DBusClient {
37  public:
38   typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler;
39   typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback;
40   typedef ShillClientHelper::ErrorCallback ErrorCallback;
41 
42   // Interface for setting up devices for testing.
43   // Accessed through GetTestInterface(), only implemented in the Stub Impl.
44   class TestInterface {
45    public:
46     virtual void AddDevice(const std::string& device_path,
47                            const std::string& type,
48                            const std::string& object_path) = 0;
49     virtual void RemoveDevice(const std::string& device_path) = 0;
50     virtual void ClearDevices() = 0;
51     virtual void SetDeviceProperty(const std::string& device_path,
52                                    const std::string& name,
53                                    const base::Value& value) = 0;
54     virtual std::string GetDevicePathForType(const std::string& type) = 0;
55 
56    protected:
~TestInterface()57     virtual ~TestInterface() {}
58   };
59 
60   virtual ~ShillDeviceClient();
61 
62   // Factory function, creates a new instance which is owned by the caller.
63   // For normal usage, access the singleton via DBusThreadManager::Get().
64   static ShillDeviceClient* Create();
65 
66   // Adds a property changed |observer| for the device at |device_path|.
67   virtual void AddPropertyChangedObserver(
68       const dbus::ObjectPath& device_path,
69       ShillPropertyChangedObserver* observer) = 0;
70 
71   // Removes a property changed |observer| for the device at |device_path|.
72   virtual void RemovePropertyChangedObserver(
73       const dbus::ObjectPath& device_path,
74       ShillPropertyChangedObserver* observer) = 0;
75 
76   // Calls GetProperties method.
77   // |callback| is called after the method call finishes.
78   virtual void GetProperties(const dbus::ObjectPath& device_path,
79                              const DictionaryValueCallback& callback) = 0;
80 
81   // Calls ProposeScan method.
82   // |callback| is called after the method call finishes.
83   virtual void ProposeScan(const dbus::ObjectPath& device_path,
84                            const VoidDBusMethodCallback& callback) = 0;
85 
86   // Calls SetProperty method.
87   // |callback| is called after the method call finishes.
88   virtual void SetProperty(const dbus::ObjectPath& device_path,
89                            const std::string& name,
90                            const base::Value& value,
91                            const base::Closure& callback,
92                            const ErrorCallback& error_callback) = 0;
93 
94   // Calls ClearProperty method.
95   // |callback| is called after the method call finishes.
96   virtual void ClearProperty(const dbus::ObjectPath& device_path,
97                              const std::string& name,
98                              const VoidDBusMethodCallback& callback) = 0;
99 
100   // Calls AddIPConfig method.
101   // |callback| is called after the method call finishes.
102   virtual void AddIPConfig(const dbus::ObjectPath& device_path,
103                            const std::string& method,
104                            const ObjectPathDBusMethodCallback& callback) = 0;
105 
106   // Calls the RequirePin method.
107   // |callback| is called after the method call finishes.
108   virtual void RequirePin(const dbus::ObjectPath& device_path,
109                           const std::string& pin,
110                           bool require,
111                           const base::Closure& callback,
112                           const ErrorCallback& error_callback) = 0;
113 
114   // Calls the EnterPin method.
115   // |callback| is called after the method call finishes.
116   virtual void EnterPin(const dbus::ObjectPath& device_path,
117                         const std::string& pin,
118                         const base::Closure& callback,
119                         const ErrorCallback& error_callback) = 0;
120 
121   // Calls the UnblockPin method.
122   // |callback| is called after the method call finishes.
123   virtual void UnblockPin(const dbus::ObjectPath& device_path,
124                           const std::string& puk,
125                           const std::string& pin,
126                           const base::Closure& callback,
127                           const ErrorCallback& error_callback) = 0;
128 
129   // Calls the ChangePin method.
130   // |callback| is called after the method call finishes.
131   virtual void ChangePin(const dbus::ObjectPath& device_path,
132                          const std::string& old_pin,
133                          const std::string& new_pin,
134                          const base::Closure& callback,
135                          const ErrorCallback& error_callback) = 0;
136 
137   // Calls the Register method.
138   // |callback| is called after the method call finishes.
139   virtual void Register(const dbus::ObjectPath& device_path,
140                         const std::string& network_id,
141                         const base::Closure& callback,
142                         const ErrorCallback& error_callback) = 0;
143 
144   // Calls the SetCarrier method.
145   // |callback| is called after the method call finishes.
146   virtual void SetCarrier(const dbus::ObjectPath& device_path,
147                           const std::string& carrier,
148                           const base::Closure& callback,
149                           const ErrorCallback& error_callback) = 0;
150 
151   // Calls the Reset method.
152   // |callback| is called after the method call finishes.
153   virtual void Reset(const dbus::ObjectPath& device_path,
154                           const base::Closure& callback,
155                           const ErrorCallback& error_callback) = 0;
156 
157   // Returns an interface for testing (stub only), or returns NULL.
158   virtual TestInterface* GetTestInterface() = 0;
159 
160  protected:
161   friend class ShillDeviceClientTest;
162 
163   // Create() should be used instead.
164   ShillDeviceClient();
165 
166  private:
167   DISALLOW_COPY_AND_ASSIGN(ShillDeviceClient);
168 };
169 
170 }  // namespace chromeos
171 
172 #endif  // CHROMEOS_DBUS_SHILL_DEVICE_CLIENT_H_
173