OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DBUS_PROPERTY_H_ | 5 #ifndef DBUS_PROPERTY_H_ |
6 #define DBUS_PROPERTY_H_ | 6 #define DBUS_PROPERTY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 252 |
253 // Requests an updated value from the remote object for |property| | 253 // Requests an updated value from the remote object for |property| |
254 // incurring a round-trip. |callback| will be called when the new | 254 // incurring a round-trip. |callback| will be called when the new |
255 // value is available. This may not be implemented by some interfaces, | 255 // value is available. This may not be implemented by some interfaces, |
256 // and may be overriden by sub-classes if interfaces use different | 256 // and may be overriden by sub-classes if interfaces use different |
257 // method calls. | 257 // method calls. |
258 virtual void Get(PropertyBase* property, GetCallback callback); | 258 virtual void Get(PropertyBase* property, GetCallback callback); |
259 virtual void OnGet(PropertyBase* property, GetCallback callback, | 259 virtual void OnGet(PropertyBase* property, GetCallback callback, |
260 Response* response); | 260 Response* response); |
261 | 261 |
| 262 // The synchronous version of Get(). |
| 263 // This should never be used on an interactive thread. |
| 264 virtual bool GetAndBlock(PropertyBase* property); |
| 265 |
262 // Queries the remote object for values of all properties and updates | 266 // Queries the remote object for values of all properties and updates |
263 // initial values. Sub-classes may override to use a different D-Bus | 267 // initial values. Sub-classes may override to use a different D-Bus |
264 // method, or if the remote object does not support retrieving all | 268 // method, or if the remote object does not support retrieving all |
265 // properties, either ignore or obtain each property value individually. | 269 // properties, either ignore or obtain each property value individually. |
266 virtual void GetAll(); | 270 virtual void GetAll(); |
267 virtual void OnGetAll(Response* response); | 271 virtual void OnGetAll(Response* response); |
268 | 272 |
269 // Callback for Set() method, |success| indicates whether or not the | 273 // Callback for Set() method, |success| indicates whether or not the |
270 // new property value was accepted by the remote object. | 274 // new property value was accepted by the remote object. |
271 typedef base::Callback<void(bool success)> SetCallback; | 275 typedef base::Callback<void(bool success)> SetCallback; |
272 | 276 |
273 // Requests that the remote object for |property| change the property to | 277 // Requests that the remote object for |property| change the property to |
274 // its new value. |callback| will be called to indicate the success or | 278 // its new value. |callback| will be called to indicate the success or |
275 // failure of the request, however the new value may not be available | 279 // failure of the request, however the new value may not be available |
276 // depending on the remote object. This method may be overridden by | 280 // depending on the remote object. This method may be overridden by |
277 // sub-classes if interfaces use different method calls. | 281 // sub-classes if interfaces use different method calls. |
278 virtual void Set(PropertyBase* property, SetCallback callback); | 282 virtual void Set(PropertyBase* property, SetCallback callback); |
279 // The sychronous version of Set(). | |
280 virtual bool SetAndBlock(PropertyBase* property); | |
281 virtual void OnSet(PropertyBase* property, SetCallback callback, | 283 virtual void OnSet(PropertyBase* property, SetCallback callback, |
282 Response* response); | 284 Response* response); |
283 | 285 |
| 286 // The synchronous version of Set(). |
| 287 // This should never be used on an interactive thread. |
| 288 virtual bool SetAndBlock(PropertyBase* property); |
| 289 |
284 // Update properties by reading an array of dictionary entries, each | 290 // Update properties by reading an array of dictionary entries, each |
285 // containing a string with the name and a variant with the value, from | 291 // containing a string with the name and a variant with the value, from |
286 // |message_reader|. Returns false if message is in incorrect format. | 292 // |message_reader|. Returns false if message is in incorrect format. |
287 bool UpdatePropertiesFromReader(MessageReader* reader); | 293 bool UpdatePropertiesFromReader(MessageReader* reader); |
288 | 294 |
289 // Updates a single property by reading a string with the name and a | 295 // Updates a single property by reading a string with the name and a |
290 // variant with the value from |message_reader|. Returns false if message | 296 // variant with the value from |message_reader|. Returns false if message |
291 // is in incorrect format, or property type doesn't match. | 297 // is in incorrect format, or property type doesn't match. |
292 bool UpdatePropertyFromReader(MessageReader* reader); | 298 bool UpdatePropertyFromReader(MessageReader* reader); |
293 | 299 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 // Retrieves the cached value. | 381 // Retrieves the cached value. |
376 const T& value() const { return value_; } | 382 const T& value() const { return value_; } |
377 | 383 |
378 // Requests an updated value from the remote object incurring a | 384 // Requests an updated value from the remote object incurring a |
379 // round-trip. |callback| will be called when the new value is available. | 385 // round-trip. |callback| will be called when the new value is available. |
380 // This may not be implemented by some interfaces. | 386 // This may not be implemented by some interfaces. |
381 virtual void Get(dbus::PropertySet::GetCallback callback) { | 387 virtual void Get(dbus::PropertySet::GetCallback callback) { |
382 property_set()->Get(this, callback); | 388 property_set()->Get(this, callback); |
383 } | 389 } |
384 | 390 |
| 391 // The synchronous version of Get(). |
| 392 // This should never be used on an interactive thread. |
| 393 virtual bool GetAndBlock() { |
| 394 return property_set()->GetAndBlock(this); |
| 395 } |
| 396 |
385 // Requests that the remote object change the property value to |value|, | 397 // Requests that the remote object change the property value to |value|, |
386 // |callback| will be called to indicate the success or failure of the | 398 // |callback| will be called to indicate the success or failure of the |
387 // request, however the new value may not be available depending on the | 399 // request, however the new value may not be available depending on the |
388 // remote object. | 400 // remote object. |
389 virtual void Set(const T& value, dbus::PropertySet::SetCallback callback) { | 401 virtual void Set(const T& value, dbus::PropertySet::SetCallback callback) { |
390 set_value_ = value; | 402 set_value_ = value; |
391 property_set()->Set(this, callback); | 403 property_set()->Set(this, callback); |
392 } | 404 } |
393 | 405 |
394 // The sychronous version of Set(). | 406 // The synchronous version of Set(). |
| 407 // This should never be used on an interactive thread. |
395 virtual bool SetAndBlock(const T& value) { | 408 virtual bool SetAndBlock(const T& value) { |
396 set_value_ = value; | 409 set_value_ = value; |
397 return property_set()->SetAndBlock(this); | 410 return property_set()->SetAndBlock(this); |
398 } | 411 } |
399 | 412 |
400 // Method used by PropertySet to retrieve the value from a MessageReader, | 413 // Method used by PropertySet to retrieve the value from a MessageReader, |
401 // no knowledge of the contained type is required, this method returns | 414 // no knowledge of the contained type is required, this method returns |
402 // true if its expected type was found, false if not. | 415 // true if its expected type was found, false if not. |
403 bool PopValueFromReader(MessageReader* reader) override; | 416 bool PopValueFromReader(MessageReader* reader) override; |
404 | 417 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>:: | 606 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>:: |
594 AppendSetValueToWriter(MessageWriter* writer); | 607 AppendSetValueToWriter(MessageWriter* writer); |
595 extern template class CHROME_DBUS_EXPORT | 608 extern template class CHROME_DBUS_EXPORT |
596 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; | 609 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; |
597 | 610 |
598 #pragma GCC diagnostic pop | 611 #pragma GCC diagnostic pop |
599 | 612 |
600 } // namespace dbus | 613 } // namespace dbus |
601 | 614 |
602 #endif // DBUS_PROPERTY_H_ | 615 #endif // DBUS_PROPERTY_H_ |
OLD | NEW |