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>
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 @@
 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 @@
     }
 };
 
+/** @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 @@
 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 @@
     }
 };
 
+/** @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>>
 {