buffet: Add State property to Manager
BUG=chromium:356368
TEST=Modified buffet_BasicDBusAPI verifies that Get and GetAll work.
Change-Id: I3af7cbbdee6d47405786420b0d00a71b0f883ec7
Reviewed-on: https://chromium-review.googlesource.com/192002
Tested-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Christopher Wiley <wiley@chromium.org>
diff --git a/buffet/manager.cc b/buffet/manager.cc
index 4daa9fc..e0a9b7a 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -28,9 +28,16 @@
dbus_constants::kManagerUpdateStateMethod,
base::Bind(&Manager::HandleUpdateState,
base::Unretained(this)));
+ properties_.reset(new Properties(exported_object));
+ // TODO(wiley): Initialize all properties appropriately before claiming
+ // the properties interface.
+ properties_->state_.SetValue("{}");
+ properties_->ClaimPropertiesInterface();
}
Manager::~Manager() {
+ // Prevent the properties object from making calls to the exported object.
+ properties_.reset(nullptr);
// Unregister ourselves from the Bus. This prevents the bus from calling
// our callbacks in between the Manager's death and the bus unregistering
// our exported object on shutdown. Unretained makes no promises of memory
@@ -89,7 +96,8 @@
}
LOG(INFO) << "Received call to Manager.UpdateState()";
- // TODO(wiley): Do something with these parameters to update state.
+ // TODO(wiley): Merge json state blobs intelligently.
+ properties_->state_.SetValue(json_state_fragment);
// Send back our response.
return dbus::Response::FromMethodCall(method_call);
diff --git a/buffet/manager.h b/buffet/manager.h
index d373a5e..cc65868 100644
--- a/buffet/manager.h
+++ b/buffet/manager.h
@@ -9,6 +9,9 @@
#include <base/memory/scoped_ptr.h>
#include <dbus/message.h>
+#include "buffet/dbus_constants.h"
+#include "buffet/exported_property_set.h"
+
namespace buffet {
class DBusManager;
@@ -22,6 +25,16 @@
~Manager();
private:
+ struct Properties: public dbus_utils::ExportedPropertySet {
+ public:
+ dbus_utils::ExportedProperty<std::string> state_;
+ Properties(dbus::ExportedObject *manager_object)
+ : dbus_utils::ExportedPropertySet(manager_object) {
+ RegisterProperty(dbus_constants::kManagerInterface, "State", &state_);
+ }
+ virtual ~Properties() {}
+ };
+
// Handles calls to org.chromium.Buffet.Manager.RegisterDevice().
scoped_ptr<dbus::Response> HandleRegisterDevice(
dbus::MethodCall* method_call);
@@ -30,6 +43,7 @@
dbus::MethodCall* method_call);
DBusManager* dbus_manager_; // Weak; DBusManager should outlive Manager.
+ scoped_ptr<Properties> properties_;
DISALLOW_COPY_AND_ASSIGN(Manager);
};