| 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 <stdint.h> |
| 9 |
| 8 #include <map> | 10 #include <map> |
| 9 #include <string> | 11 #include <string> |
| 10 #include <utility> | 12 #include <utility> |
| 11 #include <vector> | 13 #include <vector> |
| 12 | 14 |
| 13 #include "base/basictypes.h" | |
| 14 #include "base/bind.h" | 15 #include "base/bind.h" |
| 15 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/macros.h" |
| 16 #include "dbus/dbus_export.h" | 18 #include "dbus/dbus_export.h" |
| 17 #include "dbus/message.h" | 19 #include "dbus/message.h" |
| 18 #include "dbus/object_proxy.h" | 20 #include "dbus/object_proxy.h" |
| 19 | 21 |
| 20 // D-Bus objects frequently provide sets of properties accessed via a | 22 // D-Bus objects frequently provide sets of properties accessed via a |
| 21 // standard interface of method calls and signals to obtain the current value, | 23 // standard interface of method calls and signals to obtain the current value, |
| 22 // set a new value and be notified of changes to the value. Unfortunately this | 24 // set a new value and be notified of changes to the value. Unfortunately this |
| 23 // interface makes heavy use of variants and dictionaries of variants. The | 25 // interface makes heavy use of variants and dictionaries of variants. The |
| 24 // classes defined here make dealing with properties in a type-safe manner | 26 // classes defined here make dealing with properties in a type-safe manner |
| 25 // possible. | 27 // possible. |
| 26 // | 28 // |
| 27 // Client implementation classes should define a Properties structure, deriving | 29 // Client implementation classes should define a Properties structure, deriving |
| 28 // from the PropertySet class defined here. This structure should contain a | 30 // from the PropertySet class defined here. This structure should contain a |
| 29 // member for each property defined as an instance of the Property<> class, | 31 // member for each property defined as an instance of the Property<> class, |
| 30 // specifying the type to the template. Finally the structure should chain up | 32 // specifying the type to the template. Finally the structure should chain up |
| 31 // to the PropertySet constructor, and then call RegisterProperty() for each | 33 // to the PropertySet constructor, and then call RegisterProperty() for each |
| 32 // property defined to associate them with their string name. | 34 // property defined to associate them with their string name. |
| 33 // | 35 // |
| 34 // Example: | 36 // Example: |
| 35 // class ExampleClient { | 37 // class ExampleClient { |
| 36 // public: | 38 // public: |
| 37 // struct Properties : public dbus::PropertySet { | 39 // struct Properties : public dbus::PropertySet { |
| 38 // dbus::Property<std::string> name; | 40 // dbus::Property<std::string> name; |
| 39 // dbus::Property<uint16> version; | 41 // dbus::Property<uint16_t> version; |
| 40 // dbus::Property<dbus::ObjectPath> parent; | 42 // dbus::Property<dbus::ObjectPath> parent; |
| 41 // dbus::Property<std::vector<std::string> > children; | 43 // dbus::Property<std::vector<std::string> > children; |
| 42 // | 44 // |
| 43 // Properties(dbus::ObjectProxy* object_proxy, | 45 // Properties(dbus::ObjectProxy* object_proxy, |
| 44 // const PropertyChangedCallback callback) | 46 // const PropertyChangedCallback callback) |
| 45 // : dbus::PropertySet(object_proxy, "com.example.DBus", callback) { | 47 // : dbus::PropertySet(object_proxy, "com.example.DBus", callback) { |
| 46 // RegisterProperty("Name", &name); | 48 // RegisterProperty("Name", &name); |
| 47 // RegisterProperty("Version", &version); | 49 // RegisterProperty("Version", &version); |
| 48 // RegisterProperty("Parent", &parent); | 50 // RegisterProperty("Parent", &parent); |
| 49 // RegisterProperty("Children", &children); | 51 // RegisterProperty("Children", &children); |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 // Clang and GCC don't agree on how attributes should work for explicitly | 452 // Clang and GCC don't agree on how attributes should work for explicitly |
| 451 // instantiated templates. GCC ignores attributes on explicit instantiations | 453 // instantiated templates. GCC ignores attributes on explicit instantiations |
| 452 // (and emits a warning) while Clang requires the visiblity attribute on the | 454 // (and emits a warning) while Clang requires the visiblity attribute on the |
| 453 // explicit instantiations for them to be visible to other compilation units. | 455 // explicit instantiations for them to be visible to other compilation units. |
| 454 // Hopefully clang and GCC agree one day, and this can be cleaned up: | 456 // Hopefully clang and GCC agree one day, and this can be cleaned up: |
| 455 // https://llvm.org/bugs/show_bug.cgi?id=24815 | 457 // https://llvm.org/bugs/show_bug.cgi?id=24815 |
| 456 #pragma GCC diagnostic push | 458 #pragma GCC diagnostic push |
| 457 #pragma GCC diagnostic ignored "-Wattributes" | 459 #pragma GCC diagnostic ignored "-Wattributes" |
| 458 | 460 |
| 459 template <> | 461 template <> |
| 460 CHROME_DBUS_EXPORT Property<uint8>::Property(); | 462 CHROME_DBUS_EXPORT Property<uint8_t>::Property(); |
| 461 template <> | 463 template <> |
| 462 CHROME_DBUS_EXPORT bool Property<uint8>::PopValueFromReader( | 464 CHROME_DBUS_EXPORT bool Property<uint8_t>::PopValueFromReader( |
| 463 MessageReader* reader); | 465 MessageReader* reader); |
| 464 template <> | 466 template <> |
| 465 CHROME_DBUS_EXPORT void Property<uint8>::AppendSetValueToWriter( | 467 CHROME_DBUS_EXPORT void Property<uint8_t>::AppendSetValueToWriter( |
| 466 MessageWriter* writer); | 468 MessageWriter* writer); |
| 467 extern template class CHROME_DBUS_EXPORT Property<uint8>; | 469 extern template class CHROME_DBUS_EXPORT Property<uint8_t>; |
| 468 | 470 |
| 469 template <> | 471 template <> |
| 470 CHROME_DBUS_EXPORT Property<bool>::Property(); | 472 CHROME_DBUS_EXPORT Property<bool>::Property(); |
| 471 template <> | 473 template <> |
| 472 CHROME_DBUS_EXPORT bool Property<bool>::PopValueFromReader( | 474 CHROME_DBUS_EXPORT bool Property<bool>::PopValueFromReader( |
| 473 MessageReader* reader); | 475 MessageReader* reader); |
| 474 template <> | 476 template <> |
| 475 CHROME_DBUS_EXPORT void Property<bool>::AppendSetValueToWriter( | 477 CHROME_DBUS_EXPORT void Property<bool>::AppendSetValueToWriter( |
| 476 MessageWriter* writer); | 478 MessageWriter* writer); |
| 477 extern template class CHROME_DBUS_EXPORT Property<bool>; | 479 extern template class CHROME_DBUS_EXPORT Property<bool>; |
| 478 | 480 |
| 479 template <> | 481 template <> |
| 480 CHROME_DBUS_EXPORT Property<int16>::Property(); | 482 CHROME_DBUS_EXPORT Property<int16_t>::Property(); |
| 481 template <> | 483 template <> |
| 482 CHROME_DBUS_EXPORT bool Property<int16>::PopValueFromReader( | 484 CHROME_DBUS_EXPORT bool Property<int16_t>::PopValueFromReader( |
| 483 MessageReader* reader); | 485 MessageReader* reader); |
| 484 template <> | 486 template <> |
| 485 CHROME_DBUS_EXPORT void Property<int16>::AppendSetValueToWriter( | 487 CHROME_DBUS_EXPORT void Property<int16_t>::AppendSetValueToWriter( |
| 486 MessageWriter* writer); | 488 MessageWriter* writer); |
| 487 extern template class CHROME_DBUS_EXPORT Property<int16>; | 489 extern template class CHROME_DBUS_EXPORT Property<int16_t>; |
| 488 | 490 |
| 489 template <> | 491 template <> |
| 490 CHROME_DBUS_EXPORT Property<uint16>::Property(); | 492 CHROME_DBUS_EXPORT Property<uint16_t>::Property(); |
| 491 template <> | 493 template <> |
| 492 CHROME_DBUS_EXPORT bool Property<uint16>::PopValueFromReader( | 494 CHROME_DBUS_EXPORT bool Property<uint16_t>::PopValueFromReader( |
| 493 MessageReader* reader); | 495 MessageReader* reader); |
| 494 template <> | 496 template <> |
| 495 CHROME_DBUS_EXPORT void Property<uint16>::AppendSetValueToWriter( | 497 CHROME_DBUS_EXPORT void Property<uint16_t>::AppendSetValueToWriter( |
| 496 MessageWriter* writer); | 498 MessageWriter* writer); |
| 497 extern template class CHROME_DBUS_EXPORT Property<uint16>; | 499 extern template class CHROME_DBUS_EXPORT Property<uint16_t>; |
| 498 | 500 |
| 499 template <> | 501 template <> |
| 500 CHROME_DBUS_EXPORT Property<int32>::Property(); | 502 CHROME_DBUS_EXPORT Property<int32_t>::Property(); |
| 501 template <> | 503 template <> |
| 502 CHROME_DBUS_EXPORT bool Property<int32>::PopValueFromReader( | 504 CHROME_DBUS_EXPORT bool Property<int32_t>::PopValueFromReader( |
| 503 MessageReader* reader); | 505 MessageReader* reader); |
| 504 template <> | 506 template <> |
| 505 CHROME_DBUS_EXPORT void Property<int32>::AppendSetValueToWriter( | 507 CHROME_DBUS_EXPORT void Property<int32_t>::AppendSetValueToWriter( |
| 506 MessageWriter* writer); | 508 MessageWriter* writer); |
| 507 extern template class CHROME_DBUS_EXPORT Property<int32>; | 509 extern template class CHROME_DBUS_EXPORT Property<int32_t>; |
| 508 | 510 |
| 509 template <> | 511 template <> |
| 510 CHROME_DBUS_EXPORT Property<uint32>::Property(); | 512 CHROME_DBUS_EXPORT Property<uint32_t>::Property(); |
| 511 template <> | 513 template <> |
| 512 CHROME_DBUS_EXPORT bool Property<uint32>::PopValueFromReader( | 514 CHROME_DBUS_EXPORT bool Property<uint32_t>::PopValueFromReader( |
| 513 MessageReader* reader); | 515 MessageReader* reader); |
| 514 template <> | 516 template <> |
| 515 CHROME_DBUS_EXPORT void Property<uint32>::AppendSetValueToWriter( | 517 CHROME_DBUS_EXPORT void Property<uint32_t>::AppendSetValueToWriter( |
| 516 MessageWriter* writer); | 518 MessageWriter* writer); |
| 517 extern template class CHROME_DBUS_EXPORT Property<uint32>; | 519 extern template class CHROME_DBUS_EXPORT Property<uint32_t>; |
| 518 | 520 |
| 519 template <> | 521 template <> |
| 520 CHROME_DBUS_EXPORT Property<int64>::Property(); | 522 CHROME_DBUS_EXPORT Property<int64_t>::Property(); |
| 521 template <> | 523 template <> |
| 522 CHROME_DBUS_EXPORT bool Property<int64>::PopValueFromReader( | 524 CHROME_DBUS_EXPORT bool Property<int64_t>::PopValueFromReader( |
| 523 MessageReader* reader); | 525 MessageReader* reader); |
| 524 template <> | 526 template <> |
| 525 CHROME_DBUS_EXPORT void Property<int64>::AppendSetValueToWriter( | 527 CHROME_DBUS_EXPORT void Property<int64_t>::AppendSetValueToWriter( |
| 526 MessageWriter* writer); | 528 MessageWriter* writer); |
| 527 extern template class CHROME_DBUS_EXPORT Property<int64>; | 529 extern template class CHROME_DBUS_EXPORT Property<int64_t>; |
| 528 | 530 |
| 529 template <> | 531 template <> |
| 530 CHROME_DBUS_EXPORT Property<uint64>::Property(); | 532 CHROME_DBUS_EXPORT Property<uint64_t>::Property(); |
| 531 template <> | 533 template <> |
| 532 CHROME_DBUS_EXPORT bool Property<uint64>::PopValueFromReader( | 534 CHROME_DBUS_EXPORT bool Property<uint64_t>::PopValueFromReader( |
| 533 MessageReader* reader); | 535 MessageReader* reader); |
| 534 template <> | 536 template <> |
| 535 CHROME_DBUS_EXPORT void Property<uint64>::AppendSetValueToWriter( | 537 CHROME_DBUS_EXPORT void Property<uint64_t>::AppendSetValueToWriter( |
| 536 MessageWriter* writer); | 538 MessageWriter* writer); |
| 537 extern template class CHROME_DBUS_EXPORT Property<uint64>; | 539 extern template class CHROME_DBUS_EXPORT Property<uint64_t>; |
| 538 | 540 |
| 539 template <> | 541 template <> |
| 540 CHROME_DBUS_EXPORT Property<double>::Property(); | 542 CHROME_DBUS_EXPORT Property<double>::Property(); |
| 541 template <> | 543 template <> |
| 542 CHROME_DBUS_EXPORT bool Property<double>::PopValueFromReader( | 544 CHROME_DBUS_EXPORT bool Property<double>::PopValueFromReader( |
| 543 MessageReader* reader); | 545 MessageReader* reader); |
| 544 template <> | 546 template <> |
| 545 CHROME_DBUS_EXPORT void Property<double>::AppendSetValueToWriter( | 547 CHROME_DBUS_EXPORT void Property<double>::AppendSetValueToWriter( |
| 546 MessageWriter* writer); | 548 MessageWriter* writer); |
| 547 extern template class CHROME_DBUS_EXPORT Property<double>; | 549 extern template class CHROME_DBUS_EXPORT Property<double>; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 572 | 574 |
| 573 template <> | 575 template <> |
| 574 CHROME_DBUS_EXPORT bool Property<std::vector<ObjectPath>>::PopValueFromReader( | 576 CHROME_DBUS_EXPORT bool Property<std::vector<ObjectPath>>::PopValueFromReader( |
| 575 MessageReader* reader); | 577 MessageReader* reader); |
| 576 template <> | 578 template <> |
| 577 CHROME_DBUS_EXPORT void Property< | 579 CHROME_DBUS_EXPORT void Property< |
| 578 std::vector<ObjectPath>>::AppendSetValueToWriter(MessageWriter* writer); | 580 std::vector<ObjectPath>>::AppendSetValueToWriter(MessageWriter* writer); |
| 579 extern template class CHROME_DBUS_EXPORT Property<std::vector<ObjectPath>>; | 581 extern template class CHROME_DBUS_EXPORT Property<std::vector<ObjectPath>>; |
| 580 | 582 |
| 581 template <> | 583 template <> |
| 582 CHROME_DBUS_EXPORT bool Property<std::vector<uint8>>::PopValueFromReader( | 584 CHROME_DBUS_EXPORT bool Property<std::vector<uint8_t>>::PopValueFromReader( |
| 583 MessageReader* reader); | 585 MessageReader* reader); |
| 584 template <> | 586 template <> |
| 585 CHROME_DBUS_EXPORT void Property<std::vector<uint8>>::AppendSetValueToWriter( | 587 CHROME_DBUS_EXPORT void Property<std::vector<uint8_t>>::AppendSetValueToWriter( |
| 586 MessageWriter* writer); | 588 MessageWriter* writer); |
| 587 extern template class CHROME_DBUS_EXPORT Property<std::vector<uint8>>; | 589 extern template class CHROME_DBUS_EXPORT Property<std::vector<uint8_t>>; |
| 588 | 590 |
| 589 template <> | 591 template <> |
| 590 CHROME_DBUS_EXPORT bool | 592 CHROME_DBUS_EXPORT bool |
| 591 Property<std::map<std::string, std::string>>::PopValueFromReader( | 593 Property<std::map<std::string, std::string>>::PopValueFromReader( |
| 592 MessageReader* reader); | 594 MessageReader* reader); |
| 593 template <> | 595 template <> |
| 594 CHROME_DBUS_EXPORT void | 596 CHROME_DBUS_EXPORT void |
| 595 Property<std::map<std::string, std::string>>::AppendSetValueToWriter( | 597 Property<std::map<std::string, std::string>>::AppendSetValueToWriter( |
| 596 MessageWriter* writer); | 598 MessageWriter* writer); |
| 597 extern template class CHROME_DBUS_EXPORT | 599 extern template class CHROME_DBUS_EXPORT |
| 598 Property<std::map<std::string, std::string>>; | 600 Property<std::map<std::string, std::string>>; |
| 599 | 601 |
| 600 template <> | 602 template <> |
| 601 CHROME_DBUS_EXPORT bool | 603 CHROME_DBUS_EXPORT bool |
| 602 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>:: | 604 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>:: |
| 603 PopValueFromReader(MessageReader* reader); | 605 PopValueFromReader(MessageReader* reader); |
| 604 template <> | 606 template <> |
| 605 CHROME_DBUS_EXPORT void | 607 CHROME_DBUS_EXPORT void |
| 606 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>:: | 608 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>:: |
| 607 AppendSetValueToWriter(MessageWriter* writer); | 609 AppendSetValueToWriter(MessageWriter* writer); |
| 608 extern template class CHROME_DBUS_EXPORT | 610 extern template class CHROME_DBUS_EXPORT |
| 609 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; | 611 Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; |
| 610 | 612 |
| 611 #pragma GCC diagnostic pop | 613 #pragma GCC diagnostic pop |
| 612 | 614 |
| 613 } // namespace dbus | 615 } // namespace dbus |
| 614 | 616 |
| 615 #endif // DBUS_PROPERTY_H_ | 617 #endif // DBUS_PROPERTY_H_ |
| OLD | NEW |