OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_DBUS_SHILL_CLIENT_HELPER_H_ | 5 #ifndef CHROMEOS_DBUS_SHILL_CLIENT_HELPER_H_ |
6 #define CHROMEOS_DBUS_SHILL_CLIENT_HELPER_H_ | 6 #define CHROMEOS_DBUS_SHILL_CLIENT_HELPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 typedef base::Callback<void(const base::ListValue& result)> ListValueCallback; | 59 typedef base::Callback<void(const base::ListValue& result)> ListValueCallback; |
60 | 60 |
61 // A callback to handle errors for method call. | 61 // A callback to handle errors for method call. |
62 typedef base::Callback<void(const std::string& error_name, | 62 typedef base::Callback<void(const std::string& error_name, |
63 const std::string& error_message)> ErrorCallback; | 63 const std::string& error_message)> ErrorCallback; |
64 | 64 |
65 ShillClientHelper(dbus::Bus* bus, dbus::ObjectProxy* proxy); | 65 ShillClientHelper(dbus::Bus* bus, dbus::ObjectProxy* proxy); |
66 | 66 |
67 virtual ~ShillClientHelper(); | 67 virtual ~ShillClientHelper(); |
68 | 68 |
| 69 // Returns true if there is a PropertyChangedObserver registered. |
| 70 bool IsObserved() const; |
| 71 |
| 72 // Returns true if the are method calls waiting for a response. If this |
| 73 // function is called from within the return callback return true only if |
| 74 // there are *other* calls waiting for a response. |
| 75 bool IsWaitingResponse() const; |
| 76 |
69 // Adds an |observer| of the PropertyChanged signal. | 77 // Adds an |observer| of the PropertyChanged signal. |
70 void AddPropertyChangedObserver(ShillPropertyChangedObserver* observer); | 78 void AddPropertyChangedObserver(ShillPropertyChangedObserver* observer); |
71 | 79 |
72 // Removes an |observer| of the PropertyChanged signal. | 80 // Removes an |observer| of the PropertyChanged signal. |
73 void RemovePropertyChangedObserver(ShillPropertyChangedObserver* observer); | 81 void RemovePropertyChangedObserver(ShillPropertyChangedObserver* observer); |
74 | 82 |
75 // Starts monitoring PropertyChanged signal. | 83 // Starts monitoring PropertyChanged signal. If there aren't observers for the |
| 84 // PropertyChanged signal, the actual monitoring will be delayed until the |
| 85 // first observer is added. |
76 void MonitorPropertyChanged(const std::string& interface_name); | 86 void MonitorPropertyChanged(const std::string& interface_name); |
77 | 87 |
78 // Calls a method without results. | 88 // Calls a method without results. |
79 void CallVoidMethod(dbus::MethodCall* method_call, | 89 void CallVoidMethod(dbus::MethodCall* method_call, |
80 const VoidDBusMethodCallback& callback); | 90 const VoidDBusMethodCallback& callback); |
81 | 91 |
82 // Calls a method with an object path result. | 92 // Calls a method with an object path result. |
83 void CallObjectPathMethod(dbus::MethodCall* method_call, | 93 void CallObjectPathMethod(dbus::MethodCall* method_call, |
84 const ObjectPathDBusMethodCallback& callback); | 94 const ObjectPathDBusMethodCallback& callback); |
85 | 95 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // This method returns NULL when method call fails. | 128 // This method returns NULL when method call fails. |
119 base::DictionaryValue* CallDictionaryValueMethodAndBlock( | 129 base::DictionaryValue* CallDictionaryValueMethodAndBlock( |
120 dbus::MethodCall* method_call); | 130 dbus::MethodCall* method_call); |
121 | 131 |
122 // Appends the value (basic types and string-to-string dictionary) to the | 132 // Appends the value (basic types and string-to-string dictionary) to the |
123 // writer as a variant. | 133 // writer as a variant. |
124 static void AppendValueDataAsVariant(dbus::MessageWriter* writer, | 134 static void AppendValueDataAsVariant(dbus::MessageWriter* writer, |
125 const base::Value& value); | 135 const base::Value& value); |
126 | 136 |
127 private: | 137 private: |
| 138 // Starts monitoring PropertyChanged signal. |
| 139 void MonitorPropertyChangedInternal(const std::string& interface_name); |
| 140 |
128 // Handles the result of signal connection setup. | 141 // Handles the result of signal connection setup. |
129 void OnSignalConnected(const std::string& interface, | 142 void OnSignalConnected(const std::string& interface, |
130 const std::string& signal, | 143 const std::string& signal, |
131 bool success); | 144 bool success); |
132 | 145 |
133 // Handles PropertyChanged signal. | 146 // Handles PropertyChanged signal. |
134 void OnPropertyChanged(dbus::Signal* signal); | 147 void OnPropertyChanged(dbus::Signal* signal); |
135 | 148 |
136 // Handles responses for methods without results. | 149 // Handles responses for methods without results. |
137 void OnVoidMethod(const VoidDBusMethodCallback& callback, | 150 void OnVoidMethod(const VoidDBusMethodCallback& callback, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // Handles errors for method calls. | 186 // Handles errors for method calls. |
174 void OnError(const ErrorCallback& error_callback, | 187 void OnError(const ErrorCallback& error_callback, |
175 dbus::ErrorResponse* response); | 188 dbus::ErrorResponse* response); |
176 | 189 |
177 // TODO(hashimoto): Remove this when we no longer need to make blocking calls. | 190 // TODO(hashimoto): Remove this when we no longer need to make blocking calls. |
178 BlockingMethodCaller blocking_method_caller_; | 191 BlockingMethodCaller blocking_method_caller_; |
179 dbus::ObjectProxy* proxy_; | 192 dbus::ObjectProxy* proxy_; |
180 PropertyChangedHandler property_changed_handler_; | 193 PropertyChangedHandler property_changed_handler_; |
181 ObserverList<ShillPropertyChangedObserver, true /* check_empty */> | 194 ObserverList<ShillPropertyChangedObserver, true /* check_empty */> |
182 observer_list_; | 195 observer_list_; |
| 196 int in_progress_calls_; |
| 197 std::vector<std::string> monitored_interfaces_; |
183 | 198 |
184 // Note: This should remain the last member so it'll be destroyed and | 199 // Note: This should remain the last member so it'll be destroyed and |
185 // invalidate its weak pointers before any other members are destroyed. | 200 // invalidate its weak pointers before any other members are destroyed. |
186 base::WeakPtrFactory<ShillClientHelper> weak_ptr_factory_; | 201 base::WeakPtrFactory<ShillClientHelper> weak_ptr_factory_; |
187 | 202 |
188 DISALLOW_COPY_AND_ASSIGN(ShillClientHelper); | 203 DISALLOW_COPY_AND_ASSIGN(ShillClientHelper); |
189 }; | 204 }; |
190 | 205 |
191 } // namespace chromeos | 206 } // namespace chromeos |
192 | 207 |
193 #endif // CHROMEOS_DBUS_SHILL_CLIENT_HELPER_H_ | 208 #endif // CHROMEOS_DBUS_SHILL_CLIENT_HELPER_H_ |
OLD | NEW |