Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // A callback that handles responses for methods with string results. | 65 // A callback that handles responses for methods with string results. |
| 66 typedef base::Callback<void(const std::string& result)> StringCallback; | 66 typedef base::Callback<void(const std::string& result)> StringCallback; |
| 67 | 67 |
| 68 // A callback that handles responses for methods with boolean results. | 68 // A callback that handles responses for methods with boolean results. |
| 69 typedef base::Callback<void(bool result)> BooleanCallback; | 69 typedef base::Callback<void(bool result)> BooleanCallback; |
| 70 | 70 |
| 71 | 71 |
| 72 ShillClientHelper(dbus::Bus* bus, dbus::ObjectProxy* proxy); | 72 // Interface class for owner of this class so that it can be notified. |
| 73 class Owner { | |
| 74 public: | |
| 75 // Notifies the owner that |helper| can be released (no active references). | |
| 76 virtual void NotifyReleased(ShillClientHelper* helper) = 0; | |
| 77 | |
| 78 protected: | |
| 79 virtual ~Owner() {} | |
| 80 }; | |
| 81 | |
| 82 explicit ShillClientHelper(dbus::ObjectProxy* proxy); | |
| 73 | 83 |
| 74 virtual ~ShillClientHelper(); | 84 virtual ~ShillClientHelper(); |
| 75 | 85 |
| 86 // Sets |owner_|. This is optional and should only be called at most once. | |
| 87 void SetOwner(Owner* owner); | |
|
hashimoto
2013/09/17 03:28:53
nit: Since the Owner interface has only one method
stevenjb
2013/09/17 21:03:17
Sure, I'll change this to SetReleasedCallback.
| |
| 88 | |
| 76 // Adds an |observer| of the PropertyChanged signal. | 89 // Adds an |observer| of the PropertyChanged signal. |
| 77 void AddPropertyChangedObserver(ShillPropertyChangedObserver* observer); | 90 void AddPropertyChangedObserver(ShillPropertyChangedObserver* observer); |
| 78 | 91 |
| 79 // Removes an |observer| of the PropertyChanged signal. | 92 // Removes an |observer| of the PropertyChanged signal. |
| 80 void RemovePropertyChangedObserver(ShillPropertyChangedObserver* observer); | 93 void RemovePropertyChangedObserver(ShillPropertyChangedObserver* observer); |
| 81 | 94 |
| 82 // Starts monitoring PropertyChanged signal. If there aren't observers for the | 95 // Starts monitoring PropertyChanged signal. If there aren't observers for the |
| 83 // PropertyChanged signal, the actual monitoring will be delayed until the | 96 // PropertyChanged signal, the actual monitoring will be delayed until the |
| 84 // first observer is added. | 97 // first observer is added. |
| 85 void MonitorPropertyChanged(const std::string& interface_name); | 98 void MonitorPropertyChanged(const std::string& interface_name); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 dbus::MethodCall* method_call, | 137 dbus::MethodCall* method_call, |
| 125 const DictionaryValueCallbackWithoutStatus& callback, | 138 const DictionaryValueCallbackWithoutStatus& callback, |
| 126 const ErrorCallback& error_callback); | 139 const ErrorCallback& error_callback); |
| 127 | 140 |
| 128 // Calls a method with a boolean array result with error callback. | 141 // Calls a method with a boolean array result with error callback. |
| 129 void CallListValueMethodWithErrorCallback( | 142 void CallListValueMethodWithErrorCallback( |
| 130 dbus::MethodCall* method_call, | 143 dbus::MethodCall* method_call, |
| 131 const ListValueCallback& callback, | 144 const ListValueCallback& callback, |
| 132 const ErrorCallback& error_callback); | 145 const ErrorCallback& error_callback); |
| 133 | 146 |
| 147 // Reference / Ownership management. If the number of active refs (observers | |
| 148 // + in-progress method calls) becomes 0, |owner_| (if set) will be notified. | |
| 149 void AddRef(); | |
| 150 void Release(); | |
|
hashimoto
2013/09/17 03:28:53
nit: How about making these methods private by mak
stevenjb
2013/09/17 21:03:17
Done.
| |
| 151 | |
| 152 const dbus::ObjectProxy* object_proxy() const { return proxy_; } | |
| 153 | |
| 134 // Appends the value (basic types and string-to-string dictionary) to the | 154 // Appends the value (basic types and string-to-string dictionary) to the |
| 135 // writer as a variant. | 155 // writer as a variant. |
| 136 static void AppendValueDataAsVariant(dbus::MessageWriter* writer, | 156 static void AppendValueDataAsVariant(dbus::MessageWriter* writer, |
| 137 const base::Value& value); | 157 const base::Value& value); |
| 138 | 158 |
| 139 // Appends a string-to-variant dictionary to the writer. | 159 // Appends a string-to-variant dictionary to the writer. |
| 140 static void AppendServicePropertiesDictionary( | 160 static void AppendServicePropertiesDictionary( |
| 141 dbus::MessageWriter* writer, | 161 dbus::MessageWriter* writer, |
| 142 const base::DictionaryValue& dictionary); | 162 const base::DictionaryValue& dictionary); |
| 143 | 163 |
| 144 private: | 164 private: |
| 145 // Starts monitoring PropertyChanged signal. | 165 // Starts monitoring PropertyChanged signal. |
| 146 void MonitorPropertyChangedInternal(const std::string& interface_name); | 166 void MonitorPropertyChangedInternal(const std::string& interface_name); |
| 147 | 167 |
| 148 // Handles the result of signal connection setup. | 168 // Handles the result of signal connection setup. |
| 149 void OnSignalConnected(const std::string& interface, | 169 void OnSignalConnected(const std::string& interface, |
| 150 const std::string& signal, | 170 const std::string& signal, |
| 151 bool success); | 171 bool success); |
| 152 | 172 |
| 153 // Handles PropertyChanged signal. | 173 // Handles PropertyChanged signal. |
| 154 void OnPropertyChanged(dbus::Signal* signal); | 174 void OnPropertyChanged(dbus::Signal* signal); |
| 155 | 175 |
| 156 dbus::ObjectProxy* proxy_; | 176 dbus::ObjectProxy* proxy_; |
| 177 Owner* owner_; | |
| 178 int active_refs_; | |
| 157 PropertyChangedHandler property_changed_handler_; | 179 PropertyChangedHandler property_changed_handler_; |
| 158 ObserverList<ShillPropertyChangedObserver, true /* check_empty */> | 180 ObserverList<ShillPropertyChangedObserver, true /* check_empty */> |
| 159 observer_list_; | 181 observer_list_; |
| 160 std::vector<std::string> interfaces_to_be_monitored_; | 182 std::vector<std::string> interfaces_to_be_monitored_; |
| 161 | 183 |
| 162 // Note: This should remain the last member so it'll be destroyed and | 184 // Note: This should remain the last member so it'll be destroyed and |
| 163 // invalidate its weak pointers before any other members are destroyed. | 185 // invalidate its weak pointers before any other members are destroyed. |
| 164 base::WeakPtrFactory<ShillClientHelper> weak_ptr_factory_; | 186 base::WeakPtrFactory<ShillClientHelper> weak_ptr_factory_; |
| 165 | 187 |
| 166 DISALLOW_COPY_AND_ASSIGN(ShillClientHelper); | 188 DISALLOW_COPY_AND_ASSIGN(ShillClientHelper); |
| 167 }; | 189 }; |
| 168 | 190 |
| 169 } // namespace chromeos | 191 } // namespace chromeos |
| 170 | 192 |
| 171 #endif // CHROMEOS_DBUS_SHILL_CLIENT_HELPER_H_ | 193 #endif // CHROMEOS_DBUS_SHILL_CLIENT_HELPER_H_ |
| OLD | NEW |