libchromeos: Add D-Bus Property class that handles any data type
libchrome's D-Bus library provides dbus::Property<T> class in
<dbus/property.h> header file for implementing D-Bus property support
in object proxies. Unfortunately it provides specializations only for
a limited number of data types, such as basic D-Bus types (int, string,
bool, etc.) as well as just a few common arrays: std::vector<std::string>,
std::vector<dbus::ObjectPath>, std::vector<uint8>. None of the
other array types, STUCTs or DICTs are supported.
It is very difficult to add generic specializations to Property<T>
for other array and map types, as well as tuple<> for STRUCT data.
As a work-around, re-implement only the top-level Property<T> on
libchromeos side using its extensive data serialization framework.
The code in chromeos/dbus_dbus_property.h is almost the 1-for-1 copy
of that from <dbus/property.h> except for additional implementaion
of PopValueFromReader and AppendSetValueToWriter.
Also updated buffet with using the new class and therefore removed
the specialization of Property for VariantDictionary type.
command_property_set.cc is left empty for now and will be removed
completely in a follow-up CL when D-Bus proxy generator adds support
for D-Bus properties.
BUG=chromium:431737
TEST=FEATURES=test emerge-link libchromeos buffet
Change-Id: I06659fd6569898275fa2d16cd643ceda9058ffc2
Reviewed-on: https://chromium-review.googlesource.com/231995
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Anton Muhin <antonm@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/libbuffet/command_listener.cc b/buffet/libbuffet/command_listener.cc
index 40c09a3..50e90ce 100644
--- a/buffet/libbuffet/command_listener.cc
+++ b/buffet/libbuffet/command_listener.cc
@@ -22,6 +22,7 @@
RegisterProperty(dbus_constants::kCommandStatus, &status);
RegisterProperty(dbus_constants::kCommandProgress, &progress);
RegisterProperty(dbus_constants::kCommandParameters, ¶meters);
+ RegisterProperty(dbus_constants::kCommandResults, &results);
}
bool CommandListener::Init(
diff --git a/buffet/libbuffet/private/command_property_set.cc b/buffet/libbuffet/private/command_property_set.cc
index 65f5c5e..370139d 100644
--- a/buffet/libbuffet/private/command_property_set.cc
+++ b/buffet/libbuffet/private/command_property_set.cc
@@ -4,4 +4,3 @@
#include "libbuffet/private/command_property_set.h"
-template class dbus::Property<chromeos::VariantDictionary>;
diff --git a/buffet/libbuffet/private/command_property_set.h b/buffet/libbuffet/private/command_property_set.h
index 98387d3..dbf9eae 100644
--- a/buffet/libbuffet/private/command_property_set.h
+++ b/buffet/libbuffet/private/command_property_set.h
@@ -8,29 +8,12 @@
#include <string>
#include <base/macros.h>
-#include <chromeos/dbus/data_serialization.h>
+#include <chromeos/dbus/dbus_property.h>
#include <chromeos/variant_dictionary.h>
#include <dbus/object_manager.h>
#include "buffet/libbuffet/export.h"
-namespace dbus {
-// Specialize dbus::Property for chromeos::VariantDictionary type.
-template <>
-inline bool Property<chromeos::VariantDictionary>::PopValueFromReader(
- MessageReader* reader) {
- return chromeos::dbus_utils::PopVariantValueFromReader(reader, &value_);
-}
-
-template <>
-inline void Property<chromeos::VariantDictionary>::AppendSetValueToWriter(
- MessageWriter* writer) {
- chromeos::dbus_utils::AppendValueToWriterAsVariant(writer, set_value_);
-}
-
-extern template class Property<chromeos::VariantDictionary>;
-} // namespace dbus
-
namespace buffet {
// PropertySet for remote D-Bus GCD Command object from Buffet daemon.
@@ -39,12 +22,13 @@
CommandPropertySet(dbus::ObjectProxy* object_proxy,
const std::string& interface_name,
const PropertyChangedCallback& callback);
- dbus::Property<std::string> id;
- dbus::Property<std::string> name;
- dbus::Property<std::string> category;
- dbus::Property<std::string> status;
- dbus::Property<int32_t> progress;
- dbus::Property<chromeos::VariantDictionary> parameters;
+ chromeos::dbus_utils::Property<std::string> id;
+ chromeos::dbus_utils::Property<std::string> name;
+ chromeos::dbus_utils::Property<std::string> category;
+ chromeos::dbus_utils::Property<std::string> status;
+ chromeos::dbus_utils::Property<int32_t> progress;
+ chromeos::dbus_utils::Property<chromeos::VariantDictionary> parameters;
+ chromeos::dbus_utils::Property<chromeos::VariantDictionary> results;
private:
DISALLOW_COPY_AND_ASSIGN(CommandPropertySet);