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" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/observer_list.h" | |
13 #include "chromeos/dbus/blocking_method_caller.h" | 14 #include "chromeos/dbus/blocking_method_caller.h" |
14 #include "chromeos/dbus/dbus_method_call_status.h" | 15 #include "chromeos/dbus/dbus_method_call_status.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 | 18 |
18 class Value; | 19 class Value; |
19 class DictionaryValue; | 20 class DictionaryValue; |
20 | 21 |
21 } // namespace base | 22 } // namespace base |
22 | 23 |
(...skipping 17 matching lines...) Expand all Loading... | |
40 public: | 41 public: |
41 // A callback to handle PropertyChanged signals. | 42 // A callback to handle PropertyChanged signals. |
42 typedef base::Callback<void(const std::string& name, | 43 typedef base::Callback<void(const std::string& name, |
43 const base::Value& value)> PropertyChangedHandler; | 44 const base::Value& value)> PropertyChangedHandler; |
44 | 45 |
45 // A callback to handle responses for methods with DictionaryValue results. | 46 // A callback to handle responses for methods with DictionaryValue results. |
46 typedef base::Callback<void( | 47 typedef base::Callback<void( |
47 DBusMethodCallStatus call_status, | 48 DBusMethodCallStatus call_status, |
48 const base::DictionaryValue& result)> DictionaryValueCallback; | 49 const base::DictionaryValue& result)> DictionaryValueCallback; |
49 | 50 |
50 // A callback to handle responses for methods with DictionaryValue reuslts. | 51 // A callback to handle responses for methods with DictionaryValue results. |
51 // This is used by CallDictionaryValueMethodWithErrorCallback. | 52 // This is used by CallDictionaryValueMethodWithErrorCallback. |
52 typedef base::Callback<void(const base::DictionaryValue& result | 53 typedef base::Callback<void(const base::DictionaryValue& result |
53 )> DictionaryValueCallbackWithoutStatus; | 54 )> DictionaryValueCallbackWithoutStatus; |
54 | 55 |
55 // A callback to handle erros for method call. | 56 // A callback to handle errors for method call. |
56 typedef base::Callback<void(const std::string& error_name, | 57 typedef base::Callback<void(const std::string& error_name, |
57 const std::string& error_message)> ErrorCallback; | 58 const std::string& error_message)> ErrorCallback; |
58 | 59 |
60 class PropertyChangedObserver { | |
hashimoto
2012/09/21 11:52:01
Please add class comment, especially about the eve
Greg Spencer (Chromium)
2012/09/21 22:03:47
Done.
| |
61 public: | |
62 virtual void OnPropertyChanged(const std::string& name, | |
63 const base::Value& value) = 0; | |
64 }; | |
65 | |
59 ShillClientHelper(dbus::Bus* bus, dbus::ObjectProxy* proxy); | 66 ShillClientHelper(dbus::Bus* bus, dbus::ObjectProxy* proxy); |
60 | 67 |
61 virtual ~ShillClientHelper(); | 68 virtual ~ShillClientHelper(); |
62 | 69 |
63 // Sets PropertyChanged signal handler. | 70 void AddPropertyChangedObserver(PropertyChangedObserver* observer); |
hashimoto
2012/09/21 11:52:01
Please add method comments.
Greg Spencer (Chromium)
2012/09/21 22:03:47
Done.
| |
64 void SetPropertyChangedHandler(const PropertyChangedHandler& handler); | 71 void RemovePropertyChangedObserver(PropertyChangedObserver* observer); |
65 | |
66 // Resets PropertyChanged signal handler. | |
67 void ResetPropertyChangedHandler(); | |
68 | 72 |
69 // Starts monitoring PropertyChanged signal. | 73 // Starts monitoring PropertyChanged signal. |
70 void MonitorPropertyChanged(const std::string& interface_name); | 74 void MonitorPropertyChanged(const std::string& interface_name); |
71 | 75 |
72 // Calls a method without results. | 76 // Calls a method without results. |
73 void CallVoidMethod(dbus::MethodCall* method_call, | 77 void CallVoidMethod(dbus::MethodCall* method_call, |
74 const VoidDBusMethodCallback& callback); | 78 const VoidDBusMethodCallback& callback); |
75 | 79 |
76 // Calls a method with an object path result. | 80 // Calls a method with an object path result. |
77 void CallObjectPathMethod(dbus::MethodCall* method_call, | 81 void CallObjectPathMethod(dbus::MethodCall* method_call, |
78 const ObjectPathDBusMethodCallback& callback); | 82 const ObjectPathDBusMethodCallback& callback); |
79 | 83 |
84 // Calls a method with an object path result where there is an error callback. | |
85 void CallObjectPathMethodWithErrorCallback( | |
86 dbus::MethodCall* method_call, | |
87 const ObjectPathDBusMethodCallback& callback, | |
hashimoto
2012/09/21 11:52:01
Can we introduce something like DictionaryValueCal
Greg Spencer (Chromium)
2012/09/21 22:03:47
Done.
| |
88 const ErrorCallback& error_callback); | |
89 | |
80 // Calls a method with a dictionary value result. | 90 // Calls a method with a dictionary value result. |
81 void CallDictionaryValueMethod(dbus::MethodCall* method_call, | 91 void CallDictionaryValueMethod(dbus::MethodCall* method_call, |
82 const DictionaryValueCallback& callback); | 92 const DictionaryValueCallback& callback); |
83 | 93 |
84 // Calls a method without results with error callback. | 94 // Calls a method without results with error callback. |
85 void CallVoidMethodWithErrorCallback(dbus::MethodCall* method_call, | 95 void CallVoidMethodWithErrorCallback(dbus::MethodCall* method_call, |
86 const base::Closure& callback, | 96 const base::Closure& callback, |
87 const ErrorCallback& error_callback); | 97 const ErrorCallback& error_callback); |
88 | 98 |
89 // Calls a method with a dictionary value result with error callback. | 99 // Calls a method with a dictionary value result with error callback. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 dbus::Response* response); | 153 dbus::Response* response); |
144 | 154 |
145 // Handles errors for method calls. | 155 // Handles errors for method calls. |
146 void OnError(const ErrorCallback& error_callback, | 156 void OnError(const ErrorCallback& error_callback, |
147 dbus::ErrorResponse* response); | 157 dbus::ErrorResponse* response); |
148 | 158 |
149 // TODO(hashimoto): Remove this when we no longer need to make blocking calls. | 159 // TODO(hashimoto): Remove this when we no longer need to make blocking calls. |
150 BlockingMethodCaller blocking_method_caller_; | 160 BlockingMethodCaller blocking_method_caller_; |
151 dbus::ObjectProxy* proxy_; | 161 dbus::ObjectProxy* proxy_; |
152 PropertyChangedHandler property_changed_handler_; | 162 PropertyChangedHandler property_changed_handler_; |
163 ObserverList<PropertyChangedObserver> observer_list_; | |
153 | 164 |
154 // Note: This should remain the last member so it'll be destroyed and | 165 // Note: This should remain the last member so it'll be destroyed and |
155 // invalidate its weak pointers before any other members are destroyed. | 166 // invalidate its weak pointers before any other members are destroyed. |
156 base::WeakPtrFactory<ShillClientHelper> weak_ptr_factory_; | 167 base::WeakPtrFactory<ShillClientHelper> weak_ptr_factory_; |
157 | 168 |
158 DISALLOW_COPY_AND_ASSIGN(ShillClientHelper); | 169 DISALLOW_COPY_AND_ASSIGN(ShillClientHelper); |
159 }; | 170 }; |
160 | 171 |
161 } // namespace chromeos | 172 } // namespace chromeos |
162 | 173 |
163 #endif // CHROMEOS_DBUS_SHILL_CLIENT_HELPER_H_ | 174 #endif // CHROMEOS_DBUS_SHILL_CLIENT_HELPER_H_ |
OLD | NEW |