Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1 | // Copyright 2014 The Chromium OS 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 | #include "chromeos-dbus-bindings/proxy_generator.h" |
| 6 | |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 10 | #include <base/files/file_path.h> |
Alex Vakulenko | f3c6897 | 2014-12-10 12:52:31 -0800 | [diff] [blame] | 11 | #include <base/files/file_util.h> |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 12 | #include <base/files/scoped_temp_dir.h> |
| 13 | #include <gtest/gtest.h> |
| 14 | |
| 15 | #include "chromeos-dbus-bindings/interface.h" |
Alex Deymo | f211ae6 | 2015-07-28 13:09:29 -0700 | [diff] [blame] | 16 | #include "chromeos-dbus-bindings/test_utils.h" |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 17 | |
| 18 | using std::string; |
| 19 | using std::vector; |
| 20 | using testing::Test; |
| 21 | |
| 22 | namespace chromeos_dbus_bindings { |
| 23 | |
| 24 | namespace { |
| 25 | |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 26 | const char kDBusTypeArryOfObjects[] = "ao"; |
| 27 | const char kDBusTypeArryOfStrings[] = "as"; |
| 28 | const char kDBusTypeBool[] = "b"; |
| 29 | const char kDBusTypeByte[] = "y"; |
| 30 | const char kDBusTypeInt32[] = "i"; |
| 31 | const char kDBusTypeInt64[] = "x"; |
| 32 | const char kDBusTypeString[] = "s"; |
| 33 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 34 | const char kExpectedContent[] = R"literal_string( |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 35 | #include <memory> |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 36 | #include <string> |
| 37 | #include <vector> |
| 38 | |
| 39 | #include <base/bind.h> |
| 40 | #include <base/callback.h> |
| 41 | #include <base/logging.h> |
| 42 | #include <base/macros.h> |
| 43 | #include <base/memory/ref_counted.h> |
| 44 | #include <chromeos/any.h> |
| 45 | #include <chromeos/dbus/dbus_method_invoker.h> |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 46 | #include <chromeos/dbus/dbus_property.h> |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 47 | #include <chromeos/dbus/dbus_signal_handler.h> |
| 48 | #include <chromeos/errors/error.h> |
Alex Vakulenko | 4f3c05e | 2014-11-12 15:01:46 -0800 | [diff] [blame] | 49 | #include <chromeos/variant_dictionary.h> |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 50 | #include <dbus/bus.h> |
| 51 | #include <dbus/message.h> |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 52 | #include <dbus/object_manager.h> |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 53 | #include <dbus/object_path.h> |
| 54 | #include <dbus/object_proxy.h> |
| 55 | |
| 56 | namespace org { |
| 57 | namespace chromium { |
| 58 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 59 | // Abstract interface proxy for org::chromium::TestInterface. |
| 60 | class TestInterfaceProxyInterface { |
| 61 | public: |
| 62 | virtual bool Elements( |
| 63 | const std::string& in_space_walk, |
| 64 | const std::vector<dbus::ObjectPath>& in_ramblin_man, |
| 65 | std::string* out_3, |
| 66 | chromeos::ErrorPtr* error, |
| 67 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0; |
| 68 | |
| 69 | virtual void ElementsAsync( |
| 70 | const std::string& in_space_walk, |
| 71 | const std::vector<dbus::ObjectPath>& in_ramblin_man, |
| 72 | const base::Callback<void(const std::string&)>& success_callback, |
| 73 | const base::Callback<void(chromeos::Error*)>& error_callback, |
| 74 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0; |
| 75 | |
| 76 | virtual bool ReturnToPatagonia( |
| 77 | int64_t* out_1, |
| 78 | chromeos::ErrorPtr* error, |
| 79 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0; |
| 80 | |
| 81 | virtual void ReturnToPatagoniaAsync( |
| 82 | const base::Callback<void(int64_t)>& success_callback, |
| 83 | const base::Callback<void(chromeos::Error*)>& error_callback, |
| 84 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0; |
| 85 | |
| 86 | virtual bool NiceWeatherForDucks( |
| 87 | bool in_1, |
| 88 | chromeos::ErrorPtr* error, |
| 89 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0; |
| 90 | |
| 91 | virtual void NiceWeatherForDucksAsync( |
| 92 | bool in_1, |
| 93 | const base::Callback<void()>& success_callback, |
| 94 | const base::Callback<void(chromeos::Error*)>& error_callback, |
| 95 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0; |
| 96 | |
| 97 | // Comment line1 |
| 98 | // line2 |
| 99 | virtual bool ExperimentNumberSix( |
| 100 | chromeos::ErrorPtr* error, |
| 101 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0; |
| 102 | |
| 103 | // Comment line1 |
| 104 | // line2 |
| 105 | virtual void ExperimentNumberSixAsync( |
| 106 | const base::Callback<void()>& success_callback, |
| 107 | const base::Callback<void(chromeos::Error*)>& error_callback, |
| 108 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0; |
| 109 | |
Alex Deymo | ce286b9 | 2015-07-28 15:04:07 -0700 | [diff] [blame^] | 110 | virtual void RegisterCloserSignalHandler( |
| 111 | const base::Closure& signal_callback, |
| 112 | dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0; |
| 113 | |
| 114 | virtual void RegisterTheCurseOfKaZarSignalHandler( |
| 115 | const base::Callback<void(const std::vector<std::string>&, |
| 116 | uint8_t)>& signal_callback, |
| 117 | dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0; |
| 118 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 119 | protected: |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 120 | virtual ~TestInterfaceProxyInterface() = default; |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | } // namespace chromium |
| 124 | } // namespace org |
| 125 | |
| 126 | namespace org { |
| 127 | namespace chromium { |
| 128 | |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 129 | // Interface proxy for org::chromium::TestInterface. |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 130 | class TestInterfaceProxy final : public TestInterfaceProxyInterface { |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 131 | public: |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 132 | TestInterfaceProxy( |
| 133 | const scoped_refptr<dbus::Bus>& bus, |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 134 | const std::string& service_name) : |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 135 | bus_{bus}, |
| 136 | service_name_{service_name}, |
| 137 | dbus_object_proxy_{ |
| 138 | bus_->GetObjectProxy(service_name_, object_path_)} { |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 141 | ~TestInterfaceProxy() override { |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | void RegisterCloserSignalHandler( |
| 145 | const base::Closure& signal_callback, |
Alex Deymo | ce286b9 | 2015-07-28 15:04:07 -0700 | [diff] [blame^] | 146 | dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override { |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 147 | chromeos::dbus_utils::ConnectToSignal( |
| 148 | dbus_object_proxy_, |
| 149 | "org.chromium.TestInterface", |
| 150 | "Closer", |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 151 | signal_callback, |
| 152 | on_connected_callback); |
| 153 | } |
| 154 | |
| 155 | void RegisterTheCurseOfKaZarSignalHandler( |
| 156 | const base::Callback<void(const std::vector<std::string>&, |
| 157 | uint8_t)>& signal_callback, |
Alex Deymo | ce286b9 | 2015-07-28 15:04:07 -0700 | [diff] [blame^] | 158 | dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override { |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 159 | chromeos::dbus_utils::ConnectToSignal( |
| 160 | dbus_object_proxy_, |
| 161 | "org.chromium.TestInterface", |
| 162 | "TheCurseOfKaZar", |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 163 | signal_callback, |
| 164 | on_connected_callback); |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void ReleaseObjectProxy(const base::Closure& callback) { |
| 168 | bus_->RemoveObjectProxy(service_name_, object_path_, callback); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 169 | } |
Alex Vakulenko | 4f3c05e | 2014-11-12 15:01:46 -0800 | [diff] [blame] | 170 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 171 | const dbus::ObjectPath& GetObjectPath() const { |
| 172 | return object_path_; |
| 173 | } |
| 174 | |
| 175 | dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; } |
| 176 | |
Alex Vakulenko | 4f3c05e | 2014-11-12 15:01:46 -0800 | [diff] [blame] | 177 | bool Elements( |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 178 | const std::string& in_space_walk, |
| 179 | const std::vector<dbus::ObjectPath>& in_ramblin_man, |
| 180 | std::string* out_3, |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 181 | chromeos::ErrorPtr* error, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 182 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override { |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 183 | auto response = chromeos::dbus_utils::CallMethodAndBlockWithTimeout( |
| 184 | timeout_ms, |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 185 | dbus_object_proxy_, |
| 186 | "org.chromium.TestInterface", |
| 187 | "Elements", |
| 188 | error, |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 189 | in_space_walk, |
| 190 | in_ramblin_man); |
| 191 | return response && chromeos::dbus_utils::ExtractMethodCallResults( |
| 192 | response.get(), error, out_3); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 193 | } |
Alex Vakulenko | 4f3c05e | 2014-11-12 15:01:46 -0800 | [diff] [blame] | 194 | |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 195 | void ElementsAsync( |
| 196 | const std::string& in_space_walk, |
| 197 | const std::vector<dbus::ObjectPath>& in_ramblin_man, |
| 198 | const base::Callback<void(const std::string&)>& success_callback, |
| 199 | const base::Callback<void(chromeos::Error*)>& error_callback, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 200 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override { |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 201 | chromeos::dbus_utils::CallMethodWithTimeout( |
| 202 | timeout_ms, |
| 203 | dbus_object_proxy_, |
| 204 | "org.chromium.TestInterface", |
| 205 | "Elements", |
| 206 | success_callback, |
| 207 | error_callback, |
| 208 | in_space_walk, |
| 209 | in_ramblin_man); |
| 210 | } |
| 211 | |
Alex Vakulenko | 4f3c05e | 2014-11-12 15:01:46 -0800 | [diff] [blame] | 212 | bool ReturnToPatagonia( |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 213 | int64_t* out_1, |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 214 | chromeos::ErrorPtr* error, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 215 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override { |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 216 | auto response = chromeos::dbus_utils::CallMethodAndBlockWithTimeout( |
| 217 | timeout_ms, |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 218 | dbus_object_proxy_, |
| 219 | "org.chromium.TestInterface", |
| 220 | "ReturnToPatagonia", |
| 221 | error); |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 222 | return response && chromeos::dbus_utils::ExtractMethodCallResults( |
| 223 | response.get(), error, out_1); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 224 | } |
Alex Vakulenko | 4f3c05e | 2014-11-12 15:01:46 -0800 | [diff] [blame] | 225 | |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 226 | void ReturnToPatagoniaAsync( |
| 227 | const base::Callback<void(int64_t)>& success_callback, |
| 228 | const base::Callback<void(chromeos::Error*)>& error_callback, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 229 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override { |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 230 | chromeos::dbus_utils::CallMethodWithTimeout( |
| 231 | timeout_ms, |
| 232 | dbus_object_proxy_, |
| 233 | "org.chromium.TestInterface", |
| 234 | "ReturnToPatagonia", |
| 235 | success_callback, |
| 236 | error_callback); |
| 237 | } |
| 238 | |
Alex Vakulenko | 4f3c05e | 2014-11-12 15:01:46 -0800 | [diff] [blame] | 239 | bool NiceWeatherForDucks( |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 240 | bool in_1, |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 241 | chromeos::ErrorPtr* error, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 242 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override { |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 243 | auto response = chromeos::dbus_utils::CallMethodAndBlockWithTimeout( |
| 244 | timeout_ms, |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 245 | dbus_object_proxy_, |
| 246 | "org.chromium.TestInterface", |
| 247 | "NiceWeatherForDucks", |
| 248 | error, |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 249 | in_1); |
| 250 | return response && chromeos::dbus_utils::ExtractMethodCallResults( |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 251 | response.get(), error); |
| 252 | } |
Alex Vakulenko | 4f3c05e | 2014-11-12 15:01:46 -0800 | [diff] [blame] | 253 | |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 254 | void NiceWeatherForDucksAsync( |
| 255 | bool in_1, |
| 256 | const base::Callback<void()>& success_callback, |
| 257 | const base::Callback<void(chromeos::Error*)>& error_callback, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 258 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override { |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 259 | chromeos::dbus_utils::CallMethodWithTimeout( |
| 260 | timeout_ms, |
| 261 | dbus_object_proxy_, |
| 262 | "org.chromium.TestInterface", |
| 263 | "NiceWeatherForDucks", |
| 264 | success_callback, |
| 265 | error_callback, |
| 266 | in_1); |
| 267 | } |
| 268 | |
Alex Vakulenko | 4f3c05e | 2014-11-12 15:01:46 -0800 | [diff] [blame] | 269 | // Comment line1 |
| 270 | // line2 |
| 271 | bool ExperimentNumberSix( |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 272 | chromeos::ErrorPtr* error, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 273 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override { |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 274 | auto response = chromeos::dbus_utils::CallMethodAndBlockWithTimeout( |
| 275 | timeout_ms, |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 276 | dbus_object_proxy_, |
| 277 | "org.chromium.TestInterface", |
| 278 | "ExperimentNumberSix", |
| 279 | error); |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 280 | return response && chromeos::dbus_utils::ExtractMethodCallResults( |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 281 | response.get(), error); |
| 282 | } |
Alex Vakulenko | 4f3c05e | 2014-11-12 15:01:46 -0800 | [diff] [blame] | 283 | |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 284 | // Comment line1 |
| 285 | // line2 |
| 286 | void ExperimentNumberSixAsync( |
| 287 | const base::Callback<void()>& success_callback, |
| 288 | const base::Callback<void(chromeos::Error*)>& error_callback, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 289 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override { |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 290 | chromeos::dbus_utils::CallMethodWithTimeout( |
| 291 | timeout_ms, |
| 292 | dbus_object_proxy_, |
| 293 | "org.chromium.TestInterface", |
| 294 | "ExperimentNumberSix", |
| 295 | success_callback, |
| 296 | error_callback); |
| 297 | } |
| 298 | |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 299 | private: |
| 300 | scoped_refptr<dbus::Bus> bus_; |
| 301 | std::string service_name_; |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 302 | const dbus::ObjectPath object_path_{"/org/chromium/Test"}; |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 303 | dbus::ObjectProxy* dbus_object_proxy_; |
| 304 | |
| 305 | DISALLOW_COPY_AND_ASSIGN(TestInterfaceProxy); |
| 306 | }; |
| 307 | |
| 308 | } // namespace chromium |
| 309 | } // namespace org |
| 310 | |
| 311 | namespace org { |
| 312 | namespace chromium { |
| 313 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 314 | // Abstract interface proxy for org::chromium::TestInterface2. |
| 315 | class TestInterface2ProxyInterface { |
| 316 | public: |
| 317 | virtual bool GetPersonInfo( |
| 318 | std::string* out_name, |
| 319 | int32_t* out_age, |
| 320 | chromeos::ErrorPtr* error, |
| 321 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0; |
| 322 | |
| 323 | virtual void GetPersonInfoAsync( |
| 324 | const base::Callback<void(const std::string& /*name*/, int32_t /*age*/)>& success_callback, |
| 325 | const base::Callback<void(chromeos::Error*)>& error_callback, |
| 326 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0; |
| 327 | |
| 328 | protected: |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 329 | virtual ~TestInterface2ProxyInterface() = default; |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 330 | }; |
| 331 | |
| 332 | } // namespace chromium |
| 333 | } // namespace org |
| 334 | |
| 335 | namespace org { |
| 336 | namespace chromium { |
| 337 | |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 338 | // Interface proxy for org::chromium::TestInterface2. |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 339 | class TestInterface2Proxy final : public TestInterface2ProxyInterface { |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 340 | public: |
| 341 | TestInterface2Proxy( |
| 342 | const scoped_refptr<dbus::Bus>& bus, |
| 343 | const std::string& service_name, |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 344 | const dbus::ObjectPath& object_path) : |
| 345 | bus_{bus}, |
| 346 | service_name_{service_name}, |
| 347 | object_path_{object_path}, |
| 348 | dbus_object_proxy_{ |
| 349 | bus_->GetObjectProxy(service_name_, object_path_)} { |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 352 | ~TestInterface2Proxy() override { |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void ReleaseObjectProxy(const base::Closure& callback) { |
| 356 | bus_->RemoveObjectProxy(service_name_, object_path_, callback); |
| 357 | } |
| 358 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 359 | const dbus::ObjectPath& GetObjectPath() const { |
| 360 | return object_path_; |
| 361 | } |
| 362 | |
| 363 | dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; } |
| 364 | |
Alex Vakulenko | 4f3c05e | 2014-11-12 15:01:46 -0800 | [diff] [blame] | 365 | bool GetPersonInfo( |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 366 | std::string* out_name, |
| 367 | int32_t* out_age, |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 368 | chromeos::ErrorPtr* error, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 369 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override { |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 370 | auto response = chromeos::dbus_utils::CallMethodAndBlockWithTimeout( |
| 371 | timeout_ms, |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 372 | dbus_object_proxy_, |
| 373 | "org.chromium.TestInterface2", |
| 374 | "GetPersonInfo", |
| 375 | error); |
| 376 | return response && chromeos::dbus_utils::ExtractMethodCallResults( |
| 377 | response.get(), error, out_name, out_age); |
| 378 | } |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 379 | |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 380 | void GetPersonInfoAsync( |
| 381 | const base::Callback<void(const std::string& /*name*/, int32_t /*age*/)>& success_callback, |
| 382 | const base::Callback<void(chromeos::Error*)>& error_callback, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 383 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override { |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 384 | chromeos::dbus_utils::CallMethodWithTimeout( |
| 385 | timeout_ms, |
| 386 | dbus_object_proxy_, |
| 387 | "org.chromium.TestInterface2", |
| 388 | "GetPersonInfo", |
| 389 | success_callback, |
| 390 | error_callback); |
| 391 | } |
| 392 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 393 | private: |
| 394 | scoped_refptr<dbus::Bus> bus_; |
| 395 | std::string service_name_; |
| 396 | dbus::ObjectPath object_path_; |
| 397 | dbus::ObjectProxy* dbus_object_proxy_; |
| 398 | |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 399 | DISALLOW_COPY_AND_ASSIGN(TestInterface2Proxy); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 400 | }; |
| 401 | |
| 402 | } // namespace chromium |
| 403 | } // namespace org |
| 404 | )literal_string"; |
| 405 | |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 406 | const char kExpectedContentWithService[] = R"literal_string( |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 407 | #include <memory> |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 408 | #include <string> |
| 409 | #include <vector> |
| 410 | |
| 411 | #include <base/bind.h> |
| 412 | #include <base/callback.h> |
| 413 | #include <base/logging.h> |
| 414 | #include <base/macros.h> |
| 415 | #include <base/memory/ref_counted.h> |
| 416 | #include <chromeos/any.h> |
| 417 | #include <chromeos/dbus/dbus_method_invoker.h> |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 418 | #include <chromeos/dbus/dbus_property.h> |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 419 | #include <chromeos/dbus/dbus_signal_handler.h> |
| 420 | #include <chromeos/errors/error.h> |
| 421 | #include <chromeos/variant_dictionary.h> |
| 422 | #include <dbus/bus.h> |
| 423 | #include <dbus/message.h> |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 424 | #include <dbus/object_manager.h> |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 425 | #include <dbus/object_path.h> |
| 426 | #include <dbus/object_proxy.h> |
| 427 | |
| 428 | namespace org { |
| 429 | namespace chromium { |
| 430 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 431 | // Abstract interface proxy for org::chromium::TestInterface. |
| 432 | class TestInterfaceProxyInterface { |
| 433 | public: |
Alex Deymo | ce286b9 | 2015-07-28 15:04:07 -0700 | [diff] [blame^] | 434 | virtual void RegisterCloserSignalHandler( |
| 435 | const base::Closure& signal_callback, |
| 436 | dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0; |
| 437 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 438 | protected: |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 439 | virtual ~TestInterfaceProxyInterface() = default; |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 440 | }; |
| 441 | |
| 442 | } // namespace chromium |
| 443 | } // namespace org |
| 444 | |
| 445 | namespace org { |
| 446 | namespace chromium { |
| 447 | |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 448 | // Interface proxy for org::chromium::TestInterface. |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 449 | class TestInterfaceProxy final : public TestInterfaceProxyInterface { |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 450 | public: |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 451 | TestInterfaceProxy(const scoped_refptr<dbus::Bus>& bus) : |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 452 | bus_{bus}, |
| 453 | dbus_object_proxy_{ |
| 454 | bus_->GetObjectProxy(service_name_, object_path_)} { |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 455 | } |
| 456 | |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 457 | ~TestInterfaceProxy() override { |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | void RegisterCloserSignalHandler( |
| 461 | const base::Closure& signal_callback, |
Alex Deymo | ce286b9 | 2015-07-28 15:04:07 -0700 | [diff] [blame^] | 462 | dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override { |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 463 | chromeos::dbus_utils::ConnectToSignal( |
| 464 | dbus_object_proxy_, |
| 465 | "org.chromium.TestInterface", |
| 466 | "Closer", |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 467 | signal_callback, |
| 468 | on_connected_callback); |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | void ReleaseObjectProxy(const base::Closure& callback) { |
| 472 | bus_->RemoveObjectProxy(service_name_, object_path_, callback); |
| 473 | } |
| 474 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 475 | const dbus::ObjectPath& GetObjectPath() const { |
| 476 | return object_path_; |
| 477 | } |
| 478 | |
| 479 | dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; } |
| 480 | |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 481 | private: |
| 482 | scoped_refptr<dbus::Bus> bus_; |
| 483 | const std::string service_name_{"org.chromium.Test"}; |
| 484 | const dbus::ObjectPath object_path_{"/org/chromium/Test"}; |
| 485 | dbus::ObjectProxy* dbus_object_proxy_; |
| 486 | |
| 487 | DISALLOW_COPY_AND_ASSIGN(TestInterfaceProxy); |
| 488 | }; |
| 489 | |
| 490 | } // namespace chromium |
| 491 | } // namespace org |
| 492 | |
| 493 | namespace org { |
| 494 | namespace chromium { |
| 495 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 496 | // Abstract interface proxy for org::chromium::TestInterface2. |
| 497 | class TestInterface2ProxyInterface { |
| 498 | public: |
| 499 | protected: |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 500 | virtual ~TestInterface2ProxyInterface() = default; |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 501 | }; |
| 502 | |
| 503 | } // namespace chromium |
| 504 | } // namespace org |
| 505 | |
| 506 | namespace org { |
| 507 | namespace chromium { |
| 508 | |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 509 | // Interface proxy for org::chromium::TestInterface2. |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 510 | class TestInterface2Proxy final : public TestInterface2ProxyInterface { |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 511 | public: |
| 512 | TestInterface2Proxy( |
| 513 | const scoped_refptr<dbus::Bus>& bus, |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 514 | const dbus::ObjectPath& object_path) : |
| 515 | bus_{bus}, |
| 516 | object_path_{object_path}, |
| 517 | dbus_object_proxy_{ |
| 518 | bus_->GetObjectProxy(service_name_, object_path_)} { |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 521 | ~TestInterface2Proxy() override { |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | void ReleaseObjectProxy(const base::Closure& callback) { |
| 525 | bus_->RemoveObjectProxy(service_name_, object_path_, callback); |
| 526 | } |
| 527 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 528 | const dbus::ObjectPath& GetObjectPath() const { |
| 529 | return object_path_; |
| 530 | } |
| 531 | |
| 532 | dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; } |
| 533 | |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 534 | private: |
| 535 | scoped_refptr<dbus::Bus> bus_; |
| 536 | const std::string service_name_{"org.chromium.Test"}; |
| 537 | dbus::ObjectPath object_path_; |
| 538 | dbus::ObjectProxy* dbus_object_proxy_; |
| 539 | |
| 540 | DISALLOW_COPY_AND_ASSIGN(TestInterface2Proxy); |
| 541 | }; |
| 542 | |
| 543 | } // namespace chromium |
| 544 | } // namespace org |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 545 | )literal_string"; |
| 546 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 547 | const char kExpectedContentWithObjectManager[] = R"literal_string( |
| 548 | #include <memory> |
| 549 | #include <string> |
| 550 | #include <vector> |
| 551 | |
| 552 | #include <base/bind.h> |
| 553 | #include <base/callback.h> |
| 554 | #include <base/logging.h> |
| 555 | #include <base/macros.h> |
| 556 | #include <base/memory/ref_counted.h> |
| 557 | #include <chromeos/any.h> |
| 558 | #include <chromeos/dbus/dbus_method_invoker.h> |
| 559 | #include <chromeos/dbus/dbus_property.h> |
| 560 | #include <chromeos/dbus/dbus_signal_handler.h> |
| 561 | #include <chromeos/errors/error.h> |
| 562 | #include <chromeos/variant_dictionary.h> |
| 563 | #include <dbus/bus.h> |
| 564 | #include <dbus/message.h> |
| 565 | #include <dbus/object_manager.h> |
| 566 | #include <dbus/object_path.h> |
| 567 | #include <dbus/object_proxy.h> |
| 568 | |
| 569 | namespace org { |
| 570 | namespace chromium { |
| 571 | class ObjectManagerProxy; |
| 572 | } // namespace chromium |
| 573 | } // namespace org |
| 574 | |
| 575 | namespace org { |
| 576 | namespace chromium { |
| 577 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 578 | // Abstract interface proxy for org::chromium::Itf1. |
| 579 | class Itf1ProxyInterface { |
| 580 | public: |
Alex Deymo | ce286b9 | 2015-07-28 15:04:07 -0700 | [diff] [blame^] | 581 | virtual void RegisterCloserSignalHandler( |
| 582 | const base::Closure& signal_callback, |
| 583 | dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0; |
| 584 | |
Alex Vakulenko | 59dd2e9 | 2015-02-23 15:14:28 -0800 | [diff] [blame] | 585 | static const char* DataName() { return "Data"; } |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 586 | virtual const std::string& data() const = 0; |
| 587 | |
| 588 | protected: |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 589 | virtual ~Itf1ProxyInterface() = default; |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 590 | }; |
| 591 | |
| 592 | } // namespace chromium |
| 593 | } // namespace org |
| 594 | |
| 595 | namespace org { |
| 596 | namespace chromium { |
| 597 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 598 | // Interface proxy for org::chromium::Itf1. |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 599 | class Itf1Proxy final : public Itf1ProxyInterface { |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 600 | public: |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 601 | class PropertySet : public dbus::PropertySet { |
| 602 | public: |
| 603 | PropertySet(dbus::ObjectProxy* object_proxy, |
| 604 | const PropertyChangedCallback& callback) |
| 605 | : dbus::PropertySet{object_proxy, |
| 606 | "org.chromium.Itf1", |
| 607 | callback} { |
Alex Vakulenko | 59dd2e9 | 2015-02-23 15:14:28 -0800 | [diff] [blame] | 608 | RegisterProperty(DataName(), &data); |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | chromeos::dbus_utils::Property<std::string> data; |
| 612 | |
| 613 | private: |
| 614 | DISALLOW_COPY_AND_ASSIGN(PropertySet); |
| 615 | }; |
| 616 | |
| 617 | Itf1Proxy( |
| 618 | const scoped_refptr<dbus::Bus>& bus, |
| 619 | const std::string& service_name, |
| 620 | PropertySet* property_set) : |
| 621 | bus_{bus}, |
| 622 | service_name_{service_name}, |
| 623 | property_set_{property_set}, |
| 624 | dbus_object_proxy_{ |
| 625 | bus_->GetObjectProxy(service_name_, object_path_)} { |
| 626 | } |
| 627 | |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 628 | ~Itf1Proxy() override { |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | void RegisterCloserSignalHandler( |
| 632 | const base::Closure& signal_callback, |
Alex Deymo | ce286b9 | 2015-07-28 15:04:07 -0700 | [diff] [blame^] | 633 | dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override { |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 634 | chromeos::dbus_utils::ConnectToSignal( |
| 635 | dbus_object_proxy_, |
| 636 | "org.chromium.Itf1", |
| 637 | "Closer", |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 638 | signal_callback, |
| 639 | on_connected_callback); |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | void ReleaseObjectProxy(const base::Closure& callback) { |
| 643 | bus_->RemoveObjectProxy(service_name_, object_path_, callback); |
| 644 | } |
| 645 | |
| 646 | const dbus::ObjectPath& GetObjectPath() const { |
| 647 | return object_path_; |
| 648 | } |
| 649 | |
| 650 | dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; } |
| 651 | |
| 652 | void SetPropertyChangedCallback( |
| 653 | const base::Callback<void(Itf1Proxy*, const std::string&)>& callback) { |
| 654 | on_property_changed_ = callback; |
| 655 | } |
| 656 | |
| 657 | const PropertySet* GetProperties() const { return property_set_; } |
| 658 | PropertySet* GetProperties() { return property_set_; } |
| 659 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 660 | const std::string& data() const override { |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 661 | return property_set_->data.value(); |
| 662 | } |
| 663 | |
| 664 | private: |
| 665 | void OnPropertyChanged(const std::string& property_name) { |
| 666 | if (!on_property_changed_.is_null()) |
| 667 | on_property_changed_.Run(this, property_name); |
| 668 | } |
| 669 | |
| 670 | scoped_refptr<dbus::Bus> bus_; |
| 671 | std::string service_name_; |
| 672 | const dbus::ObjectPath object_path_{"/org/chromium/Test/Object"}; |
| 673 | PropertySet* property_set_; |
| 674 | base::Callback<void(Itf1Proxy*, const std::string&)> on_property_changed_; |
| 675 | dbus::ObjectProxy* dbus_object_proxy_; |
| 676 | |
| 677 | friend class org::chromium::ObjectManagerProxy; |
| 678 | DISALLOW_COPY_AND_ASSIGN(Itf1Proxy); |
| 679 | }; |
| 680 | |
| 681 | } // namespace chromium |
| 682 | } // namespace org |
| 683 | |
| 684 | namespace org { |
| 685 | namespace chromium { |
| 686 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 687 | // Abstract interface proxy for org::chromium::Itf2. |
| 688 | class Itf2ProxyInterface { |
| 689 | public: |
| 690 | protected: |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 691 | virtual ~Itf2ProxyInterface() = default; |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 692 | }; |
| 693 | |
| 694 | } // namespace chromium |
| 695 | } // namespace org |
| 696 | |
| 697 | namespace org { |
| 698 | namespace chromium { |
| 699 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 700 | // Interface proxy for org::chromium::Itf2. |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 701 | class Itf2Proxy final : public Itf2ProxyInterface { |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 702 | public: |
| 703 | class PropertySet : public dbus::PropertySet { |
| 704 | public: |
| 705 | PropertySet(dbus::ObjectProxy* object_proxy, |
| 706 | const PropertyChangedCallback& callback) |
| 707 | : dbus::PropertySet{object_proxy, |
| 708 | "org.chromium.Itf2", |
| 709 | callback} { |
| 710 | } |
| 711 | |
| 712 | |
| 713 | private: |
| 714 | DISALLOW_COPY_AND_ASSIGN(PropertySet); |
| 715 | }; |
| 716 | |
| 717 | Itf2Proxy( |
| 718 | const scoped_refptr<dbus::Bus>& bus, |
| 719 | const std::string& service_name, |
| 720 | const dbus::ObjectPath& object_path) : |
| 721 | bus_{bus}, |
| 722 | service_name_{service_name}, |
| 723 | object_path_{object_path}, |
| 724 | dbus_object_proxy_{ |
| 725 | bus_->GetObjectProxy(service_name_, object_path_)} { |
| 726 | } |
| 727 | |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 728 | ~Itf2Proxy() override { |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | void ReleaseObjectProxy(const base::Closure& callback) { |
| 732 | bus_->RemoveObjectProxy(service_name_, object_path_, callback); |
| 733 | } |
| 734 | |
| 735 | const dbus::ObjectPath& GetObjectPath() const { |
| 736 | return object_path_; |
| 737 | } |
| 738 | |
| 739 | dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; } |
| 740 | |
| 741 | private: |
| 742 | scoped_refptr<dbus::Bus> bus_; |
| 743 | std::string service_name_; |
| 744 | dbus::ObjectPath object_path_; |
| 745 | dbus::ObjectProxy* dbus_object_proxy_; |
| 746 | |
| 747 | DISALLOW_COPY_AND_ASSIGN(Itf2Proxy); |
| 748 | }; |
| 749 | |
| 750 | } // namespace chromium |
| 751 | } // namespace org |
| 752 | |
| 753 | namespace org { |
| 754 | namespace chromium { |
| 755 | |
| 756 | class ObjectManagerProxy : public dbus::ObjectManager::Interface { |
| 757 | public: |
| 758 | ObjectManagerProxy(const scoped_refptr<dbus::Bus>& bus, |
| 759 | const std::string& service_name) |
| 760 | : bus_{bus}, |
Christopher Wiley | efe9df5 | 2015-03-12 16:02:22 -0700 | [diff] [blame] | 761 | service_name_{service_name}, |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 762 | dbus_object_manager_{bus->GetObjectManager( |
| 763 | service_name, |
| 764 | dbus::ObjectPath{"/org/chromium/Test"})} { |
| 765 | dbus_object_manager_->RegisterInterface("org.chromium.Itf1", this); |
| 766 | dbus_object_manager_->RegisterInterface("org.chromium.Itf2", this); |
| 767 | } |
| 768 | |
Christopher Wiley | e11e81c | 2014-12-19 13:10:52 -0800 | [diff] [blame] | 769 | ~ObjectManagerProxy() override { |
| 770 | dbus_object_manager_->UnregisterInterface("org.chromium.Itf1"); |
| 771 | dbus_object_manager_->UnregisterInterface("org.chromium.Itf2"); |
| 772 | } |
| 773 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 774 | dbus::ObjectManager* GetObjectManagerProxy() const { |
| 775 | return dbus_object_manager_; |
| 776 | } |
| 777 | |
Alex Vakulenko | c4e01f1 | 2015-02-23 15:55:21 -0800 | [diff] [blame] | 778 | org::chromium::Itf1Proxy* GetItf1Proxy() { |
| 779 | if (itf1_instances_.empty()) |
| 780 | return nullptr; |
| 781 | return itf1_instances_.begin()->second.get(); |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 782 | } |
| 783 | std::vector<org::chromium::Itf1Proxy*> GetItf1Instances() const { |
| 784 | std::vector<org::chromium::Itf1Proxy*> values; |
| 785 | values.reserve(itf1_instances_.size()); |
| 786 | for (const auto& pair : itf1_instances_) |
| 787 | values.push_back(pair.second.get()); |
| 788 | return values; |
| 789 | } |
| 790 | void SetItf1AddedCallback( |
| 791 | const base::Callback<void(org::chromium::Itf1Proxy*)>& callback) { |
| 792 | on_itf1_added_ = callback; |
| 793 | } |
| 794 | void SetItf1RemovedCallback( |
| 795 | const base::Callback<void(const dbus::ObjectPath&)>& callback) { |
| 796 | on_itf1_removed_ = callback; |
| 797 | } |
| 798 | |
| 799 | org::chromium::Itf2Proxy* GetItf2Proxy( |
| 800 | const dbus::ObjectPath& object_path) { |
| 801 | auto p = itf2_instances_.find(object_path); |
| 802 | if (p != itf2_instances_.end()) |
| 803 | return p->second.get(); |
| 804 | return nullptr; |
| 805 | } |
| 806 | std::vector<org::chromium::Itf2Proxy*> GetItf2Instances() const { |
| 807 | std::vector<org::chromium::Itf2Proxy*> values; |
| 808 | values.reserve(itf2_instances_.size()); |
| 809 | for (const auto& pair : itf2_instances_) |
| 810 | values.push_back(pair.second.get()); |
| 811 | return values; |
| 812 | } |
| 813 | void SetItf2AddedCallback( |
| 814 | const base::Callback<void(org::chromium::Itf2Proxy*)>& callback) { |
| 815 | on_itf2_added_ = callback; |
| 816 | } |
| 817 | void SetItf2RemovedCallback( |
| 818 | const base::Callback<void(const dbus::ObjectPath&)>& callback) { |
| 819 | on_itf2_removed_ = callback; |
| 820 | } |
| 821 | |
| 822 | private: |
| 823 | void OnPropertyChanged(const dbus::ObjectPath& object_path, |
| 824 | const std::string& interface_name, |
| 825 | const std::string& property_name) { |
| 826 | if (interface_name == "org.chromium.Itf1") { |
| 827 | auto p = itf1_instances_.find(object_path); |
| 828 | if (p == itf1_instances_.end()) |
| 829 | return; |
| 830 | p->second->OnPropertyChanged(property_name); |
| 831 | return; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | void ObjectAdded( |
| 836 | const dbus::ObjectPath& object_path, |
| 837 | const std::string& interface_name) override { |
| 838 | if (interface_name == "org.chromium.Itf1") { |
| 839 | auto property_set = |
| 840 | static_cast<org::chromium::Itf1Proxy::PropertySet*>( |
| 841 | dbus_object_manager_->GetProperties(object_path, interface_name)); |
| 842 | std::unique_ptr<org::chromium::Itf1Proxy> itf1_proxy{ |
Christopher Wiley | efe9df5 | 2015-03-12 16:02:22 -0700 | [diff] [blame] | 843 | new org::chromium::Itf1Proxy{bus_, service_name_, property_set} |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 844 | }; |
| 845 | auto p = itf1_instances_.emplace(object_path, std::move(itf1_proxy)); |
| 846 | if (!on_itf1_added_.is_null()) |
| 847 | on_itf1_added_.Run(p.first->second.get()); |
| 848 | return; |
| 849 | } |
| 850 | if (interface_name == "org.chromium.Itf2") { |
| 851 | std::unique_ptr<org::chromium::Itf2Proxy> itf2_proxy{ |
Christopher Wiley | efe9df5 | 2015-03-12 16:02:22 -0700 | [diff] [blame] | 852 | new org::chromium::Itf2Proxy{bus_, service_name_, object_path} |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 853 | }; |
| 854 | auto p = itf2_instances_.emplace(object_path, std::move(itf2_proxy)); |
| 855 | if (!on_itf2_added_.is_null()) |
| 856 | on_itf2_added_.Run(p.first->second.get()); |
| 857 | return; |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | void ObjectRemoved( |
| 862 | const dbus::ObjectPath& object_path, |
| 863 | const std::string& interface_name) override { |
| 864 | if (interface_name == "org.chromium.Itf1") { |
| 865 | auto p = itf1_instances_.find(object_path); |
| 866 | if (p != itf1_instances_.end()) { |
| 867 | if (!on_itf1_removed_.is_null()) |
| 868 | on_itf1_removed_.Run(object_path); |
| 869 | itf1_instances_.erase(p); |
| 870 | } |
| 871 | return; |
| 872 | } |
| 873 | if (interface_name == "org.chromium.Itf2") { |
| 874 | auto p = itf2_instances_.find(object_path); |
| 875 | if (p != itf2_instances_.end()) { |
| 876 | if (!on_itf2_removed_.is_null()) |
| 877 | on_itf2_removed_.Run(object_path); |
| 878 | itf2_instances_.erase(p); |
| 879 | } |
| 880 | return; |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | dbus::PropertySet* CreateProperties( |
| 885 | dbus::ObjectProxy* object_proxy, |
| 886 | const dbus::ObjectPath& object_path, |
| 887 | const std::string& interface_name) override { |
| 888 | if (interface_name == "org.chromium.Itf1") { |
| 889 | return new org::chromium::Itf1Proxy::PropertySet{ |
| 890 | object_proxy, |
| 891 | base::Bind(&ObjectManagerProxy::OnPropertyChanged, |
| 892 | weak_ptr_factory_.GetWeakPtr(), |
| 893 | object_path, |
| 894 | interface_name) |
| 895 | }; |
| 896 | } |
| 897 | if (interface_name == "org.chromium.Itf2") { |
| 898 | return new org::chromium::Itf2Proxy::PropertySet{ |
| 899 | object_proxy, |
| 900 | base::Bind(&ObjectManagerProxy::OnPropertyChanged, |
| 901 | weak_ptr_factory_.GetWeakPtr(), |
| 902 | object_path, |
| 903 | interface_name) |
| 904 | }; |
| 905 | } |
| 906 | LOG(FATAL) << "Creating properties for unsupported interface " |
| 907 | << interface_name; |
| 908 | return nullptr; |
| 909 | } |
| 910 | |
| 911 | scoped_refptr<dbus::Bus> bus_; |
Christopher Wiley | efe9df5 | 2015-03-12 16:02:22 -0700 | [diff] [blame] | 912 | std::string service_name_; |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 913 | dbus::ObjectManager* dbus_object_manager_; |
| 914 | std::map<dbus::ObjectPath, |
| 915 | std::unique_ptr<org::chromium::Itf1Proxy>> itf1_instances_; |
| 916 | base::Callback<void(org::chromium::Itf1Proxy*)> on_itf1_added_; |
| 917 | base::Callback<void(const dbus::ObjectPath&)> on_itf1_removed_; |
| 918 | std::map<dbus::ObjectPath, |
| 919 | std::unique_ptr<org::chromium::Itf2Proxy>> itf2_instances_; |
| 920 | base::Callback<void(org::chromium::Itf2Proxy*)> on_itf2_added_; |
| 921 | base::Callback<void(const dbus::ObjectPath&)> on_itf2_removed_; |
| 922 | base::WeakPtrFactory<ObjectManagerProxy> weak_ptr_factory_{this}; |
| 923 | |
| 924 | DISALLOW_COPY_AND_ASSIGN(ObjectManagerProxy); |
| 925 | }; |
| 926 | |
| 927 | } // namespace chromium |
| 928 | } // namespace org |
| 929 | )literal_string"; |
| 930 | |
| 931 | const char kExpectedContentWithObjectManagerAndServiceName[] = R"literal_string( |
| 932 | #include <memory> |
| 933 | #include <string> |
| 934 | #include <vector> |
| 935 | |
| 936 | #include <base/bind.h> |
| 937 | #include <base/callback.h> |
| 938 | #include <base/logging.h> |
| 939 | #include <base/macros.h> |
| 940 | #include <base/memory/ref_counted.h> |
| 941 | #include <chromeos/any.h> |
| 942 | #include <chromeos/dbus/dbus_method_invoker.h> |
| 943 | #include <chromeos/dbus/dbus_property.h> |
| 944 | #include <chromeos/dbus/dbus_signal_handler.h> |
| 945 | #include <chromeos/errors/error.h> |
| 946 | #include <chromeos/variant_dictionary.h> |
| 947 | #include <dbus/bus.h> |
| 948 | #include <dbus/message.h> |
| 949 | #include <dbus/object_manager.h> |
| 950 | #include <dbus/object_path.h> |
| 951 | #include <dbus/object_proxy.h> |
| 952 | |
| 953 | namespace org { |
| 954 | namespace chromium { |
| 955 | class ObjectManagerProxy; |
| 956 | } // namespace chromium |
| 957 | } // namespace org |
| 958 | |
| 959 | namespace org { |
| 960 | namespace chromium { |
| 961 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 962 | // Abstract interface proxy for org::chromium::Itf1. |
| 963 | class Itf1ProxyInterface { |
| 964 | public: |
Alex Deymo | ce286b9 | 2015-07-28 15:04:07 -0700 | [diff] [blame^] | 965 | virtual void RegisterCloserSignalHandler( |
| 966 | const base::Closure& signal_callback, |
| 967 | dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0; |
| 968 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 969 | protected: |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 970 | virtual ~Itf1ProxyInterface() = default; |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 971 | }; |
| 972 | |
| 973 | } // namespace chromium |
| 974 | } // namespace org |
| 975 | |
| 976 | namespace org { |
| 977 | namespace chromium { |
| 978 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 979 | // Interface proxy for org::chromium::Itf1. |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 980 | class Itf1Proxy final : public Itf1ProxyInterface { |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 981 | public: |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 982 | class PropertySet : public dbus::PropertySet { |
| 983 | public: |
| 984 | PropertySet(dbus::ObjectProxy* object_proxy, |
| 985 | const PropertyChangedCallback& callback) |
| 986 | : dbus::PropertySet{object_proxy, |
| 987 | "org.chromium.Itf1", |
| 988 | callback} { |
| 989 | } |
| 990 | |
| 991 | |
| 992 | private: |
| 993 | DISALLOW_COPY_AND_ASSIGN(PropertySet); |
| 994 | }; |
| 995 | |
| 996 | Itf1Proxy(const scoped_refptr<dbus::Bus>& bus) : |
| 997 | bus_{bus}, |
| 998 | dbus_object_proxy_{ |
| 999 | bus_->GetObjectProxy(service_name_, object_path_)} { |
| 1000 | } |
| 1001 | |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 1002 | ~Itf1Proxy() override { |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | void RegisterCloserSignalHandler( |
| 1006 | const base::Closure& signal_callback, |
Alex Deymo | ce286b9 | 2015-07-28 15:04:07 -0700 | [diff] [blame^] | 1007 | dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override { |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1008 | chromeos::dbus_utils::ConnectToSignal( |
| 1009 | dbus_object_proxy_, |
| 1010 | "org.chromium.Itf1", |
| 1011 | "Closer", |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 1012 | signal_callback, |
| 1013 | on_connected_callback); |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | void ReleaseObjectProxy(const base::Closure& callback) { |
| 1017 | bus_->RemoveObjectProxy(service_name_, object_path_, callback); |
| 1018 | } |
| 1019 | |
| 1020 | const dbus::ObjectPath& GetObjectPath() const { |
| 1021 | return object_path_; |
| 1022 | } |
| 1023 | |
| 1024 | dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; } |
| 1025 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1026 | private: |
| 1027 | scoped_refptr<dbus::Bus> bus_; |
| 1028 | const std::string service_name_{"org.chromium.Test"}; |
| 1029 | const dbus::ObjectPath object_path_{"/org/chromium/Test/Object"}; |
| 1030 | dbus::ObjectProxy* dbus_object_proxy_; |
| 1031 | |
| 1032 | DISALLOW_COPY_AND_ASSIGN(Itf1Proxy); |
| 1033 | }; |
| 1034 | |
| 1035 | } // namespace chromium |
| 1036 | } // namespace org |
| 1037 | |
| 1038 | namespace org { |
| 1039 | namespace chromium { |
| 1040 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 1041 | // Abstract interface proxy for org::chromium::Itf2. |
| 1042 | class Itf2ProxyInterface { |
| 1043 | public: |
| 1044 | protected: |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 1045 | virtual ~Itf2ProxyInterface() = default; |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 1046 | }; |
| 1047 | |
| 1048 | } // namespace chromium |
| 1049 | } // namespace org |
| 1050 | |
| 1051 | namespace org { |
| 1052 | namespace chromium { |
| 1053 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1054 | // Interface proxy for org::chromium::Itf2. |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 1055 | class Itf2Proxy final : public Itf2ProxyInterface { |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1056 | public: |
| 1057 | class PropertySet : public dbus::PropertySet { |
| 1058 | public: |
| 1059 | PropertySet(dbus::ObjectProxy* object_proxy, |
| 1060 | const PropertyChangedCallback& callback) |
| 1061 | : dbus::PropertySet{object_proxy, |
| 1062 | "org.chromium.Itf2", |
| 1063 | callback} { |
| 1064 | } |
| 1065 | |
| 1066 | |
| 1067 | private: |
| 1068 | DISALLOW_COPY_AND_ASSIGN(PropertySet); |
| 1069 | }; |
| 1070 | |
| 1071 | Itf2Proxy( |
| 1072 | const scoped_refptr<dbus::Bus>& bus, |
| 1073 | const dbus::ObjectPath& object_path) : |
| 1074 | bus_{bus}, |
| 1075 | object_path_{object_path}, |
| 1076 | dbus_object_proxy_{ |
| 1077 | bus_->GetObjectProxy(service_name_, object_path_)} { |
| 1078 | } |
| 1079 | |
Alex Deymo | 1685610 | 2015-06-19 20:55:14 -0700 | [diff] [blame] | 1080 | ~Itf2Proxy() override { |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | void ReleaseObjectProxy(const base::Closure& callback) { |
| 1084 | bus_->RemoveObjectProxy(service_name_, object_path_, callback); |
| 1085 | } |
| 1086 | |
| 1087 | const dbus::ObjectPath& GetObjectPath() const { |
| 1088 | return object_path_; |
| 1089 | } |
| 1090 | |
| 1091 | dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; } |
| 1092 | |
| 1093 | private: |
| 1094 | scoped_refptr<dbus::Bus> bus_; |
| 1095 | const std::string service_name_{"org.chromium.Test"}; |
| 1096 | dbus::ObjectPath object_path_; |
| 1097 | dbus::ObjectProxy* dbus_object_proxy_; |
| 1098 | |
| 1099 | DISALLOW_COPY_AND_ASSIGN(Itf2Proxy); |
| 1100 | }; |
| 1101 | |
| 1102 | } // namespace chromium |
| 1103 | } // namespace org |
| 1104 | |
| 1105 | namespace org { |
| 1106 | namespace chromium { |
| 1107 | |
| 1108 | class ObjectManagerProxy : public dbus::ObjectManager::Interface { |
| 1109 | public: |
| 1110 | ObjectManagerProxy(const scoped_refptr<dbus::Bus>& bus) |
| 1111 | : bus_{bus}, |
| 1112 | dbus_object_manager_{bus->GetObjectManager( |
| 1113 | "org.chromium.Test", |
| 1114 | dbus::ObjectPath{"/org/chromium/Test"})} { |
| 1115 | dbus_object_manager_->RegisterInterface("org.chromium.Itf1", this); |
| 1116 | dbus_object_manager_->RegisterInterface("org.chromium.Itf2", this); |
| 1117 | } |
| 1118 | |
Christopher Wiley | e11e81c | 2014-12-19 13:10:52 -0800 | [diff] [blame] | 1119 | ~ObjectManagerProxy() override { |
| 1120 | dbus_object_manager_->UnregisterInterface("org.chromium.Itf1"); |
| 1121 | dbus_object_manager_->UnregisterInterface("org.chromium.Itf2"); |
| 1122 | } |
| 1123 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1124 | dbus::ObjectManager* GetObjectManagerProxy() const { |
| 1125 | return dbus_object_manager_; |
| 1126 | } |
| 1127 | |
Alex Vakulenko | c4e01f1 | 2015-02-23 15:55:21 -0800 | [diff] [blame] | 1128 | org::chromium::Itf1Proxy* GetItf1Proxy() { |
| 1129 | if (itf1_instances_.empty()) |
| 1130 | return nullptr; |
| 1131 | return itf1_instances_.begin()->second.get(); |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1132 | } |
| 1133 | std::vector<org::chromium::Itf1Proxy*> GetItf1Instances() const { |
| 1134 | std::vector<org::chromium::Itf1Proxy*> values; |
| 1135 | values.reserve(itf1_instances_.size()); |
| 1136 | for (const auto& pair : itf1_instances_) |
| 1137 | values.push_back(pair.second.get()); |
| 1138 | return values; |
| 1139 | } |
| 1140 | void SetItf1AddedCallback( |
| 1141 | const base::Callback<void(org::chromium::Itf1Proxy*)>& callback) { |
| 1142 | on_itf1_added_ = callback; |
| 1143 | } |
| 1144 | void SetItf1RemovedCallback( |
| 1145 | const base::Callback<void(const dbus::ObjectPath&)>& callback) { |
| 1146 | on_itf1_removed_ = callback; |
| 1147 | } |
| 1148 | |
| 1149 | org::chromium::Itf2Proxy* GetItf2Proxy( |
| 1150 | const dbus::ObjectPath& object_path) { |
| 1151 | auto p = itf2_instances_.find(object_path); |
| 1152 | if (p != itf2_instances_.end()) |
| 1153 | return p->second.get(); |
| 1154 | return nullptr; |
| 1155 | } |
| 1156 | std::vector<org::chromium::Itf2Proxy*> GetItf2Instances() const { |
| 1157 | std::vector<org::chromium::Itf2Proxy*> values; |
| 1158 | values.reserve(itf2_instances_.size()); |
| 1159 | for (const auto& pair : itf2_instances_) |
| 1160 | values.push_back(pair.second.get()); |
| 1161 | return values; |
| 1162 | } |
| 1163 | void SetItf2AddedCallback( |
| 1164 | const base::Callback<void(org::chromium::Itf2Proxy*)>& callback) { |
| 1165 | on_itf2_added_ = callback; |
| 1166 | } |
| 1167 | void SetItf2RemovedCallback( |
| 1168 | const base::Callback<void(const dbus::ObjectPath&)>& callback) { |
| 1169 | on_itf2_removed_ = callback; |
| 1170 | } |
| 1171 | |
| 1172 | private: |
| 1173 | void OnPropertyChanged(const dbus::ObjectPath& object_path, |
| 1174 | const std::string& interface_name, |
| 1175 | const std::string& property_name) { |
| 1176 | } |
| 1177 | |
| 1178 | void ObjectAdded( |
| 1179 | const dbus::ObjectPath& object_path, |
| 1180 | const std::string& interface_name) override { |
| 1181 | if (interface_name == "org.chromium.Itf1") { |
| 1182 | std::unique_ptr<org::chromium::Itf1Proxy> itf1_proxy{ |
| 1183 | new org::chromium::Itf1Proxy{bus_} |
| 1184 | }; |
| 1185 | auto p = itf1_instances_.emplace(object_path, std::move(itf1_proxy)); |
| 1186 | if (!on_itf1_added_.is_null()) |
| 1187 | on_itf1_added_.Run(p.first->second.get()); |
| 1188 | return; |
| 1189 | } |
| 1190 | if (interface_name == "org.chromium.Itf2") { |
| 1191 | std::unique_ptr<org::chromium::Itf2Proxy> itf2_proxy{ |
| 1192 | new org::chromium::Itf2Proxy{bus_, object_path} |
| 1193 | }; |
| 1194 | auto p = itf2_instances_.emplace(object_path, std::move(itf2_proxy)); |
| 1195 | if (!on_itf2_added_.is_null()) |
| 1196 | on_itf2_added_.Run(p.first->second.get()); |
| 1197 | return; |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | void ObjectRemoved( |
| 1202 | const dbus::ObjectPath& object_path, |
| 1203 | const std::string& interface_name) override { |
| 1204 | if (interface_name == "org.chromium.Itf1") { |
| 1205 | auto p = itf1_instances_.find(object_path); |
| 1206 | if (p != itf1_instances_.end()) { |
| 1207 | if (!on_itf1_removed_.is_null()) |
| 1208 | on_itf1_removed_.Run(object_path); |
| 1209 | itf1_instances_.erase(p); |
| 1210 | } |
| 1211 | return; |
| 1212 | } |
| 1213 | if (interface_name == "org.chromium.Itf2") { |
| 1214 | auto p = itf2_instances_.find(object_path); |
| 1215 | if (p != itf2_instances_.end()) { |
| 1216 | if (!on_itf2_removed_.is_null()) |
| 1217 | on_itf2_removed_.Run(object_path); |
| 1218 | itf2_instances_.erase(p); |
| 1219 | } |
| 1220 | return; |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | dbus::PropertySet* CreateProperties( |
| 1225 | dbus::ObjectProxy* object_proxy, |
| 1226 | const dbus::ObjectPath& object_path, |
| 1227 | const std::string& interface_name) override { |
| 1228 | if (interface_name == "org.chromium.Itf1") { |
| 1229 | return new org::chromium::Itf1Proxy::PropertySet{ |
| 1230 | object_proxy, |
| 1231 | base::Bind(&ObjectManagerProxy::OnPropertyChanged, |
| 1232 | weak_ptr_factory_.GetWeakPtr(), |
| 1233 | object_path, |
| 1234 | interface_name) |
| 1235 | }; |
| 1236 | } |
| 1237 | if (interface_name == "org.chromium.Itf2") { |
| 1238 | return new org::chromium::Itf2Proxy::PropertySet{ |
| 1239 | object_proxy, |
| 1240 | base::Bind(&ObjectManagerProxy::OnPropertyChanged, |
| 1241 | weak_ptr_factory_.GetWeakPtr(), |
| 1242 | object_path, |
| 1243 | interface_name) |
| 1244 | }; |
| 1245 | } |
| 1246 | LOG(FATAL) << "Creating properties for unsupported interface " |
| 1247 | << interface_name; |
| 1248 | return nullptr; |
| 1249 | } |
| 1250 | |
| 1251 | scoped_refptr<dbus::Bus> bus_; |
| 1252 | dbus::ObjectManager* dbus_object_manager_; |
| 1253 | std::map<dbus::ObjectPath, |
| 1254 | std::unique_ptr<org::chromium::Itf1Proxy>> itf1_instances_; |
| 1255 | base::Callback<void(org::chromium::Itf1Proxy*)> on_itf1_added_; |
| 1256 | base::Callback<void(const dbus::ObjectPath&)> on_itf1_removed_; |
| 1257 | std::map<dbus::ObjectPath, |
| 1258 | std::unique_ptr<org::chromium::Itf2Proxy>> itf2_instances_; |
| 1259 | base::Callback<void(org::chromium::Itf2Proxy*)> on_itf2_added_; |
| 1260 | base::Callback<void(const dbus::ObjectPath&)> on_itf2_removed_; |
| 1261 | base::WeakPtrFactory<ObjectManagerProxy> weak_ptr_factory_{this}; |
| 1262 | |
| 1263 | DISALLOW_COPY_AND_ASSIGN(ObjectManagerProxy); |
| 1264 | }; |
| 1265 | |
| 1266 | } // namespace chromium |
| 1267 | } // namespace org |
| 1268 | )literal_string"; |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1269 | } // namespace |
| 1270 | |
| 1271 | class ProxyGeneratorTest : public Test { |
| 1272 | public: |
| 1273 | void SetUp() override { |
| 1274 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 1275 | } |
| 1276 | |
| 1277 | protected: |
| 1278 | base::FilePath CreateInputFile(const string& contents) { |
| 1279 | base::FilePath path; |
| 1280 | EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &path)); |
Christopher Wiley | d0cb3fe | 2015-07-27 17:32:58 -0700 | [diff] [blame] | 1281 | int written = base::WriteFile(path, contents.c_str(), contents.size()); |
| 1282 | EXPECT_EQ(contents.size(), static_cast<size_t>(written)); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1283 | return path; |
| 1284 | } |
| 1285 | |
| 1286 | base::ScopedTempDir temp_dir_; |
| 1287 | }; |
| 1288 | |
| 1289 | TEST_F(ProxyGeneratorTest, GenerateAdaptors) { |
| 1290 | Interface interface; |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1291 | interface.name = "org.chromium.TestInterface"; |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 1292 | interface.path = "/org/chromium/Test"; |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1293 | interface.methods.emplace_back( |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1294 | "Elements", |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1295 | vector<Interface::Argument>{ |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1296 | {"space_walk", kDBusTypeString}, |
| 1297 | {"ramblin_man", kDBusTypeArryOfObjects}}, |
| 1298 | vector<Interface::Argument>{{"", kDBusTypeString}}); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1299 | interface.methods.emplace_back( |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1300 | "ReturnToPatagonia", |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1301 | vector<Interface::Argument>{}, |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1302 | vector<Interface::Argument>{{"", kDBusTypeInt64}}); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1303 | interface.methods.emplace_back( |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1304 | "NiceWeatherForDucks", |
| 1305 | vector<Interface::Argument>{{"", kDBusTypeBool}}, |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1306 | vector<Interface::Argument>{}); |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1307 | interface.methods.emplace_back("ExperimentNumberSix"); |
| 1308 | interface.signals.emplace_back("Closer"); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1309 | interface.signals.emplace_back( |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1310 | "TheCurseOfKaZar", |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1311 | vector<Interface::Argument>{ |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1312 | {"", kDBusTypeArryOfStrings}, |
| 1313 | {"", kDBusTypeByte}}); |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 1314 | interface.methods.back().doc_string = "Comment line1\nline2"; |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 1315 | Interface interface2; |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1316 | interface2.name = "org.chromium.TestInterface2"; |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 1317 | interface2.methods.emplace_back( |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1318 | "GetPersonInfo", |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 1319 | vector<Interface::Argument>{}, |
| 1320 | vector<Interface::Argument>{ |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1321 | {"name", kDBusTypeString}, |
| 1322 | {"age", kDBusTypeInt32}}); |
Alex Vakulenko | fafef13 | 2014-11-03 14:52:09 -0800 | [diff] [blame] | 1323 | vector<Interface> interfaces{interface, interface2}; |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1324 | base::FilePath output_path = temp_dir_.path().Append("output.h"); |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 1325 | ServiceConfig config; |
| 1326 | EXPECT_TRUE(ProxyGenerator::GenerateProxies(config, interfaces, output_path)); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1327 | string contents; |
| 1328 | EXPECT_TRUE(base::ReadFileToString(output_path, &contents)); |
| 1329 | // The header guards contain the (temporary) filename, so we search for |
| 1330 | // the content we need within the string. |
Alex Deymo | f211ae6 | 2015-07-28 13:09:29 -0700 | [diff] [blame] | 1331 | test_utils::EXPECT_TEXT_CONTAINED(kExpectedContent, contents); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 1334 | TEST_F(ProxyGeneratorTest, GenerateAdaptorsWithServiceName) { |
| 1335 | Interface interface; |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1336 | interface.name = "org.chromium.TestInterface"; |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 1337 | interface.path = "/org/chromium/Test"; |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1338 | interface.signals.emplace_back("Closer"); |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 1339 | Interface interface2; |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1340 | interface2.name = "org.chromium.TestInterface2"; |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 1341 | vector<Interface> interfaces{interface, interface2}; |
| 1342 | base::FilePath output_path = temp_dir_.path().Append("output2.h"); |
| 1343 | ServiceConfig config; |
| 1344 | config.service_name = "org.chromium.Test"; |
| 1345 | EXPECT_TRUE(ProxyGenerator::GenerateProxies(config, interfaces, output_path)); |
| 1346 | string contents; |
| 1347 | EXPECT_TRUE(base::ReadFileToString(output_path, &contents)); |
| 1348 | // The header guards contain the (temporary) filename, so we search for |
| 1349 | // the content we need within the string. |
Alex Deymo | f211ae6 | 2015-07-28 13:09:29 -0700 | [diff] [blame] | 1350 | test_utils::EXPECT_TEXT_CONTAINED(kExpectedContentWithService, contents); |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 1351 | } |
| 1352 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1353 | TEST_F(ProxyGeneratorTest, GenerateAdaptorsWithObjectManager) { |
| 1354 | Interface interface; |
| 1355 | interface.name = "org.chromium.Itf1"; |
| 1356 | interface.path = "/org/chromium/Test/Object"; |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1357 | interface.signals.emplace_back("Closer"); |
Alex Vakulenko | 59dd2e9 | 2015-02-23 15:14:28 -0800 | [diff] [blame] | 1358 | interface.properties.emplace_back("Data", "s", "read"); |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1359 | Interface interface2; |
| 1360 | interface2.name = "org.chromium.Itf2"; |
| 1361 | vector<Interface> interfaces{interface, interface2}; |
| 1362 | base::FilePath output_path = temp_dir_.path().Append("output3.h"); |
| 1363 | ServiceConfig config; |
| 1364 | config.object_manager.name = "org.chromium.ObjectManager"; |
| 1365 | config.object_manager.object_path = "/org/chromium/Test"; |
| 1366 | EXPECT_TRUE(ProxyGenerator::GenerateProxies(config, interfaces, output_path)); |
| 1367 | string contents; |
| 1368 | EXPECT_TRUE(base::ReadFileToString(output_path, &contents)); |
| 1369 | // The header guards contain the (temporary) filename, so we search for |
| 1370 | // the content we need within the string. |
Alex Deymo | f211ae6 | 2015-07-28 13:09:29 -0700 | [diff] [blame] | 1371 | test_utils::EXPECT_TEXT_CONTAINED( |
| 1372 | kExpectedContentWithObjectManager, contents); |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | TEST_F(ProxyGeneratorTest, GenerateAdaptorsWithObjectManagerAndServiceName) { |
| 1376 | Interface interface; |
| 1377 | interface.name = "org.chromium.Itf1"; |
| 1378 | interface.path = "/org/chromium/Test/Object"; |
Alex Vakulenko | b69be60 | 2015-02-23 14:40:42 -0800 | [diff] [blame] | 1379 | interface.signals.emplace_back("Closer"); |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1380 | Interface interface2; |
| 1381 | interface2.name = "org.chromium.Itf2"; |
| 1382 | vector<Interface> interfaces{interface, interface2}; |
| 1383 | base::FilePath output_path = temp_dir_.path().Append("output4.h"); |
| 1384 | ServiceConfig config; |
| 1385 | config.service_name = "org.chromium.Test"; |
| 1386 | config.object_manager.name = "org.chromium.ObjectManager"; |
| 1387 | config.object_manager.object_path = "/org/chromium/Test"; |
| 1388 | EXPECT_TRUE(ProxyGenerator::GenerateProxies(config, interfaces, output_path)); |
| 1389 | string contents; |
| 1390 | EXPECT_TRUE(base::ReadFileToString(output_path, &contents)); |
| 1391 | // The header guards contain the (temporary) filename, so we search for |
| 1392 | // the content we need within the string. |
Alex Deymo | f211ae6 | 2015-07-28 13:09:29 -0700 | [diff] [blame] | 1393 | test_utils::EXPECT_TEXT_CONTAINED( |
| 1394 | kExpectedContentWithObjectManagerAndServiceName, contents); |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 1395 | } |
| 1396 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1397 | } // namespace chromeos_dbus_bindings |