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