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