libchromeos: Strongly type return values of async D-Bus calls
Async method handlers currently take just a generic DBusMethodResponse
object as a parameter and it is up to the handler's implementation to
return the correct number of values of correct types.
When using D-Bus binding code generator, the number and types of both
input and output parameters of a method are well known. However with
the current implementation, async method handler take just a response
object and lose the type information of the return values and rely
on the implementation to provide both the correct number of return
values and their types.
This change adds the ability to have strongly-typed response object
in method handlers that explicitly describes the number of return
values and their types.
Now, the async method handler signature is changed from:
bool Handler(scoped_ptr<DBusMethodResponse> response,
InTypes... inputs);
to:
bool Handler(scoped_ptr<DBusMethodResponse<OutTypes...>> response,
InTypes... inputs);
Attempt to call response->Return() with wrong number of parameters or
mismatched types will be caught at compile time.
BUG=None
TEST=FEATURES=test emerge-link libchromeos buffet peerd lorgnette
Change-Id: Ie90eaacfc091484262a09f273a7aef6aaec713c9
Reviewed-on: https://chromium-review.googlesource.com/229332
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/manager.cc b/buffet/manager.cc
index abe687c..071b861 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -79,7 +79,7 @@
device_info_->Load();
}
-void Manager::HandleStartDevice(scoped_ptr<DBusMethodResponse> response) {
+void Manager::HandleStartDevice(scoped_ptr<DBusMethodResponse<>> response) {
LOG(INFO) << "Received call to Manager.StartDevice()";
chromeos::ErrorPtr error;
@@ -91,7 +91,7 @@
}
void Manager::HandleCheckDeviceRegistered(
- scoped_ptr<DBusMethodResponse> response) {
+ scoped_ptr<DBusMethodResponse<std::string>> response) {
LOG(INFO) << "Received call to Manager.CheckDeviceRegistered()";
chromeos::ErrorPtr error;
bool registered = device_info_->CheckRegistration(&error);
@@ -117,7 +117,7 @@
}
void Manager::HandleGetDeviceInfo(
- scoped_ptr<DBusMethodResponse> response) {
+ scoped_ptr<DBusMethodResponse<std::string>> response) {
LOG(INFO) << "Received call to Manager.GetDeviceInfo()";
chromeos::ErrorPtr error;
@@ -133,7 +133,7 @@
}
void Manager::HandleRegisterDevice(
- scoped_ptr<DBusMethodResponse> response,
+ scoped_ptr<DBusMethodResponse<std::string>> response,
const std::map<std::string, std::string>& params) {
LOG(INFO) << "Received call to Manager.RegisterDevice()";
@@ -146,7 +146,7 @@
}
void Manager::HandleUpdateState(
- scoped_ptr<DBusMethodResponse> response,
+ scoped_ptr<DBusMethodResponse<>> response,
const chromeos::VariantDictionary& property_set) {
chromeos::ErrorPtr error;
base::Time timestamp = base::Time::Now();
@@ -165,7 +165,7 @@
response->Return();
}
-void Manager::HandleAddCommand(scoped_ptr<DBusMethodResponse> response,
+void Manager::HandleAddCommand(scoped_ptr<DBusMethodResponse<>> response,
const std::string& json_command) {
static int next_id = 0;
std::string error_message;
diff --git a/buffet/manager.h b/buffet/manager.h
index b8ef91a..bcc0425 100644
--- a/buffet/manager.h
+++ b/buffet/manager.h
@@ -48,24 +48,27 @@
// DBus methods:
// Handles calls to org.chromium.Buffet.Manager.StartDevice().
void HandleStartDevice(
- scoped_ptr<chromeos::dbus_utils::DBusMethodResponse> response);
+ scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response);
// Handles calls to org.chromium.Buffet.Manager.CheckDeviceRegistered().
void HandleCheckDeviceRegistered(
- scoped_ptr<chromeos::dbus_utils::DBusMethodResponse> response);
+ scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<std::string>>
+ response);
// Handles calls to org.chromium.Buffet.Manager.GetDeviceInfo().
void HandleGetDeviceInfo(
- scoped_ptr<chromeos::dbus_utils::DBusMethodResponse> response);
+ scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<std::string>>
+ response);
// Handles calls to org.chromium.Buffet.Manager.RegisterDevice().
void HandleRegisterDevice(
- scoped_ptr<chromeos::dbus_utils::DBusMethodResponse> response,
+ scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<std::string>>
+ response,
const std::map<std::string, std::string>& params);
// Handles calls to org.chromium.Buffet.Manager.UpdateState().
void HandleUpdateState(
- scoped_ptr<chromeos::dbus_utils::DBusMethodResponse> response,
+ scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response,
const chromeos::VariantDictionary& property_set);
// Handles calls to org.chromium.Buffet.Manager.AddCommand().
void HandleAddCommand(
- scoped_ptr<chromeos::dbus_utils::DBusMethodResponse> response,
+ scoped_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response,
const std::string& json_command);
// Handles calls to org.chromium.Buffet.Manager.Test()
std::string HandleTestMethod(const std::string& message);