• 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_SERVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_SHILL_SERVICE_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 // ShillServiceClient is used to communicate with the Shill Service
32 // service.
33 // All methods should be called from the origin thread which initializes the
34 // DBusThreadManager instance.
35 class CHROMEOS_EXPORT ShillServiceClient : public DBusClient {
36  public:
37   typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler;
38   typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback;
39   typedef ShillClientHelper::ListValueCallback ListValueCallback;
40   typedef ShillClientHelper::ErrorCallback ErrorCallback;
41 
42   // Interface for setting up services for testing. Accessed through
43   // GetTestInterface(), only implemented in the stub implementation.
44   class TestInterface {
45    public:
46     // Adds a Service to the Manager and Service stubs.
47     virtual void AddService(const std::string& service_path,
48                             const std::string& name,
49                             const std::string& type,
50                             const std::string& state,
51                             bool visible) = 0;
52     virtual void AddServiceWithIPConfig(const std::string& service_path,
53                                         const std::string& guid,
54                                         const std::string& name,
55                                         const std::string& type,
56                                         const std::string& state,
57                                         const std::string& ipconfig_path,
58                                         bool visible) = 0;
59     // Sets the properties for a service but does not add it to the Manager
60     // or Profile. Returns the properties for the service.
61     virtual base::DictionaryValue* SetServiceProperties(
62         const std::string& service_path,
63         const std::string& guid,
64         const std::string& name,
65         const std::string& type,
66         const std::string& state,
67         bool visible) = 0;
68 
69     // Removes a Service to the Manager and Service stubs.
70     virtual void RemoveService(const std::string& service_path) = 0;
71 
72     // Returns false if a Service matching |service_path| does not exist.
73     virtual bool SetServiceProperty(const std::string& service_path,
74                                     const std::string& property,
75                                     const base::Value& value) = 0;
76 
77     // Returns properties for |service_path| or NULL if no Service matches.
78     virtual const base::DictionaryValue* GetServiceProperties(
79         const std::string& service_path) const = 0;
80 
81     // Clears all Services from the Manager and Service stubs.
82     virtual void ClearServices() = 0;
83 
84     virtual void SetConnectBehavior(const std::string& service_path,
85                                     const base::Closure& behavior) = 0;
86 
87    protected:
~TestInterface()88     virtual ~TestInterface() {}
89   };
90   virtual ~ShillServiceClient();
91 
92   // Factory function, creates a new instance which is owned by the caller.
93   // For normal usage, access the singleton via DBusThreadManager::Get().
94   static ShillServiceClient* Create();
95 
96   // Adds a property changed |observer| to the service at |service_path|.
97   virtual void AddPropertyChangedObserver(
98       const dbus::ObjectPath& service_path,
99       ShillPropertyChangedObserver* observer) = 0;
100 
101   // Removes a property changed |observer| to the service at |service_path|.
102   virtual void RemovePropertyChangedObserver(
103       const dbus::ObjectPath& service_path,
104       ShillPropertyChangedObserver* observer) = 0;
105 
106   // Calls GetProperties method.
107   // |callback| is called after the method call succeeds.
108   virtual void GetProperties(const dbus::ObjectPath& service_path,
109                              const DictionaryValueCallback& callback) = 0;
110 
111   // Calls SetProperty method.
112   // |callback| is called after the method call succeeds.
113   virtual void SetProperty(const dbus::ObjectPath& service_path,
114                            const std::string& name,
115                            const base::Value& value,
116                            const base::Closure& callback,
117                            const ErrorCallback& error_callback) = 0;
118 
119   // Calls SetProperties method.
120   // |callback| is called after the method call succeeds.
121   virtual void SetProperties(const dbus::ObjectPath& service_path,
122                              const base::DictionaryValue& properties,
123                              const base::Closure& callback,
124                              const ErrorCallback& error_callback) = 0;
125 
126   // Calls ClearProperty method.
127   // |callback| is called after the method call succeeds.
128   virtual void ClearProperty(const dbus::ObjectPath& service_path,
129                              const std::string& name,
130                              const base::Closure& callback,
131                              const ErrorCallback& error_callback) = 0;
132 
133   // Calls ClearProperties method.
134   // |callback| is called after the method call succeeds.
135   virtual void ClearProperties(const dbus::ObjectPath& service_path,
136                                const std::vector<std::string>& names,
137                                const ListValueCallback& callback,
138                                const ErrorCallback& error_callback) = 0;
139 
140   // Calls Connect method.
141   // |callback| is called after the method call succeeds.
142   virtual void Connect(const dbus::ObjectPath& service_path,
143                        const base::Closure& callback,
144                        const ErrorCallback& error_callback) = 0;
145 
146   // Calls Disconnect method.
147   // |callback| is called after the method call succeeds.
148   virtual void Disconnect(const dbus::ObjectPath& service_path,
149                           const base::Closure& callback,
150                           const ErrorCallback& error_callback) = 0;
151 
152   // Calls Remove method.
153   // |callback| is called after the method call succeeds.
154   virtual void Remove(const dbus::ObjectPath& service_path,
155                       const base::Closure& callback,
156                       const ErrorCallback& error_callback) = 0;
157 
158   // Calls ActivateCellularModem method.
159   // |callback| is called after the method call succeeds.
160   virtual void ActivateCellularModem(
161       const dbus::ObjectPath& service_path,
162       const std::string& carrier,
163       const base::Closure& callback,
164       const ErrorCallback& error_callback) = 0;
165 
166   // Calls the CompleteCellularActivation method.
167   // |callback| is called after the method call succeeds.
168   virtual void CompleteCellularActivation(
169       const dbus::ObjectPath& service_path,
170       const base::Closure& callback,
171       const ErrorCallback& error_callback) = 0;
172 
173   // Calls the GetLoadableProfileEntries method.
174   // |callback| is called after the method call succeeds.
175   virtual void GetLoadableProfileEntries(
176       const dbus::ObjectPath& service_path,
177       const DictionaryValueCallback& callback) = 0;
178 
179   // Returns an interface for testing (stub only), or returns NULL.
180   virtual TestInterface* GetTestInterface() = 0;
181 
182  protected:
183   friend class ShillServiceClientTest;
184 
185   // Create() should be used instead.
186   ShillServiceClient();
187 
188  private:
189   DISALLOW_COPY_AND_ASSIGN(ShillServiceClient);
190 };
191 
192 }  // namespace chromeos
193 
194 #endif  // CHROMEOS_DBUS_SHILL_SERVICE_CLIENT_H_
195