diff options
| author | Patrick Williams <patrick@stwcx.xyz> | 2016-11-28 14:04:01 -0600 |
|---|---|---|
| committer | Patrick Williams <patrick@stwcx.xyz> | 2016-11-28 14:04:03 -0600 |
| commit | 6a9c8ae58131f9601e774a7fda9ee4b7b27ce189 (patch) | |
| tree | c5a9f8df16682cfc12bf3aa4459a90d7d3c6c0cd | |
| parent | b760a99c93a5fb2db2c1a54b5223f86e6c28fe82 (diff) | |
| download | sdbusplus-6a9c8ae58131f9601e774a7fda9ee4b7b27ce189.tar.gz sdbusplus-6a9c8ae58131f9601e774a7fda9ee4b7b27ce189.zip | |
message: pass 'bool' types to sdbus as 'int'
sdbus requires dbus-boolean to be passed as 'int' and not 'bool'.
Modify message append / read functions to ensure this requirement
is met.
See man-page for sd_bus_message_append_basic, SD_BUS_TYPE_BOOLEAN.
Fixes openbmc/sdbusplus#7.
Change-Id: Id020f1a8598f034551d30a0561c50cb1ab5d752d
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
| -rw-r--r-- | sdbusplus/message/append.hpp | 14 | ||||
| -rw-r--r-- | sdbusplus/message/read.hpp | 16 |
2 files changed, 30 insertions, 0 deletions
diff --git a/sdbusplus/message/append.hpp b/sdbusplus/message/append.hpp index df0b08f..7b84ed0 100644 --- a/sdbusplus/message/append.hpp +++ b/sdbusplus/message/append.hpp @@ -47,6 +47,8 @@ namespace details template<typename T> struct can_append_multiple : std::true_type {}; // std::string needs a c_str() call. template<> struct can_append_multiple<std::string> : std::false_type {}; + // bool needs to be resized to int, per sdbus documentation. +template<> struct can_append_multiple<bool> : std::false_type {}; // std::vector needs a loop. template<typename T> struct can_append_multiple<std::vector<T>> : std::false_type {}; @@ -119,6 +121,18 @@ template <> struct append_single<std::string> } }; +/** @brief Specialization of append_single for bool. */ +template <> struct append_single<bool> +{ + template<typename T> + static void op(sd_bus_message* m, T&& b) + { + constexpr auto dbusType = 'b'; + int i = b; + sd_bus_message_append_basic(m, dbusType, &i); + } +}; + /** @brief Specialization of append_single for std::vectors. */ template <typename T> struct append_single<std::vector<T>> { diff --git a/sdbusplus/message/read.hpp b/sdbusplus/message/read.hpp index 621721f..9a98f52 100644 --- a/sdbusplus/message/read.hpp +++ b/sdbusplus/message/read.hpp @@ -47,6 +47,8 @@ namespace details template<typename T> struct can_read_multiple : std::true_type {}; // std::string needs a c_str() call. template<> struct can_read_multiple<std::string> : std::false_type {}; + // bool needs to be resized to int, per sdbus documentation. +template<> struct can_read_multiple<bool> : std::false_type {}; // std::vector needs a loop. template<typename T> struct can_read_multiple<std::vector<T>> : std::false_type {}; @@ -121,6 +123,20 @@ template <> struct read_single<std::string> } }; +/** @brief Specialization of read_single for bools. */ +template <> struct read_single<bool> +{ + template<typename T> + static void op(sd_bus_message* m, T&& b) + { + constexpr auto dbusType = 'b'; + int i = 0; + sd_bus_message_read_basic(m, dbusType, &i); + b = (i != 0); + } +}; + + /** @brief Specialization of read_single for std::vectors. */ template <typename T> struct read_single<std::vector<T>> { |

