buffet: Moved D-Bus definitions to XML/Code generator
Moved D-Bus interface definitions for buffet to XML files and using
the code generator to produce adaptors/proxies. Switched over the
implementations of objects to using the generated adaptors and using
the generated proxies in buffet_client.
Some more work on proxy generator is required to switch over the
usage of Command/CommandListener in libbuffet to using the generated
proxies, since the generator does not support D-Bus properties or
Object Manager yet.
BUG=chromium:435591
TEST=FEATURES=test emerge-link buffet
Change-Id: If010ee70b356d146e4a35a7301a753c9c54377f5
Reviewed-on: https://chromium-review.googlesource.com/231350
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/dbus_command_dispatcher_unittest.cc b/buffet/commands/dbus_command_dispatcher_unittest.cc
index ed272a1..8033390 100644
--- a/buffet/commands/dbus_command_dispatcher_unittest.cc
+++ b/buffet/commands/dbus_command_dispatcher_unittest.cc
@@ -116,11 +116,11 @@
}
void FinishCommand(DBusCommandProxy* proxy) {
- proxy->HandleDone();
+ proxy->Done();
}
void SetProgress(DBusCommandProxy* proxy, int progress) {
- proxy->HandleSetProgress(nullptr, progress);
+ proxy->SetProgress(nullptr, progress);
}
diff --git a/buffet/commands/dbus_command_proxy.cc b/buffet/commands/dbus_command_proxy.cc
index 4ef94a8..2778a78 100644
--- a/buffet/commands/dbus_command_proxy.cc
+++ b/buffet/commands/dbus_command_proxy.cc
@@ -20,44 +20,20 @@
const scoped_refptr<dbus::Bus>& bus,
CommandInstance* command_instance,
std::string object_path)
- : object_path_(std::move(object_path)),
- command_instance_(command_instance),
- dbus_object_(object_manager, bus, object_path_) {
+ : command_instance_{command_instance},
+ dbus_object_{object_manager, bus, dbus::ObjectPath{object_path}} {
}
void DBusCommandProxy::RegisterAsync(
const AsyncEventSequencer::CompletionAction& completion_callback) {
- chromeos::dbus_utils::DBusInterface* itf =
- dbus_object_.AddOrGetInterface(dbus_constants::kCommandInterface);
-
- // DBus methods.
- itf->AddSimpleMethodHandlerWithError(dbus_constants::kCommandSetProgress,
- base::Unretained(this),
- &DBusCommandProxy::HandleSetProgress);
- itf->AddSimpleMethodHandler(dbus_constants::kCommandAbort,
- base::Unretained(this),
- &DBusCommandProxy::HandleAbort);
- itf->AddSimpleMethodHandler(dbus_constants::kCommandCancel,
- base::Unretained(this),
- &DBusCommandProxy::HandleCancel);
- itf->AddSimpleMethodHandler(dbus_constants::kCommandDone,
- base::Unretained(this),
- &DBusCommandProxy::HandleDone);
-
- // DBus properties.
- itf->AddProperty(dbus_constants::kCommandName, &name_);
- itf->AddProperty(dbus_constants::kCommandCategory, &category_);
- itf->AddProperty(dbus_constants::kCommandId, &id_);
- itf->AddProperty(dbus_constants::kCommandStatus, &status_);
- itf->AddProperty(dbus_constants::kCommandProgress, &progress_);
- itf->AddProperty(dbus_constants::kCommandParameters, ¶meters_);
+ dbus_adaptor_.RegisterWithDBusObject(&dbus_object_);
// Set the initial property values before registering the DBus object.
- name_.SetValue(command_instance_->GetName());
- category_.SetValue(command_instance_->GetCategory());
- id_.SetValue(command_instance_->GetID());
- status_.SetValue(command_instance_->GetStatus());
- progress_.SetValue(command_instance_->GetProgress());
+ dbus_adaptor_.SetName(command_instance_->GetName());
+ dbus_adaptor_.SetCategory(command_instance_->GetCategory());
+ dbus_adaptor_.SetId(command_instance_->GetID());
+ dbus_adaptor_.SetStatus(command_instance_->GetStatus());
+ dbus_adaptor_.SetProgress(command_instance_->GetProgress());
// Convert a string-to-PropValue map into a string-to-Any map which can be
// sent over D-Bus.
chromeos::VariantDictionary params;
@@ -65,22 +41,22 @@
params.insert(std::make_pair(param_pair.first,
param_pair.second->GetValueAsAny()));
}
- parameters_.SetValue(params);
+ dbus_adaptor_.SetParameters(params);
// Register the command DBus object and expose its methods and properties.
dbus_object_.RegisterAsync(completion_callback);
}
void DBusCommandProxy::OnStatusChanged(const std::string& status) {
- status_.SetValue(status);
+ dbus_adaptor_.SetStatus(status);
}
void DBusCommandProxy::OnProgressChanged(int progress) {
- progress_.SetValue(progress);
+ dbus_adaptor_.SetProgress(progress);
}
-bool DBusCommandProxy::HandleSetProgress(chromeos::ErrorPtr* error,
- int32_t progress) {
+bool DBusCommandProxy::SetProgress(chromeos::ErrorPtr* error,
+ int32_t progress) {
LOG(INFO) << "Received call to Command<"
<< command_instance_->GetName() << ">::SetProgress("
<< progress << ")";
@@ -95,19 +71,19 @@
return true;
}
-void DBusCommandProxy::HandleAbort() {
+void DBusCommandProxy::Abort() {
LOG(INFO) << "Received call to Command<"
<< command_instance_->GetName() << ">::Abort()";
command_instance_->Abort();
}
-void DBusCommandProxy::HandleCancel() {
+void DBusCommandProxy::Cancel() {
LOG(INFO) << "Received call to Command<"
<< command_instance_->GetName() << ">::Cancel()";
command_instance_->Cancel();
}
-void DBusCommandProxy::HandleDone() {
+void DBusCommandProxy::Done() {
LOG(INFO) << "Received call to Command<"
<< command_instance_->GetName() << ">::Done()";
command_instance_->Done();
diff --git a/buffet/commands/dbus_command_proxy.h b/buffet/commands/dbus_command_proxy.h
index 386ecaf..f3f3e4e 100644
--- a/buffet/commands/dbus_command_proxy.h
+++ b/buffet/commands/dbus_command_proxy.h
@@ -13,6 +13,7 @@
#include "buffet/commands/command_proxy_interface.h"
#include "buffet/libbuffet/dbus_constants.h"
+#include "buffet/org.chromium.Buffet.Command.h"
namespace chromeos {
namespace dbus_utils {
@@ -24,7 +25,8 @@
class CommandInstance;
-class DBusCommandProxy : public CommandProxyInterface {
+class DBusCommandProxy : public CommandProxyInterface,
+ public org::chromium::Buffet::CommandInterface {
public:
DBusCommandProxy(chromeos::dbus_utils::ExportedObjectManager* object_manager,
const scoped_refptr<dbus::Bus>& bus,
@@ -41,27 +43,17 @@
void OnProgressChanged(int progress) override;
private:
- // DBus properties for org.chromium.Buffet.Command interface.
- chromeos::dbus_utils::ExportedProperty<std::string> name_;
- chromeos::dbus_utils::ExportedProperty<std::string> category_;
- chromeos::dbus_utils::ExportedProperty<std::string> id_;
- chromeos::dbus_utils::ExportedProperty<std::string> status_;
- chromeos::dbus_utils::ExportedProperty<int32_t> progress_;
- chromeos::dbus_utils::ExportedProperty<chromeos::VariantDictionary>
- parameters_;
-
// Handles calls to org.chromium.Buffet.Command.SetProgress(progress).
- bool HandleSetProgress(chromeos::ErrorPtr* error, int32_t progress);
+ bool SetProgress(chromeos::ErrorPtr* error, int32_t progress) override;
// Handles calls to org.chromium.Buffet.Command.Abort().
- void HandleAbort();
+ void Abort() override;
// Handles calls to org.chromium.Buffet.Command.Cancel().
- void HandleCancel();
+ void Cancel() override;
// Handles calls to org.chromium.Buffet.Command.Done().
- void HandleDone();
+ void Done() override;
- dbus::ObjectPath object_path_;
CommandInstance* command_instance_;
-
+ org::chromium::Buffet::CommandAdaptor dbus_adaptor_{this};
chromeos::dbus_utils::DBusObject dbus_object_;
friend class DBusCommandProxyTest;
diff --git a/buffet/commands/dbus_command_proxy_unittest.cc b/buffet/commands/dbus_command_proxy_unittest.cc
index 81d9827..a810464 100644
--- a/buffet/commands/dbus_command_proxy_unittest.cc
+++ b/buffet/commands/dbus_command_proxy_unittest.cc
@@ -118,15 +118,15 @@
}
std::string GetStatus() const {
- return GetCommandProxy()->status_.value();
+ return GetCommandProxy()->dbus_adaptor_.GetStatus();
}
int32_t GetProgress() const {
- return GetCommandProxy()->progress_.value();
+ return GetCommandProxy()->dbus_adaptor_.GetProgress();
}
VariantDictionary GetParameters() const {
- return GetCommandProxy()->parameters_.value();
+ return GetCommandProxy()->dbus_adaptor_.GetParameters();
}
std::unique_ptr<dbus::Response> CallMethod(