aboutsummaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/dbus_param_reader.h
diff options
context:
space:
mode:
authorAlex Vakulenko <avakulenko@chromium.org>2014-11-09 13:21:59 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-11 00:10:37 +0000
commit003e3bb092961d8d0236fd09efaf0ded404828cb (patch)
tree55d316b2717e3ce62c776dfd15af32ad8cdfd3eb /chromeos/dbus/dbus_param_reader.h
parentf02e379d620ec06e52d96276c40f687e83844e18 (diff)
downloadplatform_external_libbrillo-003e3bb092961d8d0236fd09efaf0ded404828cb.tar.gz
platform_external_libbrillo-003e3bb092961d8d0236fd09efaf0ded404828cb.tar.bz2
platform_external_libbrillo-003e3bb092961d8d0236fd09efaf0ded404828cb.zip
libchromeos: Fix DBus data serialization to work with custom types
The previous implementation suffered from C++ binding rules for non-dependent names in templates. Template functions such as AppendValueToWriter and PopValueFromReader for template types such as std::vector<T> and std::map<K,V> are limited to the types defined in libchromeos because the implementations calling the inner overloads for types such as T would only select functions defined before the overloads for vector and map are defined. This forced the custom implementations of user-provided types to be included before chromeos/dbus/data_serialization.h and having the code depend on the order of includes is a very dangerous thing. To make the problem worse, generic AppendValueToWriter<T> is always a default fall-back for any unknown types and it simply fails at run-time which makes it very difficult to detect unintended problems. The reason why the generic AppendValueToWriter<T>() was provided is to allow chromeos::Any to contain any C++ type but still be able to use with D-Bus subset of types to implement the D-Bus's VARIANT type. This change addresses the above problems as follows: - The template functionality depending on custom overloads of AppendValueToWriter and PopValueFromReader now call them indirectly through DBusType<T>::Write and DBusType<T>::Read helpers that delay binding to the correct overload of Append... and Pop... until the template instantiation. - Marked the generic AppendValueToWriter<T> and PopValueFromReader<T> as "deleted" functions so the compilation would break as soon as these functions are called with an unsupported types. - Provided IsTypeSupported<T...> type trait to help specialize the implementation for only supported D-Bus types. This allows, for example, specialization of vector<T> to work for supported types T and fail immediately for T that are not supported by D-Bus. - Used IsTypeSupported<T> in chromeos::Any to disable calls to AppendValueToWriter at compile time for unsupported types. - Made AppendValueToWriter() a void function. Now it doesn't fail. The internal implementation inside chromeos::Any uses CHECK() to ensure the contained class which will abort as soon as Any, containing datat of an unsupported type, is being written to D-Bus message buffer. BUG=chromium:431744 TEST=FEATURES=test emerge-link libchromeos attestation buffet peerd Change-Id: I13431f74797b8b92082f172a067ea1515a7aa73e Reviewed-on: https://chromium-review.googlesource.com/228731 Reviewed-by: Christopher Wiley <wiley@chromium.org> Commit-Queue: Alex Vakulenko <avakulenko@chromium.org> Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Diffstat (limited to 'chromeos/dbus/dbus_param_reader.h')
-rw-r--r--chromeos/dbus/dbus_param_reader.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/chromeos/dbus/dbus_param_reader.h b/chromeos/dbus/dbus_param_reader.h
index 361713b..429ac48 100644
--- a/chromeos/dbus/dbus_param_reader.h
+++ b/chromeos/dbus/dbus_param_reader.h
@@ -90,7 +90,7 @@ struct DBusParamReader<allow_out_params, CurrentParam, RestOfParams...> {
// The variable to hold the value of the current parameter we reading from
// the message buffer.
ParamValueType current_param;
- if (!PopValueFromReader(reader, &current_param)) {
+ if (!DBusType<ParamValueType>::Read(reader, &current_param)) {
Error::AddTo(error, errors::dbus::kDomain, DBUS_ERROR_INVALID_ARGS,
"Method parameter type mismatch");
return false;