buffet: Remove libbuffet and rely on generated proxies
libbuffet functionality is no longer needed since the D-Bus code
generator is sufficient to provide the fully-functional proxy
objects for commands and buffet's object manager.
Also pretty much rewrote buffet_client. A lot of D-Bus
functionality in libchrome relies on the message loop and
asyncronous operations (e.g. Object Manager is constructed
asyncronously and it would crash if there is no message loop
for the main thread). So, made the buffet_client a "real"
application with a message loop that sends D-Bus requests
asynchronously.
BUG=chromium:431737
TEST=FEATURES=test emerge-link buffet
CQ-DEPEND=CL:232850
Change-Id: Ibf53369b502efa9b9d0e233fbcdf3331993e4f6a
Reviewed-on: https://chromium-review.googlesource.com/232533
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/buffet.gyp b/buffet/buffet.gyp
index c928ec4..d4c4541 100644
--- a/buffet/buffet.gyp
+++ b/buffet/buffet.gyp
@@ -11,31 +11,6 @@
},
'targets': [
{
- 'target_name': 'libbuffet-<(libbase_ver)',
- 'type': 'shared_library',
- 'sources': [
- 'libbuffet/command.cc',
- 'libbuffet/command_listener.cc',
- 'libbuffet/dbus_constants.cc',
- 'libbuffet/private/command_property_set.cc',
- ],
- 'actions': [
- {
- 'action_name': 'generate-buffet-proxies',
- 'variables': {
- 'dbus_service_config': 'dbus_bindings/dbus-service-config.json',
- 'proxy_output_file': 'include/buffet/dbus-proxies.h'
- },
- 'sources': [
- 'dbus_bindings/org.chromium.Buffet.Command.xml',
- 'dbus_bindings/org.chromium.Buffet.Manager.xml',
- ],
- 'includes': ['../common-mk/generate-dbus-proxies.gypi'],
- },
- ],
- 'includes': ['../common-mk/deps.gypi'],
- },
- {
'target_name': 'buffet_common',
'type': 'static_library',
'variables': {
@@ -60,6 +35,7 @@
'device_registration_info.cc',
'dbus_bindings/org.chromium.Buffet.Command.xml',
'dbus_bindings/org.chromium.Buffet.Manager.xml',
+ 'dbus_constants.cc',
'manager.cc',
'storage_impls.cc',
'states/error_codes.cc',
@@ -69,13 +45,26 @@
'utils.cc',
],
'includes': ['../common-mk/generate-dbus-adaptors.gypi'],
+ 'actions': [
+ {
+ 'action_name': 'generate-buffet-proxies',
+ 'variables': {
+ 'dbus_service_config': 'dbus_bindings/dbus-service-config.json',
+ 'proxy_output_file': 'include/buffet/dbus-proxies.h'
+ },
+ 'sources': [
+ 'dbus_bindings/org.chromium.Buffet.Command.xml',
+ 'dbus_bindings/org.chromium.Buffet.Manager.xml',
+ ],
+ 'includes': ['../common-mk/generate-dbus-proxies.gypi'],
+ },
+ ],
},
{
'target_name': 'buffet',
'type': 'executable',
'dependencies': [
'buffet_common',
- 'libbuffet-<(libbase_ver)',
],
'sources': [
'main.cc',
@@ -84,9 +73,6 @@
{
'target_name': 'buffet_test_daemon',
'type': 'executable',
- 'dependencies': [
- 'libbuffet-<(libbase_ver)',
- ],
'sources': [
'test_daemon/main.cc',
],
@@ -94,9 +80,6 @@
{
'target_name': 'buffet_client',
'type': 'executable',
- 'dependencies': [
- 'libbuffet-<(libbase_ver)',
- ],
'sources': [
'buffet_client.cc',
],
@@ -110,7 +93,6 @@
'type': 'executable',
'dependencies': [
'buffet_common',
- 'libbuffet-<(libbase_ver)',
],
'variables': {
'deps': [
diff --git a/buffet/buffet_client.cc b/buffet/buffet_client.cc
index 3edbbc3..ca91cee 100644
--- a/buffet/buffet_client.cc
+++ b/buffet/buffet_client.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <iostream> // NOLINT(readability/streams)
#include <memory>
#include <string>
#include <sysexits.h>
@@ -10,8 +9,10 @@
#include <base/command_line.h>
#include <base/logging.h>
#include <base/memory/ref_counted.h>
+#include <base/strings/stringprintf.h>
#include <base/values.h>
#include <chromeos/any.h>
+#include <chromeos/daemons/dbus_daemon.h>
#include <chromeos/data_encoding.h>
#include <chromeos/dbus/data_serialization.h>
#include <chromeos/dbus/dbus_method_invoker.h>
@@ -24,137 +25,183 @@
#include <dbus/values_util.h>
#include "buffet/dbus-proxies.h"
-#include "buffet/libbuffet/dbus_constants.h"
-using namespace buffet::dbus_constants; // NOLINT(build/namespaces)
-
-using chromeos::dbus_utils::CallMethodAndBlock;
-using chromeos::dbus_utils::CallMethodAndBlockWithTimeout;
-using chromeos::dbus_utils::ExtractMethodCallResults;
-using chromeos::VariantDictionary;
+using chromeos::Error;
using chromeos::ErrorPtr;
namespace {
void usage() {
- std::cerr << "Possible commands:" << std::endl;
- std::cerr << " " << kManagerTestMethod << " <message>" << std::endl;
- std::cerr << " " << kManagerStartDevice << std::endl;
- std::cerr << " " << kManagerCheckDeviceRegistered << std::endl;
- std::cerr << " " << kManagerGetDeviceInfo << std::endl;
- std::cerr << " " << kManagerRegisterDevice
- << " param1 = val1¶m2 = val2..." << std::endl;
- std::cerr << " " << kManagerAddCommand
- << " '{\"name\":\"command_name\",\"parameters\":{}}'"
- << std::endl;
- std::cerr << " " << kManagerUpdateStateMethod
- << " prop_name prop_value" << std::endl;
- std::cerr << " " << dbus::kObjectManagerGetManagedObjects << std::endl;
+ printf(R"(Possible commands:
+ - TestMethod <message>
+ - StartDevice
+ - CheckDeviceRegistered
+ - GetDeviceInfo
+ - RegisterDevice param1=val1¶m2=val2...
+ - AddCommand '{"name":"command_name","parameters":{}}'
+ - UpdateStateMethod prop_name prop_value
+ - PendingCommands
+)");
}
-class BuffetHelperProxy {
+class Daemon : public chromeos::DBusDaemon {
public:
- int Init() {
- dbus::Bus::Options options;
- options.bus_type = dbus::Bus::SYSTEM;
- bus_ = new dbus::Bus(options);
+ Daemon() = default;
+
+ protected:
+ int OnInit() override {
+ int return_code = chromeos::DBusDaemon::OnInit();
+ if (return_code != EX_OK)
+ return return_code;
+
+ object_manager_.reset(new org::chromium::Buffet::ObjectManagerProxy{bus_});
manager_proxy_.reset(new org::chromium::Buffet::ManagerProxy{bus_});
- root_proxy_ = bus_->GetObjectProxy(
- kServiceName,
- dbus::ObjectPath(kRootServicePath));
- return EX_OK;
+
+ auto args = CommandLine::ForCurrentProcess()->GetArgs();
+
+ // Pop the command off of the args list.
+ std::string command = args.front();
+ args.erase(args.begin());
+
+ if (command.compare("TestMethod") == 0) {
+ if (args.empty() || CheckArgs(command, args, 1)) {
+ std::string message;
+ if (!args.empty())
+ message = args.back();
+ PostTask(&Daemon::CallTestMethod, message);
+ }
+ } else if (command.compare("StartDevice") == 0 ||
+ command.compare("sd") == 0) {
+ if (CheckArgs(command, args, 0))
+ PostTask(&Daemon::CallStartDevice);
+ } else if (command.compare("CheckDeviceRegistered") == 0 ||
+ command.compare("cr") == 0) {
+ if (CheckArgs(command, args, 0))
+ PostTask(&Daemon::CallCheckDeviceRegistered);
+ } else if (command.compare("GetDeviceInfo") == 0 ||
+ command.compare("di") == 0) {
+ if (CheckArgs(command, args, 0))
+ PostTask(&Daemon::CallGetDeviceInfo);
+ } else if (command.compare("RegisterDevice") == 0 ||
+ command.compare("rd") == 0) {
+ if (args.empty() || CheckArgs(command, args, 1)) {
+ std::string dict;
+ if (!args.empty())
+ dict = args.back();
+ PostTask(&Daemon::CallRegisterDevice, dict);
+ }
+ } else if (command.compare("UpdateState") == 0 ||
+ command.compare("us") == 0) {
+ if (CheckArgs(command, args, 2))
+ PostTask(&Daemon::CallUpdateState, args.front(), args.back());
+ } else if (command.compare("AddCommand") == 0 ||
+ command.compare("ac") == 0) {
+ if (CheckArgs(command, args, 1))
+ PostTask(&Daemon::CallAddCommand, args.back());
+ } else if (command.compare("PendingCommands") == 0 ||
+ command.compare("pc") == 0) {
+ if (CheckArgs(command, args, 0))
+ // CallGetPendingCommands relies on ObjectManager but it is being
+ // initialized asynchronously without a way to get a callback when
+ // it is ready to be used. So, just wait a bit before calling its
+ // methods.
+ PostDelayedTask(&Daemon::CallGetPendingCommands,
+ base::TimeDelta::FromMilliseconds(100));
+ } else {
+ fprintf(stderr, "Unknown command: '%s'\n", command.c_str());
+ usage();
+ Quit();
+ return EX_USAGE;
+ }
+ return EX_OK;
}
- int CallTestMethod(const CommandLine::StringVector& args) {
- std::string message;
- if (!args.empty())
- message = args.front();
+ void OnShutdown(int* return_code) override {
+ if (*return_code == EX_OK)
+ *return_code = exit_code_;
+ }
+ private:
+ void ReportError(Error* error) {
+ fprintf(stderr, "Failed to receive a response: %s\n",
+ error->GetMessage().c_str());
+ exit_code_ = EX_UNAVAILABLE;
+ Quit();
+ }
+
+ bool CheckArgs(const std::string& command,
+ const std::vector<std::string>& args,
+ size_t expected_arg_count) {
+ if (args.size() == expected_arg_count)
+ return true;
+ fprintf(stderr, "Invalid number of arguments for command '%s'\n",
+ command.c_str());
+ usage();
+ exit_code_ = EX_USAGE;
+ Quit();
+ return false;
+ }
+
+ template<typename... Args>
+ void PostTask(void (Daemon::*fn)(const Args&...), const Args&... args) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(fn, base::Unretained(this), args...));
+ }
+
+ template<typename... Args>
+ void PostDelayedTask(void (Daemon::*fn)(const Args&...),
+ const base::TimeDelta& delay,
+ const Args&... args) {
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, base::Bind(fn, base::Unretained(this), args...), delay);
+ }
+
+ void CallTestMethod(const std::string& message) {
ErrorPtr error;
std::string response_message;
if (!manager_proxy_->TestMethod(message, &response_message, &error)) {
- std::cout << "Failed to receive a response:"
- << error->GetMessage() << std::endl;
- return EX_UNAVAILABLE;
+ return ReportError(error.get());
}
-
- std::cout << "Received a response: " << response_message << std::endl;
- return EX_OK;
+ printf("Received a response: %s\n", response_message.c_str());
+ Quit();
}
- int CallManagerStartDevice(const CommandLine::StringVector& args) {
- if (!args.empty()) {
- std::cerr << "Invalid number of arguments for "
- << "Manager." << kManagerStartDevice << std::endl;
- usage();
- return EX_USAGE;
- }
-
+ void CallStartDevice() {
ErrorPtr error;
if (!manager_proxy_->StartDevice(&error)) {
- std::cout << "Failed to receive a response:"
- << error->GetMessage() << std::endl;
- return EX_UNAVAILABLE;
+ return ReportError(error.get());
}
-
- return EX_OK;
+ Quit();
}
- int CallManagerCheckDeviceRegistered(const CommandLine::StringVector& args) {
- if (!args.empty()) {
- std::cerr << "Invalid number of arguments for "
- << "Manager." << kManagerCheckDeviceRegistered << std::endl;
- usage();
- return EX_USAGE;
- }
-
+ void CallCheckDeviceRegistered() {
ErrorPtr error;
std::string device_id;
if (!manager_proxy_->CheckDeviceRegistered(&device_id, &error)) {
- std::cout << "Failed to receive a response:"
- << error->GetMessage() << std::endl;
- return EX_UNAVAILABLE;
+ return ReportError(error.get());
}
- std::cout << "Device ID: "
- << (device_id.empty() ? std::string("<unregistered>") : device_id)
- << std::endl;
- return EX_OK;
+ printf("Device ID: %s\n",
+ device_id.empty() ? "<unregistered>" : device_id.c_str());
+ Quit();
}
- int CallManagerGetDeviceInfo(const CommandLine::StringVector& args) {
- if (!args.empty()) {
- std::cerr << "Invalid number of arguments for "
- << "Manager." << kManagerGetDeviceInfo << std::endl;
- usage();
- return EX_USAGE;
- }
-
+ void CallGetDeviceInfo() {
ErrorPtr error;
std::string device_info;
if (!manager_proxy_->GetDeviceInfo(&device_info, &error)) {
- std::cout << "Failed to receive a response:"
- << error->GetMessage() << std::endl;
- return EX_UNAVAILABLE;
+ return ReportError(error.get());
}
- std::cout << "Device Info: "
- << (device_info.empty() ? std::string("<unregistered>") : device_info)
- << std::endl;
- return EX_OK;
+ printf("Device Info: %s\n",
+ device_info.empty() ? "<unregistered>" : device_info.c_str());
+ Quit();
}
- int CallManagerRegisterDevice(const CommandLine::StringVector& args) {
- if (args.size() > 1) {
- std::cerr << "Invalid number of arguments for "
- << "Manager." << kManagerRegisterDevice << std::endl;
- usage();
- return EX_USAGE;
- }
-
- VariantDictionary params;
+ void CallRegisterDevice(const std::string& args) {
+ chromeos::VariantDictionary params;
if (!args.empty()) {
- auto key_values = chromeos::data_encoding::WebParamsDecode(args.front());
+ auto key_values = chromeos::data_encoding::WebParamsDecode(args);
for (const auto& pair : key_values) {
params.insert(std::make_pair(pair.first, chromeos::Any(pair.second)));
}
@@ -163,79 +210,50 @@
ErrorPtr error;
std::string device_id;
if (!manager_proxy_->RegisterDevice(params, &device_id, &error)) {
- std::cout << "Failed to receive a response:"
- << error->GetMessage() << std::endl;
- return EX_UNAVAILABLE;
+ return ReportError(error.get());
}
- std::cout << "Device registered: " << device_id << std::endl;
- return EX_OK;
+ printf("Device registered: %s\n", device_id.c_str());
+ Quit();
}
- int CallManagerUpdateState(const CommandLine::StringVector& args) {
- if (args.size() != 2) {
- std::cerr << "Invalid number of arguments for "
- << "Manager." << kManagerUpdateStateMethod << std::endl;
- usage();
- return EX_USAGE;
- }
-
+ void CallUpdateState(const std::string& prop, const std::string& value) {
ErrorPtr error;
- VariantDictionary property_set{{args.front(), args.back()}};
+ chromeos::VariantDictionary property_set{{prop, value}};
if (!manager_proxy_->UpdateState(property_set, &error)) {
- std::cout << "Failed to receive a response:"
- << error->GetMessage() << std::endl;
- return EX_UNAVAILABLE;
+ return ReportError(error.get());
}
- return EX_OK;
+ Quit();
}
- int CallManagerAddCommand(const CommandLine::StringVector& args) {
- if (args.size() != 1) {
- std::cerr << "Invalid number of arguments for "
- << "Manager." << kManagerAddCommand << std::endl;
- usage();
- return EX_USAGE;
- }
-
+ void CallAddCommand(const std::string& command) {
ErrorPtr error;
- if (!manager_proxy_->AddCommand(args.front(), &error)) {
- std::cout << "Failed to receive a response:"
- << error->GetMessage() << std::endl;
- return EX_UNAVAILABLE;
+ if (!manager_proxy_->AddCommand(command, &error)) {
+ return ReportError(error.get());
}
- return EX_OK;
+ Quit();
}
- int CallRootGetManagedObjects(const CommandLine::StringVector& args) {
- if (!args.empty()) {
- std::cerr << "Invalid number of arguments for "
- << dbus::kObjectManagerGetManagedObjects << std::endl;
- usage();
- return EX_USAGE;
+ void CallGetPendingCommands() {
+ printf("Pending commands:\n");
+ for (auto* cmd : object_manager_->GetCommandInstances()) {
+ printf("%10s (%-3d) - '%s' (id:%s)\n",
+ cmd->status().c_str(),
+ cmd->progress(),
+ cmd->name().c_str(),
+ cmd->id().c_str());
}
-
- ErrorPtr error;
- auto response = CallMethodAndBlock(
- root_proxy_,
- dbus::kObjectManagerInterface, dbus::kObjectManagerGetManagedObjects,
- &error);
- if (!response) {
- std::cout << "Failed to receive a response:"
- << error->GetMessage() << std::endl;
- return EX_UNAVAILABLE;
- }
- std::cout << response->ToString() << std::endl;
- return EX_OK;
+ Quit();
}
- private:
- scoped_refptr<dbus::Bus> bus_;
+ std::unique_ptr<org::chromium::Buffet::ObjectManagerProxy> object_manager_;
std::unique_ptr<org::chromium::Buffet::ManagerProxy> manager_proxy_;
- dbus::ObjectProxy* root_proxy_{nullptr};
+ int exit_code_ = EX_OK;
+
+ DISALLOW_COPY_AND_ASSIGN(Daemon);
};
-} // namespace
+} // anonymous namespace
int main(int argc, char** argv) {
CommandLine::Init(argc, argv);
@@ -246,48 +264,6 @@
return EX_USAGE;
}
- // Pop the command off of the args list.
- std::string command = args.front();
- args.erase(args.begin());
- int err = EX_USAGE;
- BuffetHelperProxy helper;
- err = helper.Init();
- if (err) {
- std::cerr << "Error initializing proxies." << std::endl;
- return err;
- }
-
- if (command.compare(kManagerTestMethod) == 0) {
- err = helper.CallTestMethod(args);
- } else if (command.compare(kManagerStartDevice) == 0 ||
- command.compare("sd") == 0) {
- err = helper.CallManagerStartDevice(args);
- } else if (command.compare(kManagerCheckDeviceRegistered) == 0 ||
- command.compare("cr") == 0) {
- err = helper.CallManagerCheckDeviceRegistered(args);
- } else if (command.compare(kManagerGetDeviceInfo) == 0 ||
- command.compare("di") == 0) {
- err = helper.CallManagerGetDeviceInfo(args);
- } else if (command.compare(kManagerRegisterDevice) == 0 ||
- command.compare("rd") == 0) {
- err = helper.CallManagerRegisterDevice(args);
- } else if (command.compare(kManagerUpdateStateMethod) == 0 ||
- command.compare("us") == 0) {
- err = helper.CallManagerUpdateState(args);
- } else if (command.compare(kManagerAddCommand) == 0 ||
- command.compare("ac") == 0) {
- err = helper.CallManagerAddCommand(args);
- } else if (command.compare(dbus::kObjectManagerGetManagedObjects) == 0) {
- err = helper.CallRootGetManagedObjects(args);
- } else {
- std::cerr << "Unknown command: " << command << std::endl;
- usage();
- }
-
- if (err) {
- std::cerr << "Done, with errors." << std::endl;
- } else {
- std::cout << "Done." << std::endl;
- }
- return err;
+ Daemon daemon;
+ return daemon.Run();
}
diff --git a/buffet/commands/dbus_command_dispatcher.cc b/buffet/commands/dbus_command_dispatcher.cc
index 6751372..457ea88 100644
--- a/buffet/commands/dbus_command_dispatcher.cc
+++ b/buffet/commands/dbus_command_dispatcher.cc
@@ -7,6 +7,7 @@
#include <chromeos/dbus/exported_object_manager.h>
#include "buffet/commands/command_instance.h"
+#include "buffet/dbus_constants.h"
using chromeos::dbus_utils::AsyncEventSequencer;
using chromeos::dbus_utils::ExportedObjectManager;
diff --git a/buffet/commands/dbus_command_dispatcher_unittest.cc b/buffet/commands/dbus_command_dispatcher_unittest.cc
index 8033390..ec3c658 100644
--- a/buffet/commands/dbus_command_dispatcher_unittest.cc
+++ b/buffet/commands/dbus_command_dispatcher_unittest.cc
@@ -17,7 +17,7 @@
#include "buffet/commands/command_dictionary.h"
#include "buffet/commands/command_queue.h"
#include "buffet/commands/unittest_utils.h"
-#include "buffet/libbuffet/dbus_constants.h"
+#include "buffet/dbus_constants.h"
using buffet::unittests::CreateDictionaryValue;
using chromeos::dbus_utils::AsyncEventSequencer;
diff --git a/buffet/commands/dbus_command_proxy.h b/buffet/commands/dbus_command_proxy.h
index 2d0f478..3511f9f 100644
--- a/buffet/commands/dbus_command_proxy.h
+++ b/buffet/commands/dbus_command_proxy.h
@@ -12,7 +12,6 @@
#include <chromeos/dbus/dbus_object.h>
#include "buffet/commands/command_proxy_interface.h"
-#include "buffet/libbuffet/dbus_constants.h"
#include "buffet/org.chromium.Buffet.Command.h"
namespace chromeos {
diff --git a/buffet/commands/dbus_command_proxy_unittest.cc b/buffet/commands/dbus_command_proxy_unittest.cc
index eac207b..e750ddb 100644
--- a/buffet/commands/dbus_command_proxy_unittest.cc
+++ b/buffet/commands/dbus_command_proxy_unittest.cc
@@ -17,7 +17,7 @@
#include "buffet/commands/command_dictionary.h"
#include "buffet/commands/command_instance.h"
#include "buffet/commands/unittest_utils.h"
-#include "buffet/libbuffet/dbus_constants.h"
+#include "buffet/dbus_constants.h"
using ::testing::AnyNumber;
using ::testing::Return;
@@ -26,7 +26,6 @@
using buffet::unittests::CreateDictionaryValue;
using chromeos::dbus_utils::AsyncEventSequencer;
-using chromeos::dbus_utils::ExportedObjectManager;
using chromeos::VariantDictionary;
namespace buffet {
@@ -120,68 +119,13 @@
return static_cast<DBusCommandProxy*>(command_instance_->proxies_[0].get());
}
- chromeos::dbus_utils::DBusObject* GetProxyDBusObject() {
- return &GetCommandProxy()->dbus_object_;
+ org::chromium::Buffet::CommandAdaptor* GetCommandAdaptor() const {
+ return &GetCommandProxy()->dbus_adaptor_;
}
- std::string GetStatus() const {
- return GetCommandProxy()->dbus_adaptor_.GetStatus();
- }
-
- int32_t GetProgress() const {
- return GetCommandProxy()->dbus_adaptor_.GetProgress();
- }
-
- VariantDictionary GetParameters() const {
- return GetCommandProxy()->dbus_adaptor_.GetParameters();
- }
-
- VariantDictionary GetResults() const {
- return GetCommandProxy()->dbus_adaptor_.GetResults();
- }
-
- std::unique_ptr<dbus::Response> CallMethod(
- const std::string& method_name,
- const std::function<void(dbus::MessageWriter*)>& param_callback) {
- dbus::MethodCall method_call(dbus_constants::kCommandInterface,
- method_name);
- method_call.SetSerial(1234);
- dbus::MessageWriter writer(&method_call);
- if (param_callback)
- param_callback(&writer);
- return chromeos::dbus_utils::testing::CallMethod(*GetProxyDBusObject(),
- &method_call);
- }
-
- static bool IsResponseError(const std::unique_ptr<dbus::Response>& response) {
- return (response->GetMessageType() == dbus::Message::MESSAGE_ERROR);
- }
-
- static void VerifyResponse(
- const std::unique_ptr<dbus::Response>& response,
- const std::function<void(dbus::MessageReader*)>& result_callback) {
- EXPECT_FALSE(IsResponseError(response));
- dbus::MessageReader reader(response.get());
- if (result_callback)
- result_callback(&reader);
- EXPECT_FALSE(reader.HasMoreData());
- }
-
- template<typename T>
- T GetPropertyValue(const std::string& property_name) {
- dbus::MethodCall method_call(dbus::kPropertiesInterface,
- dbus::kPropertiesGet);
- method_call.SetSerial(1234);
- dbus::MessageWriter writer(&method_call);
- writer.AppendString(dbus_constants::kCommandInterface);
- writer.AppendString(property_name);
- auto response = chromeos::dbus_utils::testing::CallMethod(
- *GetProxyDBusObject(), &method_call);
- T value{};
- VerifyResponse(response, [&value](dbus::MessageReader* reader) {
- EXPECT_TRUE(chromeos::dbus_utils::PopValueFromReader(reader, &value));
- });
- return value;
+ org::chromium::Buffet::CommandInterface* GetCommandInterface() const {
+ // DBusCommandProxy also implements CommandInterface.
+ return GetCommandProxy();
}
std::unique_ptr<CommandInstance> command_instance_;
@@ -198,49 +142,29 @@
};
VariantDictionary results;
- EXPECT_EQ(CommandInstance::kStatusQueued, GetStatus());
- EXPECT_EQ(0, GetProgress());
- EXPECT_EQ(params, GetParameters());
- EXPECT_EQ(results, GetResults());
- EXPECT_EQ("robot.jump",
- GetPropertyValue<std::string>(dbus_constants::kCommandName));
- EXPECT_EQ(kTestCommandCategoty,
- GetPropertyValue<std::string>(dbus_constants::kCommandCategory));
- EXPECT_EQ(kTestCommandId,
- GetPropertyValue<std::string>(dbus_constants::kCommandId));
- EXPECT_EQ(CommandInstance::kStatusQueued,
- GetPropertyValue<std::string>(dbus_constants::kCommandStatus));
- EXPECT_EQ(0, GetPropertyValue<int32_t>(dbus_constants::kCommandProgress));
- EXPECT_EQ(params,
- GetPropertyValue<VariantDictionary>(
- dbus_constants::kCommandParameters));
- EXPECT_EQ(results,
- GetPropertyValue<VariantDictionary>(
- dbus_constants::kCommandResults));
+ EXPECT_EQ(CommandInstance::kStatusQueued, GetCommandAdaptor()->GetStatus());
+ EXPECT_EQ(0, GetCommandAdaptor()->GetProgress());
+ EXPECT_EQ(params, GetCommandAdaptor()->GetParameters());
+ EXPECT_EQ(results, GetCommandAdaptor()->GetResults());
+ EXPECT_EQ("robot.jump", GetCommandAdaptor()->GetName());
+ EXPECT_EQ(kTestCommandCategoty, GetCommandAdaptor()->GetCategory());
+ EXPECT_EQ(kTestCommandId, GetCommandAdaptor()->GetId());
+ EXPECT_EQ(params, GetCommandAdaptor()->GetParameters());
+ EXPECT_EQ(results, GetCommandAdaptor()->GetResults());
}
TEST_F(DBusCommandProxyTest, SetProgress) {
EXPECT_CALL(*mock_exported_object_command_, SendSignal(_)).Times(2);
- auto response = CallMethod(dbus_constants::kCommandSetProgress,
- [](dbus::MessageWriter* writer) {
- writer->AppendInt32(10);
- });
- VerifyResponse(response, {});
- EXPECT_EQ(CommandInstance::kStatusInProgress, GetStatus());
- EXPECT_EQ(10, GetProgress());
+ EXPECT_TRUE(GetCommandInterface()->SetProgress(nullptr, 10));
EXPECT_EQ(CommandInstance::kStatusInProgress,
- GetPropertyValue<std::string>(dbus_constants::kCommandStatus));
- EXPECT_EQ(10, GetPropertyValue<int32_t>(dbus_constants::kCommandProgress));
+ GetCommandAdaptor()->GetStatus());
+ EXPECT_EQ(10, GetCommandAdaptor()->GetProgress());
}
TEST_F(DBusCommandProxyTest, SetProgress_OutOfRange) {
- auto response = CallMethod(dbus_constants::kCommandSetProgress,
- [](dbus::MessageWriter* writer) {
- writer->AppendInt32(110);
- });
- EXPECT_TRUE(IsResponseError(response));
- EXPECT_EQ(CommandInstance::kStatusQueued, GetStatus());
- EXPECT_EQ(0, GetProgress());
+ EXPECT_FALSE(GetCommandInterface()->SetProgress(nullptr, 110));
+ EXPECT_EQ(CommandInstance::kStatusQueued, GetCommandAdaptor()->GetStatus());
+ EXPECT_EQ(0, GetCommandAdaptor()->GetProgress());
}
TEST_F(DBusCommandProxyTest, SetResults) {
@@ -249,15 +173,8 @@
{"foo", int32_t{42}},
{"bar", std::string{"foobar"}},
};
- auto response = CallMethod(dbus_constants::kCommandSetResults,
- [results](dbus::MessageWriter* writer) {
- chromeos::dbus_utils::AppendValueToWriter(writer, results);
- });
- VerifyResponse(response, {});
- EXPECT_EQ(results, GetResults());
- EXPECT_EQ(results,
- GetPropertyValue<VariantDictionary>(
- dbus_constants::kCommandResults));
+ EXPECT_TRUE(GetCommandInterface()->SetResults(nullptr, results));
+ EXPECT_EQ(results, GetCommandAdaptor()->GetResults());
}
TEST_F(DBusCommandProxyTest, SetResults_UnknownProperty) {
@@ -265,25 +182,21 @@
const VariantDictionary results = {
{"quux", int32_t{42}},
};
- auto response = CallMethod(dbus_constants::kCommandSetResults,
- [results](dbus::MessageWriter* writer) {
- chromeos::dbus_utils::AppendValueToWriter(writer, results);
- });
- EXPECT_TRUE(IsResponseError(response));
+ EXPECT_FALSE(GetCommandInterface()->SetResults(nullptr, results));
}
TEST_F(DBusCommandProxyTest, Abort) {
EXPECT_CALL(*mock_exported_object_command_, SendSignal(_)).Times(1);
- auto response = CallMethod(dbus_constants::kCommandAbort, {});
- VerifyResponse(response, {});
- EXPECT_EQ(CommandInstance::kStatusAborted, GetStatus());
+ GetCommandInterface()->Abort();
+ EXPECT_EQ(CommandInstance::kStatusAborted,
+ GetCommandAdaptor()->GetStatus());
}
TEST_F(DBusCommandProxyTest, Cancel) {
EXPECT_CALL(*mock_exported_object_command_, SendSignal(_)).Times(1);
- auto response = CallMethod(dbus_constants::kCommandCancel, {});
- VerifyResponse(response, {});
- EXPECT_EQ(CommandInstance::kStatusCanceled, GetStatus());
+ GetCommandInterface()->Cancel();
+ EXPECT_EQ(CommandInstance::kStatusCanceled,
+ GetCommandAdaptor()->GetStatus());
}
TEST_F(DBusCommandProxyTest, Done) {
@@ -292,10 +205,9 @@
// progress: 0 -> 100
// status: inProgress -> done
EXPECT_CALL(*mock_exported_object_command_, SendSignal(_)).Times(3);
- auto response = CallMethod(dbus_constants::kCommandDone, {});
- VerifyResponse(response, {});
- EXPECT_EQ(CommandInstance::kStatusDone, GetStatus());
- EXPECT_EQ(100, GetProgress());
+ GetCommandInterface()->Done();
+ EXPECT_EQ(CommandInstance::kStatusDone, GetCommandAdaptor()->GetStatus());
+ EXPECT_EQ(100, GetCommandAdaptor()->GetProgress());
}
} // namespace buffet
diff --git a/buffet/dbus_bindings/dbus-service-config.json b/buffet/dbus_bindings/dbus-service-config.json
index 7b1ce6b..e610c3d 100644
--- a/buffet/dbus_bindings/dbus-service-config.json
+++ b/buffet/dbus_bindings/dbus-service-config.json
@@ -1,3 +1,7 @@
{
- "service_name": "org.chromium.Buffet"
-}
\ No newline at end of file
+ "service_name": "org.chromium.Buffet",
+ "object_manager": {
+ "name": "org.chromium.Buffet.ObjectManager",
+ "object_path": "/org/chromium/Buffet"
+ }
+}
diff --git a/buffet/dbus_constants.cc b/buffet/dbus_constants.cc
new file mode 100644
index 0000000..ac6e080
--- /dev/null
+++ b/buffet/dbus_constants.cc
@@ -0,0 +1,17 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "buffet/dbus_constants.h"
+
+namespace buffet {
+namespace dbus_constants {
+
+const char kServiceName[] = "org.chromium.Buffet";
+
+const char kRootServicePath[] = "/org/chromium/Buffet";
+
+const char kCommandServicePathPrefix[] = "/org/chromium/Buffet/commands/";
+
+} // namespace dbus_constants
+} // namespace buffet
diff --git a/buffet/dbus_constants.h b/buffet/dbus_constants.h
new file mode 100644
index 0000000..04701fe
--- /dev/null
+++ b/buffet/dbus_constants.h
@@ -0,0 +1,23 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BUFFET_DBUS_CONSTANTS_H_
+#define BUFFET_DBUS_CONSTANTS_H_
+
+namespace buffet {
+namespace dbus_constants {
+
+// The service name claimed by the Buffet daemon.
+extern const char kServiceName[];
+
+// The object at this path implements the ObjectManager interface.
+extern const char kRootServicePath[];
+
+// D-Bus object path prefix for Command objects.
+extern const char kCommandServicePathPrefix[];
+
+} // namespace dbus_constants
+} // namespace buffet
+
+#endif // BUFFET_DBUS_CONSTANTS_H_
diff --git a/buffet/libbuffet/command.cc b/buffet/libbuffet/command.cc
deleted file mode 100644
index dfa5581..0000000
--- a/buffet/libbuffet/command.cc
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "libbuffet/command.h"
-
-#include <chromeos/dbus/dbus_method_invoker.h>
-
-#include "libbuffet/command_listener.h"
-#include "libbuffet/dbus_constants.h"
-#include "libbuffet/private/command_property_set.h"
-
-namespace buffet {
-
-Command::Command(const dbus::ObjectPath& object_path,
- CommandListener* command_listener)
- : object_path_(object_path), command_listener_(command_listener) {}
-
-const std::string& Command::GetID() const {
- return GetProperties()->id.value();
-}
-
-const std::string& Command::GetName() const {
- return GetProperties()->name.value();
-}
-
-const std::string& Command::GetCategory() const {
- return GetProperties()->category.value();
-}
-
-const chromeos::VariantDictionary& Command::GetParameters() const {
- return GetProperties()->parameters.value();
-}
-
-void Command::SetProgress(int progress) {
- chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(),
- dbus_constants::kCommandInterface,
- dbus_constants::kCommandSetProgress,
- nullptr,
- progress);
-}
-
-void Command::Abort() {
- chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(),
- dbus_constants::kCommandInterface,
- dbus_constants::kCommandAbort,
- nullptr);
-}
-
-void Command::Cancel() {
- chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(),
- dbus_constants::kCommandInterface,
- dbus_constants::kCommandCancel,
- nullptr);
-}
-
-void Command::Done() {
- chromeos::dbus_utils::CallMethodAndBlock(GetObjectProxy(),
- dbus_constants::kCommandInterface,
- dbus_constants::kCommandDone,
- nullptr);
-}
-
-int Command::GetProgress() const {
- return GetProperties()->progress.value();
-}
-
-const std::string& Command::GetStatus() const {
- return GetProperties()->status.value();
-}
-
-CommandPropertySet* Command::GetProperties() const {
- return command_listener_->GetProperties(object_path_);
-}
-
-dbus::ObjectProxy* Command::GetObjectProxy() const {
- return command_listener_->GetObjectProxy(object_path_);
-}
-
-} // namespace buffet
diff --git a/buffet/libbuffet/command.h b/buffet/libbuffet/command.h
deleted file mode 100644
index 15fbb7b..0000000
--- a/buffet/libbuffet/command.h
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BUFFET_LIBBUFFET_COMMAND_H_
-#define BUFFET_LIBBUFFET_COMMAND_H_
-
-#include <string>
-
-#include <base/macros.h>
-#include <base/memory/weak_ptr.h>
-#include <chromeos/variant_dictionary.h>
-
-#include "libbuffet/export.h"
-
-namespace dbus {
-class ObjectProxy;
-}
-
-namespace buffet {
-
-class CommandListener;
-class CommandPropertySet;
-
-// buffet::Command is a proxy class for GCD CommandInstance object delivered to
-// command handling daemon over D-Bus.
-class LIBBUFFET_EXPORT Command {
- public:
- Command(const dbus::ObjectPath& object_path,
- CommandListener* command_listener);
-
- // Returns the command ID.
- const std::string& GetID() const;
- // Returns the full name of the command.
- const std::string& GetName() const;
- // Returns the command category.
- const std::string& GetCategory() const;
- // Returns the command parameters and their values.
- const chromeos::VariantDictionary& GetParameters() const;
-
- // Updates the command execution progress. The |progress| must be between
- // 0 and 100. Returns false if the progress value is incorrect.
- void SetProgress(int progress);
- // Aborts command execution.
- void Abort();
- // Cancels command execution.
- void Cancel();
- // Marks the command as completed successfully.
- void Done();
-
- // Command state getters.
- int GetProgress() const;
- const std::string& GetStatus() const;
-
- private:
- CommandPropertySet* GetProperties() const;
- dbus::ObjectProxy* GetObjectProxy() const;
-
- dbus::ObjectPath object_path_;
- CommandListener* command_listener_;
-
- DISALLOW_COPY_AND_ASSIGN(Command);
-};
-
-} // namespace buffet
-
-#endif // BUFFET_LIBBUFFET_COMMAND_H_
diff --git a/buffet/libbuffet/command_listener.cc b/buffet/libbuffet/command_listener.cc
deleted file mode 100644
index 50e90ce..0000000
--- a/buffet/libbuffet/command_listener.cc
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "libbuffet/command_listener.h"
-
-#include <dbus/bus.h>
-
-#include "libbuffet/command.h"
-#include "libbuffet/dbus_constants.h"
-#include "libbuffet/private/command_property_set.h"
-
-namespace buffet {
-
-CommandPropertySet::CommandPropertySet(dbus::ObjectProxy* object_proxy,
- const std::string& interface_name,
- const PropertyChangedCallback& callback)
- : dbus::PropertySet(object_proxy, interface_name, callback) {
- RegisterProperty(dbus_constants::kCommandName, &name);
- RegisterProperty(dbus_constants::kCommandCategory, &category);
- RegisterProperty(dbus_constants::kCommandId, &id);
- RegisterProperty(dbus_constants::kCommandStatus, &status);
- RegisterProperty(dbus_constants::kCommandProgress, &progress);
- RegisterProperty(dbus_constants::kCommandParameters, ¶meters);
- RegisterProperty(dbus_constants::kCommandResults, &results);
-}
-
-bool CommandListener::Init(
- dbus::Bus* bus, const OnBuffetCommandCallback& on_buffet_command_callback) {
- object_manager_ = bus->GetObjectManager(
- dbus_constants::kServiceName,
- dbus::ObjectPath(dbus_constants::kRootServicePath));
- on_buffet_command_callback_ = on_buffet_command_callback;
- object_manager_->RegisterInterface(dbus_constants::kCommandInterface, this);
- return true;
-}
-
-dbus::PropertySet* CommandListener::CreateProperties(
- dbus::ObjectProxy* object_proxy,
- const dbus::ObjectPath& object_path,
- const std::string& interface_name) {
- return new CommandPropertySet(object_proxy,
- interface_name,
- base::Bind(&CommandListener::OnPropertyChanged,
- weak_ptr_factory_.GetWeakPtr(),
- object_path));
-}
-
-CommandPropertySet* CommandListener::GetProperties(
- const dbus::ObjectPath& object_path) const {
- auto props = object_manager_->GetProperties(
- object_path, dbus_constants::kCommandInterface);
- CHECK(props) << "Unable to get property set of D-Bus object at "
- << object_path.value();
- return static_cast<CommandPropertySet*>(props);
-}
-
-dbus::ObjectProxy* CommandListener::GetObjectProxy(
- const dbus::ObjectPath& object_path) const {
- auto proxy = object_manager_->GetObjectProxy(object_path);
- CHECK(proxy) << "Unable to get D-Bus object proxy for "
- << object_path.value();
- return proxy;
-}
-
-void CommandListener::ObjectAdded(const dbus::ObjectPath& object_path,
- const std::string& interface_name) {
- VLOG(1) << "D-Bus interface '" << interface_name
- << "' has been added for object at path '"
- << object_path.value() << "'.";
- scoped_ptr<Command> command(new Command(object_path, this));
- if (!on_buffet_command_callback_.is_null())
- on_buffet_command_callback_.Run(command.Pass());
-}
-
-void CommandListener::ObjectRemoved(const dbus::ObjectPath& object_path,
- const std::string& interface_name) {
- VLOG(1) << "D-Bus interface '" << interface_name
- << "' has been removed from object at path '"
- << object_path.value() << "'.";
-}
-
-
-void CommandListener::OnPropertyChanged(const dbus::ObjectPath& object_path,
- const std::string& property_name) {
- VLOG(1) << "Value of property '" << property_name
- << "' on object at path '" << object_path.value() << "' has changed";
-}
-
-} // namespace buffet
diff --git a/buffet/libbuffet/command_listener.h b/buffet/libbuffet/command_listener.h
deleted file mode 100644
index 452edc6..0000000
--- a/buffet/libbuffet/command_listener.h
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BUFFET_LIBBUFFET_COMMAND_LISTENER_H_
-#define BUFFET_LIBBUFFET_COMMAND_LISTENER_H_
-
-#include <string>
-#include <vector>
-
-#include <base/callback_forward.h>
-#include <base/macros.h>
-#include <base/memory/scoped_ptr.h>
-#include <base/memory/weak_ptr.h>
-#include <dbus/object_manager.h>
-
-#include "libbuffet/export.h"
-
-namespace buffet {
-
-class CommandPropertySet;
-class Command;
-// Have to use scoped_ptr<> instead of unique_ptr<> for callback parameter
-// because base::Callback cannot handle C++11 move-only types.
-using OnBuffetCommandCallback = base::Callback<void(scoped_ptr<Command>)>;
-
-// buffet::CommandListener is a helper class that connects to Buffet's D-Bus
-// object manager and listens to InterfacesAdded notifications. When a new
-// Command D-Bus object becomes available, this class calls
-// a OnBuffetCommandCallback with buffet::Command object instance that is
-// a proxy for the remote D-Bus command object.
-class LIBBUFFET_EXPORT CommandListener : public dbus::ObjectManager::Interface {
- public:
- CommandListener() = default;
-
- // Initializes the object and establishes connection to Buffet's D-Bus Object
- // Manager. Callback |on_buffet_command_callback| is called with Command
- // object whenever a new Buffet command becomes available.
- bool Init(dbus::Bus* bus,
- const OnBuffetCommandCallback& on_buffet_command_callback);
-
- protected:
- // Callback invoked when the value of property |property_name| of an object
- // at |object_path| is changed.
- virtual void OnPropertyChanged(const dbus::ObjectPath& object_path,
- const std::string& property_name);
-
- // Called by D-Bus ObjectManager to notify that an object has been added with
- // the path |object_path|.
- void ObjectAdded(
- const dbus::ObjectPath& object_path,
- const std::string& interface_name) override;
-
- // Called by D-Bus ObjectManager to notify that an object with the path
- // |object_path| has been removed.
- void ObjectRemoved(
- const dbus::ObjectPath& object_path,
- const std::string& interface_name) override;
-
- private:
- // Override from dbus::ObjectManager::Interface to create the property set
- // for out Command D-Bus object.
- LIBBUFFET_PRIVATE dbus::PropertySet* CreateProperties(
- dbus::ObjectProxy* object_proxy,
- const dbus::ObjectPath& object_path,
- const std::string& interface_name) override;
-
- // Gets the CommandPropertySet for the command object at |object_path|.
- LIBBUFFET_PRIVATE CommandPropertySet* GetProperties(
- const dbus::ObjectPath& object_path) const;
-
- // Gets the D-Bus proxy for the command object at |object_path|.
- LIBBUFFET_PRIVATE dbus::ObjectProxy* GetObjectProxy(
- const dbus::ObjectPath& object_path) const;
-
- dbus::ObjectManager* object_manager_;
- OnBuffetCommandCallback on_buffet_command_callback_;
- base::WeakPtrFactory<CommandListener> weak_ptr_factory_{this};
-
- friend class Command;
- DISALLOW_COPY_AND_ASSIGN(CommandListener);
-};
-
-} // namespace buffet
-
-#endif // BUFFET_LIBBUFFET_COMMAND_LISTENER_H_
diff --git a/buffet/libbuffet/dbus_constants.cc b/buffet/libbuffet/dbus_constants.cc
deleted file mode 100644
index 475ffba..0000000
--- a/buffet/libbuffet/dbus_constants.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "libbuffet/dbus_constants.h"
-
-namespace buffet {
-
-namespace dbus_constants {
-
-const char kServiceName[] = "org.chromium.Buffet";
-
-const char kRootServicePath[] = "/org/chromium/Buffet";
-
-const char kManagerInterface[] = "org.chromium.Buffet.Manager";
-const char kManagerServicePath[] = "/org/chromium/Buffet/Manager";
-
-const char kManagerStartDevice[] = "StartDevice";
-const char kManagerCheckDeviceRegistered[] = "CheckDeviceRegistered";
-const char kManagerGetDeviceInfo[] = "GetDeviceInfo";
-const char kManagerRegisterDevice[] = "RegisterDevice";
-const char kManagerUpdateStateMethod[] = "UpdateState";
-const char kManagerAddCommand[] = "AddCommand";
-const char kManagerTestMethod[] = "TestMethod";
-
-const char kCommandInterface[] = "org.chromium.Buffet.Command";
-const char kCommandServicePathPrefix[] = "/org/chromium/Buffet/commands/";
-
-const char kCommandSetResults[] = "SetResults";
-const char kCommandSetProgress[] = "SetProgress";
-const char kCommandAbort[] = "Abort";
-const char kCommandCancel[] = "Cancel";
-const char kCommandDone[] = "Done";
-
-const char kCommandName[] = "Name";
-const char kCommandCategory[] = "Category";
-const char kCommandId[] = "Id";
-const char kCommandStatus[] = "Status";
-const char kCommandProgress[] = "Progress";
-const char kCommandParameters[] = "Parameters";
-const char kCommandResults[] = "Results";
-
-} // namespace dbus_constants
-
-} // namespace buffet
diff --git a/buffet/libbuffet/dbus_constants.h b/buffet/libbuffet/dbus_constants.h
deleted file mode 100644
index 22a1447..0000000
--- a/buffet/libbuffet/dbus_constants.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BUFFET_LIBBUFFET_DBUS_CONSTANTS_H_
-#define BUFFET_LIBBUFFET_DBUS_CONSTANTS_H_
-
-#include "libbuffet/export.h"
-
-namespace buffet {
-
-namespace dbus_constants {
-
-// The service name claimed by the Buffet daemon.
-LIBBUFFET_EXPORT extern const char kServiceName[];
-
-// The object at this path implements the ObjectManager interface.
-LIBBUFFET_EXPORT extern const char kRootServicePath[];
-
-// Interface implemented by the object at kManagerServicePath.
-LIBBUFFET_EXPORT extern const char kManagerInterface[];
-LIBBUFFET_EXPORT extern const char kManagerServicePath[];
-
-// Methods exposed as part of kManagerInterface.
-LIBBUFFET_EXPORT extern const char kManagerStartDevice[];
-LIBBUFFET_EXPORT extern const char kManagerCheckDeviceRegistered[];
-LIBBUFFET_EXPORT extern const char kManagerGetDeviceInfo[];
-LIBBUFFET_EXPORT extern const char kManagerRegisterDevice[];
-LIBBUFFET_EXPORT extern const char kManagerUpdateStateMethod[];
-LIBBUFFET_EXPORT extern const char kManagerAddCommand[];
-LIBBUFFET_EXPORT extern const char kManagerTestMethod[];
-
-// Interface implemented by the command instance objects.
-LIBBUFFET_EXPORT extern const char kCommandInterface[];
-LIBBUFFET_EXPORT extern const char kCommandServicePathPrefix[];
-
-// Methods exposed as part of kCommandInterface.
-LIBBUFFET_EXPORT extern const char kCommandSetResults[];
-LIBBUFFET_EXPORT extern const char kCommandSetProgress[];
-LIBBUFFET_EXPORT extern const char kCommandAbort[];
-LIBBUFFET_EXPORT extern const char kCommandCancel[];
-LIBBUFFET_EXPORT extern const char kCommandDone[];
-
-// Properties exposed as part of kCommandInterface.
-LIBBUFFET_EXPORT extern const char kCommandName[];
-LIBBUFFET_EXPORT extern const char kCommandCategory[];
-LIBBUFFET_EXPORT extern const char kCommandId[];
-LIBBUFFET_EXPORT extern const char kCommandStatus[];
-LIBBUFFET_EXPORT extern const char kCommandProgress[];
-LIBBUFFET_EXPORT extern const char kCommandParameters[];
-LIBBUFFET_EXPORT extern const char kCommandResults[];
-
-} // namespace dbus_constants
-
-} // namespace buffet
-
-#endif // BUFFET_LIBBUFFET_DBUS_CONSTANTS_H_
diff --git a/buffet/libbuffet/export.h b/buffet/libbuffet/export.h
deleted file mode 100644
index e67d6bb..0000000
--- a/buffet/libbuffet/export.h
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BUFFET_LIBBUFFET_EXPORT_H_
-#define BUFFET_LIBBUFFET_EXPORT_H_
-
-// See detailed explanation of the purpose of LIBBUFFET_EXPORT in
-// chromeos/chromeos_export.h for similar attribute - CHROMEOS_EXPORT.
-#define LIBBUFFET_EXPORT __attribute__((__visibility__("default")))
-#define LIBBUFFET_PRIVATE __attribute__((__visibility__("hidden")))
-
-#endif // BUFFET_LIBBUFFET_EXPORT_H_
diff --git a/buffet/libbuffet/libbuffet.pc.in b/buffet/libbuffet/libbuffet.pc.in
deleted file mode 100644
index 6391ea2..0000000
--- a/buffet/libbuffet/libbuffet.pc.in
+++ /dev/null
@@ -1,7 +0,0 @@
-bslot=@BSLOT@
-
-Name: libbuffet
-Description: Buffet interface library
-Version: ${bslot}
-Requires.private: @PRIVATE_PC@
-Libs: -lbuffet-${bslot}
diff --git a/buffet/libbuffet/preinstall.sh b/buffet/libbuffet/preinstall.sh
deleted file mode 100755
index 960d81e..0000000
--- a/buffet/libbuffet/preinstall.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-# Copyright 2014 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-set -e
-
-OUT=$1
-v=$2
-
-deps=$(<"${OUT}"/gen/libbuffet-${v}-deps.txt)
-sed \
- -e "s/@BSLOT@/${v}/g" \
- -e "s/@PRIVATE_PC@/${deps}/g" \
- "libbuffet/libbuffet.pc.in" > "${OUT}/lib/libbuffet-${v}.pc"
diff --git a/buffet/libbuffet/private/command_property_set.cc b/buffet/libbuffet/private/command_property_set.cc
deleted file mode 100644
index 370139d..0000000
--- a/buffet/libbuffet/private/command_property_set.cc
+++ /dev/null
@@ -1,6 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "libbuffet/private/command_property_set.h"
-
diff --git a/buffet/libbuffet/private/command_property_set.h b/buffet/libbuffet/private/command_property_set.h
deleted file mode 100644
index dbf9eae..0000000
--- a/buffet/libbuffet/private/command_property_set.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BUFFET_LIBBUFFET_PRIVATE_COMMAND_PROPERTY_SET_H_
-#define BUFFET_LIBBUFFET_PRIVATE_COMMAND_PROPERTY_SET_H_
-
-#include <string>
-
-#include <base/macros.h>
-#include <chromeos/dbus/dbus_property.h>
-#include <chromeos/variant_dictionary.h>
-#include <dbus/object_manager.h>
-
-#include "buffet/libbuffet/export.h"
-
-namespace buffet {
-
-// PropertySet for remote D-Bus GCD Command object from Buffet daemon.
-class CommandPropertySet : public dbus::PropertySet {
- public:
- CommandPropertySet(dbus::ObjectProxy* object_proxy,
- const std::string& interface_name,
- const PropertyChangedCallback& callback);
- 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);
-};
-
-} // namespace buffet
-
-#endif // BUFFET_LIBBUFFET_PRIVATE_COMMAND_PROPERTY_SET_H_
diff --git a/buffet/main.cc b/buffet/main.cc
index 2eb2e2a..7cb37fb 100644
--- a/buffet/main.cc
+++ b/buffet/main.cc
@@ -10,7 +10,7 @@
#include <chromeos/daemons/dbus_daemon.h>
#include <chromeos/syslog_logging.h>
-#include "buffet/libbuffet/dbus_constants.h"
+#include "buffet/dbus_constants.h"
#include "buffet/manager.h"
using chromeos::dbus_utils::AsyncEventSequencer;
diff --git a/buffet/manager.cc b/buffet/manager.cc
index 0a0f5fb..171eeac 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -21,7 +21,6 @@
#include "buffet/commands/command_instance.h"
#include "buffet/commands/command_manager.h"
-#include "buffet/libbuffet/dbus_constants.h"
#include "buffet/states/state_change_queue.h"
#include "buffet/states/state_manager.h"
diff --git a/buffet/test_daemon/main.cc b/buffet/test_daemon/main.cc
index 2956f16..ec26a82 100644
--- a/buffet/test_daemon/main.cc
+++ b/buffet/test_daemon/main.cc
@@ -17,8 +17,7 @@
#include <chromeos/strings/string_utils.h>
#include <chromeos/syslog_logging.h>
-#include "buffet/libbuffet/command.h"
-#include "buffet/libbuffet/command_listener.h"
+#include "buffet/dbus-proxies.h"
class Daemon : public chromeos::DBusDaemon {
public:
@@ -29,9 +28,14 @@
void OnShutdown(int* return_code) override;
private:
- buffet::CommandListener command_listener_;
+ std::unique_ptr<org::chromium::Buffet::ObjectManagerProxy> object_manager_;
- void OnBuffetCommand(scoped_ptr<buffet::Command> command);
+ void OnBuffetCommand(org::chromium::Buffet::CommandProxy* command);
+ void OnBuffetCommandRemoved(const dbus::ObjectPath& object_path);
+ void OnPropertyChange(org::chromium::Buffet::CommandProxy* command,
+ const std::string& property_name);
+ void OnCommandProgress(org::chromium::Buffet::CommandProxy* command,
+ int progress);
DISALLOW_COPY_AND_ASSIGN(Daemon);
};
@@ -41,10 +45,11 @@
if (return_code != EX_OK)
return return_code;
- if (!command_listener_.Init(bus_, base::Bind(&Daemon::OnBuffetCommand,
- base::Unretained(this)))) {
- return EX_SOFTWARE;
- }
+ object_manager_.reset(new org::chromium::Buffet::ObjectManagerProxy{bus_});
+ object_manager_->SetCommandAddedCallback(
+ base::Bind(&Daemon::OnBuffetCommand, base::Unretained(this)));
+ object_manager_->SetCommandRemovedCallback(
+ base::Bind(&Daemon::OnBuffetCommandRemoved, base::Unretained(this)));
printf("Waiting for commands...\n");
return EX_OK;
@@ -54,18 +59,54 @@
printf("Shutting down...\n");
}
-void Daemon::OnBuffetCommand(scoped_ptr<buffet::Command> command) {
- printf("================================================\n");
- printf("Command received: %s\n", command->GetName().c_str());
- printf(" category: %s\n", command->GetCategory().c_str());
- printf(" ID: %s\n", command->GetID().c_str());
- printf(" status: %s\n", command->GetStatus().c_str());
- printf(" # of parameters: %" PRIuS "\n", command->GetParameters().size());
- auto set = chromeos::GetMapKeys(command->GetParameters());
+void Daemon::OnPropertyChange(org::chromium::Buffet::CommandProxy* command,
+ const std::string& property_name) {
+ printf("Notification: property '%s' on command '%s' changed.\n",
+ property_name.c_str(), command->id().c_str());
+ printf(" Current command status: '%s' (%d)\n",
+ command->status().c_str(), command->progress());
+}
+
+void Daemon::OnBuffetCommand(org::chromium::Buffet::CommandProxy* command) {
+ command->SetPropertyChangedCallback(base::Bind(&Daemon::OnPropertyChange,
+ base::Unretained(this)));
+ printf("++++++++++++++++++++++++++++++++++++++++++++++++\n");
+ printf("Command received: %s\n", command->name().c_str());
+ printf("DBus Object Path: %s\n", command->GetObjectPath().value().c_str());
+ printf(" category: %s\n", command->category().c_str());
+ printf(" ID: %s\n", command->id().c_str());
+ printf(" status: %s\n", command->status().c_str());
+ printf(" # of parameters: %" PRIuS "\n", command->parameters().size());
+ auto set = chromeos::GetMapKeys(command->parameters());
std::string param_names = chromeos::string_utils::Join(
", ", std::vector<std::string>(set.begin(), set.end()));
printf(" parameter names: %s\n", param_names.c_str());
- command->Done();
+ OnCommandProgress(command, 0);
+}
+
+void Daemon::OnCommandProgress(org::chromium::Buffet::CommandProxy* command,
+ int progress) {
+ if (progress >= 100) {
+ command->Done(nullptr);
+ } else {
+ printf("Updating command '%s' progress to %d%%\n",
+ command->id().c_str(), progress);
+ command->SetProgress(progress, nullptr);
+ progress += 10;
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&Daemon::OnCommandProgress,
+ base::Unretained(this),
+ command,
+ progress),
+ base::TimeDelta::FromSeconds(1));
+ }
+}
+
+void Daemon::OnBuffetCommandRemoved(const dbus::ObjectPath& object_path) {
+ printf("------------------------------------------------\n");
+ printf("Command removed\n");
+ printf("DBus Object Path: %s\n", object_path.value().c_str());
}
int main(int argc, char* argv[]) {