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/buffet.gyp b/buffet/buffet.gyp index 12f4300..5072ba5 100644 --- a/buffet/buffet.gyp +++ b/buffet/buffet.gyp
@@ -19,11 +19,32 @@ 'libbuffet/dbus_constants.cc', 'libbuffet/private/command_property_set.cc', ], + 'actions': [ + { + 'action_name': 'generate-buffet-proxies', + 'inputs': [ + 'dbus_bindings/org.chromium.Buffet.Command.xml', + 'dbus_bindings/org.chromium.Buffet.Manager.xml', + ], + 'outputs': [ + '<(SHARED_INTERMEDIATE_DIR)/include/buffet/dbus-proxies.h', + ], + 'action': [ + '<!(which generate-chromeos-dbus-bindings)', + '>@(_inputs)', + '--proxy=>(_outputs)' + ], + 'hard_dependency': 1, + }, + ], 'includes': ['../common-mk/deps.gypi'], }, { 'target_name': 'buffet_common', 'type': 'static_library', + 'variables': { + 'dbus_adaptors_out_dir': 'include/buffet', + }, 'sources': [ 'commands/command_definition.cc', 'commands/command_dictionary.cc', @@ -40,6 +61,8 @@ 'commands/schema_constants.cc', 'commands/schema_utils.cc', 'device_registration_info.cc', + 'dbus_bindings/org.chromium.Buffet.Command.xml', + 'dbus_bindings/org.chromium.Buffet.Manager.xml', 'manager.cc', 'storage_impls.cc', 'states/error_codes.cc', @@ -48,6 +71,7 @@ 'states/state_package.cc', 'utils.cc', ], + 'includes': ['../common-mk/generate-dbus-adaptors.gypi'], }, { 'target_name': 'buffet',
diff --git a/buffet/buffet_client.cc b/buffet/buffet_client.cc index e32082d..72e3c88 100644 --- a/buffet/buffet_client.cc +++ b/buffet/buffet_client.cc
@@ -23,6 +23,7 @@ #include <dbus/object_manager.h> #include <dbus/values_util.h> +#include "buffet/dbus-proxies.h" #include "buffet/libbuffet/dbus_constants.h" using namespace buffet::dbus_constants; // NOLINT(build/namespaces) @@ -57,13 +58,13 @@ dbus::Bus::Options options; options.bus_type = dbus::Bus::SYSTEM; bus_ = new dbus::Bus(options); - manager_proxy_ = bus_->GetObjectProxy( - kServiceName, - dbus::ObjectPath(kManagerServicePath)); + manager_proxy_.reset( + new org::chromium::Buffet::ManagerProxy{bus_, kServiceName, + kManagerServicePath}); root_proxy_ = bus_->GetObjectProxy( kServiceName, dbus::ObjectPath(kRootServicePath)); - return EX_OK; + return EX_OK; } int CallTestMethod(const CommandLine::StringVector& args) { @@ -72,13 +73,8 @@ message = args.front(); ErrorPtr error; - auto response = CallMethodAndBlock( - manager_proxy_, - kManagerInterface, kManagerTestMethod, &error, - message); std::string response_message; - if (!response || - !ExtractMethodCallResults(response.get(), &error, &response_message)) { + if (!manager_proxy_->TestMethod(message, &response_message, &error)) { std::cout << "Failed to receive a response:" << error->GetMessage() << std::endl; return EX_UNAVAILABLE; @@ -97,14 +93,12 @@ } ErrorPtr error; - auto response = CallMethodAndBlock( - manager_proxy_, - kManagerInterface, kManagerStartDevice, &error); - if (!response || !ExtractMethodCallResults(response.get(), &error)) { + if (!manager_proxy_->StartDevice(&error)) { std::cout << "Failed to receive a response:" << error->GetMessage() << std::endl; return EX_UNAVAILABLE; } + return EX_OK; } @@ -117,12 +111,8 @@ } ErrorPtr error; - auto response = CallMethodAndBlock( - manager_proxy_, - kManagerInterface, kManagerCheckDeviceRegistered, &error); std::string device_id; - if (!response || - !ExtractMethodCallResults(response.get(), &error, &device_id)) { + if (!manager_proxy_->CheckDeviceRegistered(&device_id, &error)) { std::cout << "Failed to receive a response:" << error->GetMessage() << std::endl; return EX_UNAVAILABLE; @@ -143,11 +133,8 @@ } ErrorPtr error; - auto response = CallMethodAndBlock( - manager_proxy_, kManagerInterface, kManagerGetDeviceInfo, &error); std::string device_info; - if (!response || - !ExtractMethodCallResults(response.get(), &error, &device_info)) { + if (!manager_proxy_->GetDeviceInfo(&device_info, &error)) { std::cout << "Failed to receive a response:" << error->GetMessage() << std::endl; return EX_UNAVAILABLE; @@ -176,15 +163,8 @@ } ErrorPtr error; - static const int timeout_ms = 3000; - auto response = CallMethodAndBlockWithTimeout( - timeout_ms, - manager_proxy_, - kManagerInterface, kManagerRegisterDevice, &error, - params); std::string device_id; - if (!response || - !ExtractMethodCallResults(response.get(), &error, &device_id)) { + if (!manager_proxy_->RegisterDevice(params, &device_id, &error)) { std::cout << "Failed to receive a response:" << error->GetMessage() << std::endl; return EX_UNAVAILABLE; @@ -204,11 +184,7 @@ ErrorPtr error; VariantDictionary property_set{{args.front(), args.back()}}; - auto response = CallMethodAndBlock( - manager_proxy_, - kManagerInterface, kManagerUpdateStateMethod, &error, - property_set); - if (!response || !ExtractMethodCallResults(response.get(), &error)) { + if (!manager_proxy_->UpdateState(property_set, &error)) { std::cout << "Failed to receive a response:" << error->GetMessage() << std::endl; return EX_UNAVAILABLE; @@ -225,11 +201,7 @@ } ErrorPtr error; - auto response = CallMethodAndBlock( - manager_proxy_, - kManagerInterface, kManagerAddCommand, &error, - args.front()); - if (!response || !ExtractMethodCallResults(response.get(), &error)) { + if (!manager_proxy_->AddCommand(args.front(), &error)) { std::cout << "Failed to receive a response:" << error->GetMessage() << std::endl; return EX_UNAVAILABLE; @@ -247,7 +219,7 @@ ErrorPtr error; auto response = CallMethodAndBlock( - manager_proxy_, + root_proxy_, dbus::kObjectManagerInterface, dbus::kObjectManagerGetManagedObjects, &error); if (!response) { @@ -261,7 +233,7 @@ private: scoped_refptr<dbus::Bus> bus_; - dbus::ObjectProxy* manager_proxy_{nullptr}; + std::unique_ptr<org::chromium::Buffet::ManagerProxy> manager_proxy_; dbus::ObjectProxy* root_proxy_{nullptr}; };
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(
diff --git a/buffet/dbus_bindings/org.chromium.Buffet.Command.xml b/buffet/dbus_bindings/org.chromium.Buffet.Command.xml new file mode 100644 index 0000000..89d9efd --- /dev/null +++ b/buffet/dbus_bindings/org.chromium.Buffet.Command.xml
@@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<node name="/" + xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="org.chromium.Buffet.Command"> + <method name="SetProgress"> + <arg name="progress" type="i" direction="in"/> + <annotation name="org.chromium.DBus.Method.Kind" value="normal"/> + </method> + <method name="Abort"> + <annotation name="org.chromium.DBus.Method.Kind" value="simple"/> + </method> + <method name="Cancel"> + <annotation name="org.chromium.DBus.Method.Kind" value="simple"/> + </method> + <method name="Done"> + <annotation name="org.chromium.DBus.Method.Kind" value="simple"/> + </method> + <property name="Name" type="s" access="read"/> + <property name="Category" type="s" access="read"/> + <property name="Id" type="s" access="read"/> + <property name="Status" type="s" access="read"/> + <property name="Progress" type="i" access="read"/> + <property name="Parameters" type="a{sv}" access="read"/> + </interface> +</node>
diff --git a/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml b/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml new file mode 100644 index 0000000..4490dac --- /dev/null +++ b/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml
@@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<node name="/org/chromium/Buffet/Manager" + xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="org.chromium.Buffet.Manager"> + <tp:docstring> + The Manager is responsible for global state of Buffet. It exposes + interfaces which affect the entire device such as device registration and + device state. + </tp:docstring> + <method name="StartDevice"> + <annotation name="org.chromium.DBus.Method.Kind" value="async"/> + </method> + <method name="CheckDeviceRegistered"> + <arg name="device_id" type="s" direction="out"/> + <annotation name="org.chromium.DBus.Method.Kind" value="async"/> + </method> + <method name="GetDeviceInfo"> + <arg name="device_info" type="s" direction="out"/> + <annotation name="org.chromium.DBus.Method.Kind" value="async"/> + </method> + <method name="RegisterDevice"> + <arg name="params" type="a{sv}" direction="in"/> + <arg name="device_id" type="s" direction="out"/> + <annotation name="org.chromium.DBus.Method.Kind" value="async"/> + </method> + <method name="UpdateState"> + <arg name="property_set" type="a{sv}" direction="in"/> + <annotation name="org.chromium.DBus.Method.Kind" value="async"/> + </method> + <method name="AddCommand"> + <arg name="json_command" type="s" direction="in"/> + <annotation name="org.chromium.DBus.Method.Kind" value="async"/> + </method> + <method name="TestMethod"> + <arg name="message" type="s" direction="in"/> + <arg name="echoed_message" type="s" direction="out"/> + <annotation name="org.chromium.DBus.Method.Kind" value="simple"/> + </method> + </interface> +</node>
diff --git a/buffet/manager.cc b/buffet/manager.cc index 071b861..13ca49f 100644 --- a/buffet/manager.cc +++ b/buffet/manager.cc
@@ -25,7 +25,6 @@ #include "buffet/states/state_manager.h" using chromeos::dbus_utils::AsyncEventSequencer; -using chromeos::dbus_utils::DBusMethodResponse; using chromeos::dbus_utils::ExportedObjectManager; namespace buffet { @@ -43,30 +42,6 @@ Manager::~Manager() {} void Manager::RegisterAsync(const AsyncEventSequencer::CompletionAction& cb) { - chromeos::dbus_utils::DBusInterface* itf = - dbus_object_.AddOrGetInterface(dbus_constants::kManagerInterface); - itf->AddMethodHandler(dbus_constants::kManagerStartDevice, - base::Unretained(this), - &Manager::HandleStartDevice); - itf->AddMethodHandler(dbus_constants::kManagerCheckDeviceRegistered, - base::Unretained(this), - &Manager::HandleCheckDeviceRegistered); - itf->AddMethodHandler(dbus_constants::kManagerGetDeviceInfo, - base::Unretained(this), - &Manager::HandleGetDeviceInfo); - itf->AddMethodHandler(dbus_constants::kManagerRegisterDevice, - base::Unretained(this), - &Manager::HandleRegisterDevice); - itf->AddMethodHandler(dbus_constants::kManagerUpdateStateMethod, - base::Unretained(this), - &Manager::HandleUpdateState); - itf->AddMethodHandler(dbus_constants::kManagerAddCommand, - base::Unretained(this), - &Manager::HandleAddCommand); - itf->AddSimpleMethodHandler(dbus_constants::kManagerTestMethod, - base::Unretained(this), - &Manager::HandleTestMethod); - dbus_object_.RegisterAsync(cb); command_manager_ = std::make_shared<CommandManager>(dbus_object_.GetObjectManager()); command_manager_->Startup(); @@ -77,9 +52,11 @@ device_info_ = std::unique_ptr<DeviceRegistrationInfo>( new DeviceRegistrationInfo(command_manager_, state_manager_)); device_info_->Load(); + dbus_adaptor_.RegisterWithDBusObject(&dbus_object_); + dbus_object_.RegisterAsync(cb); } -void Manager::HandleStartDevice(scoped_ptr<DBusMethodResponse<>> response) { +void Manager::StartDevice(DBusMethodResponse<> response) { LOG(INFO) << "Received call to Manager.StartDevice()"; chromeos::ErrorPtr error; @@ -90,8 +67,7 @@ response->Return(); } -void Manager::HandleCheckDeviceRegistered( - scoped_ptr<DBusMethodResponse<std::string>> response) { +void Manager::CheckDeviceRegistered(DBusMethodResponse<std::string> response) { LOG(INFO) << "Received call to Manager.CheckDeviceRegistered()"; chromeos::ErrorPtr error; bool registered = device_info_->CheckRegistration(&error); @@ -116,8 +92,7 @@ response->Return(device_id); } -void Manager::HandleGetDeviceInfo( - scoped_ptr<DBusMethodResponse<std::string>> response) { +void Manager::GetDeviceInfo(DBusMethodResponse<std::string> response) { LOG(INFO) << "Received call to Manager.GetDeviceInfo()"; chromeos::ErrorPtr error; @@ -132,22 +107,31 @@ response->Return(device_info_str); } -void Manager::HandleRegisterDevice( - scoped_ptr<DBusMethodResponse<std::string>> response, - const std::map<std::string, std::string>& params) { +void Manager::RegisterDevice(DBusMethodResponse<std::string> response, + const chromeos::VariantDictionary& params) { LOG(INFO) << "Received call to Manager.RegisterDevice()"; chromeos::ErrorPtr error; - std::string device_id = device_info_->RegisterDevice(params, &error); + std::map<std::string, std::string> str_params; + for (const auto& pair : params) { + if (!pair.second.IsTypeCompatible<std::string>()) { + response->ReplyWithError(FROM_HERE, chromeos::errors::dbus::kDomain, + DBUS_ERROR_INVALID_ARGS, + "String value expected"); + return; + } + str_params.emplace_hint(str_params.end(), + pair.first, pair.second.Get<std::string>()); + } + std::string device_id = device_info_->RegisterDevice(str_params, &error); if (error) response->ReplyWithError(error.get()); else response->Return(device_id); } -void Manager::HandleUpdateState( - scoped_ptr<DBusMethodResponse<>> response, - const chromeos::VariantDictionary& property_set) { +void Manager::UpdateState(DBusMethodResponse<> response, + const chromeos::VariantDictionary& property_set) { chromeos::ErrorPtr error; base::Time timestamp = base::Time::Now(); bool all_success = true; @@ -165,8 +149,8 @@ response->Return(); } -void Manager::HandleAddCommand(scoped_ptr<DBusMethodResponse<>> response, - const std::string& json_command) { +void Manager::AddCommand(DBusMethodResponse<> response, + const std::string& json_command) { static int next_id = 0; std::string error_message; std::unique_ptr<base::Value> value(base::JSONReader::ReadAndReturnError( @@ -189,7 +173,7 @@ response->Return(); } -std::string Manager::HandleTestMethod(const std::string& message) { +std::string Manager::TestMethod(const std::string& message) { LOG(INFO) << "Received call to test method: " << message; return message; }
diff --git a/buffet/manager.h b/buffet/manager.h index bcc0425..318ee74 100644 --- a/buffet/manager.h +++ b/buffet/manager.h
@@ -18,6 +18,7 @@ #include <chromeos/errors/error.h> #include "buffet/device_registration_info.h" +#include "buffet/org.chromium.Buffet.Manager.h" namespace chromeos { namespace dbus_utils { @@ -31,10 +32,14 @@ class StateChangeQueue; class StateManager; +template<typename... Types> +using DBusMethodResponse = + scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>; + // The Manager is responsible for global state of Buffet. It exposes // interfaces which affect the entire device such as device registration and // device state. -class Manager final { +class Manager final : public org::chromium::Buffet::ManagerInterface { public: explicit Manager( const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>& @@ -47,32 +52,24 @@ private: // DBus methods: // Handles calls to org.chromium.Buffet.Manager.StartDevice(). - void HandleStartDevice( - scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response); + void StartDevice(DBusMethodResponse<> response) override; // Handles calls to org.chromium.Buffet.Manager.CheckDeviceRegistered(). - void HandleCheckDeviceRegistered( - scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<std::string>> - response); + void CheckDeviceRegistered(DBusMethodResponse<std::string> response) override; // Handles calls to org.chromium.Buffet.Manager.GetDeviceInfo(). - void HandleGetDeviceInfo( - scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<std::string>> - response); + void GetDeviceInfo(DBusMethodResponse<std::string> response) override; // Handles calls to org.chromium.Buffet.Manager.RegisterDevice(). - void HandleRegisterDevice( - scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<std::string>> - response, - const std::map<std::string, std::string>& params); + void RegisterDevice(DBusMethodResponse<std::string> response, + const chromeos::VariantDictionary& params) override; // Handles calls to org.chromium.Buffet.Manager.UpdateState(). - void HandleUpdateState( - scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response, - const chromeos::VariantDictionary& property_set); + void UpdateState(DBusMethodResponse<> response, + const chromeos::VariantDictionary& property_set) override; // Handles calls to org.chromium.Buffet.Manager.AddCommand(). - void HandleAddCommand( - scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response, - const std::string& json_command); + void AddCommand(DBusMethodResponse<> response, + const std::string& json_command) override; // Handles calls to org.chromium.Buffet.Manager.Test() - std::string HandleTestMethod(const std::string& message); + std::string TestMethod(const std::string& message) override; + org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this}; chromeos::dbus_utils::DBusObject dbus_object_; std::shared_ptr<CommandManager> command_manager_;