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