diff options
| author | Andrew Geissler <geissonator@yahoo.com> | 2018-01-18 07:21:42 -0800 |
|---|---|---|
| committer | Andrew Geissler <geissonator@yahoo.com> | 2018-02-05 11:04:50 -0800 |
| commit | 072da3ea39e5f2e215947c8fce347f918f075dc3 (patch) | |
| tree | 184b9402dae522f425796c0311e0b3ee61897ecc | |
| parent | 27d18d7c98a88a8f40daae38da2d4c61861ffe7d (diff) | |
| download | sdbusplus-072da3ea39e5f2e215947c8fce347f918f075dc3.tar.gz sdbusplus-072da3ea39e5f2e215947c8fce347f918f075dc3.zip | |
Update repo to conform to openbmc code standard
Change-Id: If1d6b1f04514367cc544c2507a845b3e9d6d3435
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
29 files changed, 1220 insertions, 873 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..309a9d6 --- /dev/null +++ b/.clang-format @@ -0,0 +1,85 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: AfterColon +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: true +PointerAlignment: Left +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: false +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... + diff --git a/example/calculator-server.cpp b/example/calculator-server.cpp index e72c493..753d2d7 100644 --- a/example/calculator-server.cpp +++ b/example/calculator-server.cpp @@ -3,20 +3,22 @@ #include <net/poettering/Calculator/server.hpp> #include <net/poettering/Calculator/error.hpp> -using Calculator_inherit = sdbusplus::server::object_t< - sdbusplus::net::poettering::server::Calculator>; +using Calculator_inherit = + sdbusplus::server::object_t<sdbusplus::net::poettering::server::Calculator>; /** Example implementation of net.poettering.Calculator */ struct Calculator : Calculator_inherit { /** Constructor */ Calculator(sdbusplus::bus::bus& bus, const char* path) : - Calculator_inherit(bus, path) { } + Calculator_inherit(bus, path) + { + } /** Multiply (x*y), update lastResult */ int64_t multiply(int64_t x, int64_t y) override { - return lastResult(x*y); + return lastResult(x * y); } /** Divide (x/y), update lastResult @@ -32,7 +34,7 @@ struct Calculator : Calculator_inherit throw DivisionByZero(); } - return lastResult(x/y); + return lastResult(x / y); } /** Clear lastResult, broadcast 'Cleared' signal */ @@ -62,7 +64,7 @@ int main() Calculator c1{b, path}; // Handle dbus processing forever. - while(1) + while (1) { b.process_discard(); // discard any unhandled messages b.wait(); diff --git a/example/list-users.cpp b/example/list-users.cpp index 245bf63..d5e59d6 100644 --- a/example/list-users.cpp +++ b/example/list-users.cpp @@ -12,16 +12,15 @@ int main() using namespace sdbusplus; auto b = bus::new_system(); - auto m = b.new_method_call("org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "ListUsers"); + auto m = + b.new_method_call("org.freedesktop.login1", "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", "ListUsers"); auto reply = b.call(m); std::vector<std::tuple<uint32_t, std::string, message::object_path>> users; reply.read(users); - for(auto& user : users) + for (auto& user : users) { std::cout << std::get<std::string>(user) << "\n"; } diff --git a/mapbox/recursive_wrapper.hpp b/mapbox/recursive_wrapper.hpp index 4ffcbd7..af569ef 100644 --- a/mapbox/recursive_wrapper.hpp +++ b/mapbox/recursive_wrapper.hpp @@ -15,11 +15,12 @@ #include <cassert> #include <utility> -namespace mapbox { -namespace util { +namespace mapbox +{ +namespace util +{ -template <typename T> -class recursive_wrapper +template <typename T> class recursive_wrapper { T* p_; @@ -29,7 +30,7 @@ class recursive_wrapper this->get() = rhs; } -public: + public: using type = T; /** @@ -41,22 +42,32 @@ public: * of type T. * @throws any exception thrown by the default constructur of T. */ - recursive_wrapper() - : p_(new T){} + recursive_wrapper() : p_(new T) + { + } - ~recursive_wrapper() noexcept { delete p_; } + ~recursive_wrapper() noexcept + { + delete p_; + } - recursive_wrapper(recursive_wrapper const& operand) - : p_(new T(operand.get())) {} + recursive_wrapper(recursive_wrapper const& operand) : + p_(new T(operand.get())) + { + } - recursive_wrapper(T const& operand) - : p_(new T(operand)) {} + recursive_wrapper(T const& operand) : p_(new T(operand)) + { + } - recursive_wrapper(recursive_wrapper&& operand) - : p_(new T(std::move(operand.get()))) {} + recursive_wrapper(recursive_wrapper&& operand) : + p_(new T(std::move(operand.get()))) + { + } - recursive_wrapper(T&& operand) - : p_(new T(std::move(operand))) {} + recursive_wrapper(T&& operand) : p_(new T(std::move(operand))) + { + } inline recursive_wrapper& operator=(recursive_wrapper const& rhs) { @@ -101,13 +112,25 @@ public: return *get_pointer(); } - T* get_pointer() { return p_; } + T* get_pointer() + { + return p_; + } - const T* get_pointer() const { return p_; } + const T* get_pointer() const + { + return p_; + } - operator T const&() const { return this->get(); } + operator T const&() const + { + return this->get(); + } - operator T&() { return this->get(); } + operator T&() + { + return this->get(); + } }; // class recursive_wrapper diff --git a/mapbox/variant.hpp b/mapbox/variant.hpp index 5574b67..37c736d 100644 --- a/mapbox/variant.hpp +++ b/mapbox/variant.hpp @@ -45,7 +45,7 @@ // clang-format on // Exceptions -#if defined( __EXCEPTIONS) || defined( _MSC_VER) +#if defined(__EXCEPTIONS) || defined(_MSC_VER) #define HAS_EXCEPTIONS #endif @@ -53,52 +53,61 @@ #define VARIANT_MINOR_VERSION 1 #define VARIANT_PATCH_VERSION 0 -#define VARIANT_VERSION (VARIANT_MAJOR_VERSION * 100000) + (VARIANT_MINOR_VERSION * 100) + (VARIANT_PATCH_VERSION) +#define VARIANT_VERSION \ + (VARIANT_MAJOR_VERSION * 100000) + (VARIANT_MINOR_VERSION * 100) + \ + (VARIANT_PATCH_VERSION) -namespace mapbox { -namespace util { +namespace mapbox +{ +namespace util +{ // XXX This should derive from std::logic_error instead of std::runtime_error. // See https://github.com/mapbox/variant/issues/48 for details. class bad_variant_access : public std::runtime_error { -public: - explicit bad_variant_access(const std::string& what_arg) - : runtime_error(what_arg) {} + public: + explicit bad_variant_access(const std::string& what_arg) : + runtime_error(what_arg) + { + } - explicit bad_variant_access(const char* what_arg) - : runtime_error(what_arg) {} + explicit bad_variant_access(const char* what_arg) : runtime_error(what_arg) + { + } }; // class bad_variant_access -template <typename R = void> -struct MAPBOX_VARIANT_DEPRECATED static_visitor +template <typename R = void> struct MAPBOX_VARIANT_DEPRECATED static_visitor { using result_type = R; -protected: - static_visitor() {} - ~static_visitor() {} + protected: + static_visitor() + { + } + ~static_visitor() + { + } }; -namespace detail { +namespace detail +{ static constexpr std::size_t invalid_value = std::size_t(-1); -template <typename T, typename... Types> -struct direct_type; +template <typename T, typename... Types> struct direct_type; template <typename T, typename First, typename... Types> struct direct_type<T, First, Types...> { static constexpr std::size_t index = std::is_same<T, First>::value - ? sizeof...(Types) - : direct_type<T, Types...>::index; + ? sizeof...(Types) + : direct_type<T, Types...>::index; }; -template <typename T> -struct direct_type<T> +template <typename T> struct direct_type<T> { static constexpr std::size_t index = invalid_value; }; @@ -109,51 +118,63 @@ using std::disjunction; #else -template <typename...> -struct disjunction : std::false_type {}; +template <typename...> struct disjunction : std::false_type +{ +}; -template <typename B1> -struct disjunction<B1> : B1 {}; +template <typename B1> struct disjunction<B1> : B1 +{ +}; template <typename B1, typename B2> -struct disjunction<B1, B2> : std::conditional<B1::value, B1, B2>::type {}; +struct disjunction<B1, B2> : std::conditional<B1::value, B1, B2>::type +{ +}; template <typename B1, typename... Bs> -struct disjunction<B1, Bs...> : std::conditional<B1::value, B1, disjunction<Bs...>>::type {}; +struct disjunction<B1, Bs...> + : std::conditional<B1::value, B1, disjunction<Bs...>>::type +{ +}; #endif -template <typename T, typename... Types> -struct convertible_type; +template <typename T, typename... Types> struct convertible_type; template <typename T, typename First, typename... Types> struct convertible_type<T, First, Types...> { - static constexpr std::size_t index = std::is_convertible<T, First>::value - ? disjunction<std::is_convertible<T, Types>...>::value ? invalid_value : sizeof...(Types) - : convertible_type<T, Types...>::index; + static constexpr std::size_t index = + std::is_convertible<T, First>::value + ? disjunction<std::is_convertible<T, Types>...>::value + ? invalid_value + : sizeof...(Types) + : convertible_type<T, Types...>::index; }; -template <typename T> -struct convertible_type<T> +template <typename T> struct convertible_type<T> { static constexpr std::size_t index = invalid_value; }; -template <typename T, typename... Types> -struct value_traits +template <typename T, typename... Types> struct value_traits { - using value_type = typename std::remove_const<typename std::remove_reference<T>::type>::type; - static constexpr std::size_t direct_index = direct_type<value_type, Types...>::index; + using value_type = typename std::remove_const< + typename std::remove_reference<T>::type>::type; + static constexpr std::size_t direct_index = + direct_type<value_type, Types...>::index; static constexpr bool is_direct = direct_index != invalid_value; - static constexpr std::size_t index = is_direct ? direct_index : convertible_type<value_type, Types...>::index; + static constexpr std::size_t index = + is_direct ? direct_index + : convertible_type<value_type, Types...>::index; static constexpr bool is_valid = index != invalid_value; - static constexpr std::size_t tindex = is_valid ? sizeof...(Types)-index : 0; - using target_type = typename std::tuple_element<tindex, std::tuple<void, Types...>>::type; + static constexpr std::size_t tindex = + is_valid ? sizeof...(Types) - index : 0; + using target_type = + typename std::tuple_element<tindex, std::tuple<void, Types...>>::type; }; -template <typename T, typename R = void> -struct enable_if_type +template <typename T, typename R = void> struct enable_if_type { using type = R; }; @@ -165,7 +186,8 @@ struct result_of_unary_visit }; template <typename F, typename V> -struct result_of_unary_visit<F, V, typename enable_if_type<typename F::result_type>::type> +struct result_of_unary_visit< + F, V, typename enable_if_type<typename F::result_type>::type> { using type = typename F::result_type; }; @@ -177,16 +199,15 @@ struct result_of_binary_visit }; template <typename F, typename V> -struct result_of_binary_visit<F, V, typename enable_if_type<typename F::result_type>::type> +struct result_of_binary_visit< + F, V, typename enable_if_type<typename F::result_type>::type> { using type = typename F::result_type; }; -template <std::size_t arg1, std::size_t... others> -struct static_max; +template <std::size_t arg1, std::size_t... others> struct static_max; -template <std::size_t arg> -struct static_max<arg> +template <std::size_t arg> struct static_max<arg> { static const std::size_t value = arg; }; @@ -194,14 +215,14 @@ struct static_max<arg> template <std::size_t arg1, std::size_t arg2, std::size_t... others> struct static_max<arg1, arg2, others...> { - static const std::size_t value = arg1 >= arg2 ? static_max<arg1, others...>::value : static_max<arg2, others...>::value; + static const std::size_t value = arg1 >= arg2 + ? static_max<arg1, others...>::value + : static_max<arg2, others...>::value; }; -template <typename... Types> -struct variant_helper; +template <typename... Types> struct variant_helper; -template <typename T, typename... Types> -struct variant_helper<T, Types...> +template <typename T, typename... Types> struct variant_helper<T, Types...> { VARIANT_INLINE static void destroy(const std::size_t type_index, void* data) { @@ -215,7 +236,8 @@ struct variant_helper<T, Types...> } } - VARIANT_INLINE static void move(const std::size_t old_type_index, void* old_value, void* new_value) + VARIANT_INLINE static void move(const std::size_t old_type_index, + void* old_value, void* new_value) { if (old_type_index == sizeof...(Types)) { @@ -223,11 +245,13 @@ struct variant_helper<T, Types...> } else { - variant_helper<Types...>::move(old_type_index, old_value, new_value); + variant_helper<Types...>::move(old_type_index, old_value, + new_value); } } - VARIANT_INLINE static void copy(const std::size_t old_type_index, const void* old_value, void* new_value) + VARIANT_INLINE static void copy(const std::size_t old_type_index, + const void* old_value, void* new_value) { if (old_type_index == sizeof...(Types)) { @@ -235,51 +259,60 @@ struct variant_helper<T, Types...> } else { - variant_helper<Types...>::copy(old_type_index, old_value, new_value); + variant_helper<Types...>::copy(old_type_index, old_value, + new_value); } } }; -template <> -struct variant_helper<> +template <> struct variant_helper<> { - VARIANT_INLINE static void destroy(const std::size_t, void*) {} - VARIANT_INLINE static void move(const std::size_t, void*, void*) {} - VARIANT_INLINE static void copy(const std::size_t, const void*, void*) {} + VARIANT_INLINE static void destroy(const std::size_t, void*) + { + } + VARIANT_INLINE static void move(const std::size_t, void*, void*) + { + } + VARIANT_INLINE static void copy(const std::size_t, const void*, void*) + { + } }; -template <typename T> -struct unwrapper +template <typename T> struct unwrapper { - static T const& apply_const(T const& obj) { return obj; } - static T& apply(T& obj) { return obj; } + static T const& apply_const(T const& obj) + { + return obj; + } + static T& apply(T& obj) + { + return obj; + } }; -template <typename T> -struct unwrapper<recursive_wrapper<T>> +template <typename T> struct unwrapper<recursive_wrapper<T>> { - static auto apply_const(recursive_wrapper<T> const& obj) - -> typename recursive_wrapper<T>::type const& + static auto apply_const(recursive_wrapper<T> const& obj) -> + typename recursive_wrapper<T>::type const& { return obj.get(); } - static auto apply(recursive_wrapper<T>& obj) - -> typename recursive_wrapper<T>::type& + static auto apply(recursive_wrapper<T>& obj) -> + typename recursive_wrapper<T>::type& { return obj.get(); } }; -template <typename T> -struct unwrapper<std::reference_wrapper<T>> +template <typename T> struct unwrapper<std::reference_wrapper<T>> { - static auto apply_const(std::reference_wrapper<T> const& obj) - -> typename std::reference_wrapper<T>::type const& + static auto apply_const(std::reference_wrapper<T> const& obj) -> + typename std::reference_wrapper<T>::type const& { return obj.get(); } - static auto apply(std::reference_wrapper<T>& obj) - -> typename std::reference_wrapper<T>::type& + static auto apply(std::reference_wrapper<T>& obj) -> + typename std::reference_wrapper<T>::type& { return obj.get(); } @@ -299,7 +332,8 @@ struct dispatcher<F, V, R, T, Types...> } else { - return dispatcher<F, V, R, Types...>::apply_const(v, std::forward<F>(f)); + return dispatcher<F, V, R, Types...>::apply_const( + v, std::forward<F>(f)); } } @@ -333,19 +367,22 @@ struct dispatcher<F, V, R, T> template <typename F, typename V, typename R, typename T, typename... Types> struct binary_dispatcher_rhs; -template <typename F, typename V, typename R, typename T0, typename T1, typename... Types> +template <typename F, typename V, typename R, typename T0, typename T1, + typename... Types> struct binary_dispatcher_rhs<F, V, R, T0, T1, Types...> { VARIANT_INLINE static R apply_const(V const& lhs, V const& rhs, F&& f) { if (rhs.template is<T1>()) // call binary functor { - return f(unwrapper<T0>::apply_const(lhs.template get_unchecked<T0>()), - unwrapper<T1>::apply_const(rhs.template get_unchecked<T1>())); + return f( + unwrapper<T0>::apply_const(lhs.template get_unchecked<T0>()), + unwrapper<T1>::apply_const(rhs.template get_unchecked<T1>())); } else { - return binary_dispatcher_rhs<F, V, R, T0, Types...>::apply_const(lhs, rhs, std::forward<F>(f)); + return binary_dispatcher_rhs<F, V, R, T0, Types...>::apply_const( + lhs, rhs, std::forward<F>(f)); } } @@ -358,7 +395,8 @@ struct binary_dispatcher_rhs<F, V, R, T0, T1, Types...> } else { - return binary_dispatcher_rhs<F, V, R, T0, Types...>::apply(lhs, rhs, std::forward<F>(f)); + return binary_dispatcher_rhs<F, V, R, T0, Types...>::apply( + lhs, rhs, std::forward<F>(f)); } } }; @@ -382,19 +420,22 @@ struct binary_dispatcher_rhs<F, V, R, T0, T1> template <typename F, typename V, typename R, typename T, typename... Types> struct binary_dispatcher_lhs; -template <typename F, typename V, typename R, typename T0, typename T1, typename... Types> +template <typename F, typename V, typename R, typename T0, typename T1, + typename... Types> struct binary_dispatcher_lhs<F, V, R, T0, T1, Types...> { VARIANT_INLINE static R apply_const(V const& lhs, V const& rhs, F&& f) { if (lhs.template is<T1>()) // call binary functor { - return f(unwrapper<T1>::apply_const(lhs.template get_unchecked<T1>()), - unwrapper<T0>::apply_const(rhs.template get_unchecked<T0>())); + return f( + unwrapper<T1>::apply_const(lhs.template get_unchecked<T1>()), + unwrapper<T0>::apply_const(rhs.template get_unchecked<T0>())); } else { - return binary_dispatcher_lhs<F, V, R, T0, Types...>::apply_const(lhs, rhs, std::forward<F>(f)); + return binary_dispatcher_lhs<F, V, R, T0, Types...>::apply_const( + lhs, rhs, std::forward<F>(f)); } } @@ -407,7 +448,8 @@ struct binary_dispatcher_lhs<F, V, R, T0, T1, Types...> } else { - return binary_dispatcher_lhs<F, V, R, T0, Types...>::apply(lhs, rhs, std::forward<F>(f)); + return binary_dispatcher_lhs<F, V, R, T0, Types...>::apply( + lhs, rhs, std::forward<F>(f)); } } }; @@ -440,19 +482,24 @@ struct binary_dispatcher<F, V, R, T, Types...> { if (v1.template is<T>()) { - return f(unwrapper<T>::apply_const(v0.template get_unchecked<T>()), - unwrapper<T>::apply_const(v1.template get_unchecked<T>())); // call binary functor + return f( + unwrapper<T>::apply_const(v0.template get_unchecked<T>()), + unwrapper<T>::apply_const( + v1.template get_unchecked<T>())); // call binary functor } else { - return binary_dispatcher_rhs<F, V, R, T, Types...>::apply_const(v0, v1, std::forward<F>(f)); + return binary_dispatcher_rhs<F, V, R, T, Types...>::apply_const( + v0, v1, std::forward<F>(f)); } } else if (v1.template is<T>()) { - return binary_dispatcher_lhs<F, V, R, T, Types...>::apply_const(v0, v1, std::forward<F>(f)); + return binary_dispatcher_lhs<F, V, R, T, Types...>::apply_const( + v0, v1, std::forward<F>(f)); } - return binary_dispatcher<F, V, R, Types...>::apply_const(v0, v1, std::forward<F>(f)); + return binary_dispatcher<F, V, R, Types...>::apply_const( + v0, v1, std::forward<F>(f)); } VARIANT_INLINE static R apply(V& v0, V& v1, F&& f) @@ -461,19 +508,24 @@ struct binary_dispatcher<F, V, R, T, Types...> { if (v1.template is<T>()) { - return f(unwrapper<T>::apply(v0.template get_unchecked<T>()), - unwrapper<T>::apply(v1.template get_unchecked<T>())); // call binary functor + return f( + unwrapper<T>::apply(v0.template get_unchecked<T>()), + unwrapper<T>::apply( + v1.template get_unchecked<T>())); // call binary functor } else { - return binary_dispatcher_rhs<F, V, R, T, Types...>::apply(v0, v1, std::forward<F>(f)); + return binary_dispatcher_rhs<F, V, R, T, Types...>::apply( + v0, v1, std::forward<F>(f)); } } else if (v1.template is<T>()) { - return binary_dispatcher_lhs<F, V, R, T, Types...>::apply(v0, v1, std::forward<F>(f)); + return binary_dispatcher_lhs<F, V, R, T, Types...>::apply( + v0, v1, std::forward<F>(f)); } - return binary_dispatcher<F, V, R, Types...>::apply(v0, v1, std::forward<F>(f)); + return binary_dispatcher<F, V, R, Types...>::apply(v0, v1, + std::forward<F>(f)); } }; @@ -483,21 +535,22 @@ struct binary_dispatcher<F, V, R, T> VARIANT_INLINE static R apply_const(V const& v0, V const& v1, F&& f) { return f(unwrapper<T>::apply_const(v0.template get_unchecked<T>()), - unwrapper<T>::apply_const(v1.template get_unchecked<T>())); // call binary functor + unwrapper<T>::apply_const( + v1.template get_unchecked<T>())); // call binary functor } VARIANT_INLINE static R apply(V& v0, V& v1, F&& f) { return f(unwrapper<T>::apply(v0.template get_unchecked<T>()), - unwrapper<T>::apply(v1.template get_unchecked<T>())); // call binary functor + unwrapper<T>::apply( + v1.template get_unchecked<T>())); // call binary functor } }; // comparator functors struct equal_comp { - template <typename T> - bool operator()(T const& lhs, T const& rhs) const + template <typename T> bool operator()(T const& lhs, T const& rhs) const { return lhs == rhs; } @@ -505,29 +558,27 @@ struct equal_comp struct less_comp { - template <typename T> - bool operator()(T const& lhs, T const& rhs) const + template <typename T> bool operator()(T const& lhs, T const& rhs) const { return lhs < rhs; } }; -template <typename Variant, typename Comp> -class comparer +template <typename Variant, typename Comp> class comparer { -public: - explicit comparer(Variant const& lhs) noexcept - : lhs_(lhs) {} + public: + explicit comparer(Variant const& lhs) noexcept : lhs_(lhs) + { + } comparer& operator=(comparer const&) = delete; // visitor - template <typename T> - bool operator()(T const& rhs_content) const + template <typename T> bool operator()(T const& rhs_content) const { T const& lhs_content = lhs_.template get_unchecked<T>(); return Comp()(lhs_content, rhs_content); } -private: + private: Variant const& lhs_; }; @@ -537,56 +588,69 @@ struct no_init { }; -template <typename... Types> -class variant +template <typename... Types> class variant { - static_assert(sizeof...(Types) > 0, "Template parameter type list of variant can not be empty"); - static_assert(!detail::disjunction<std::is_reference<Types>...>::value, "Variant can not hold reference types. Maybe use std::reference_wrapper?"); - -private: - static const std::size_t data_size = detail::static_max<sizeof(Types)...>::value; - static const std::size_t data_align = detail::static_max<alignof(Types)...>::value; - - using first_type = typename std::tuple_element<0, std::tuple<Types...>>::type; - using data_type = typename std::aligned_storage<data_size, data_align>::type; + static_assert(sizeof...(Types) > 0, + "Template parameter type list of variant can not be empty"); + static_assert(!detail::disjunction<std::is_reference<Types>...>::value, + "Variant can not hold reference types. Maybe use " + "std::reference_wrapper?"); + + private: + static const std::size_t data_size = + detail::static_max<sizeof(Types)...>::value; + static const std::size_t data_align = + detail::static_max<alignof(Types)...>::value; + + using first_type = + typename std::tuple_element<0, std::tuple<Types...>>::type; + using data_type = + typename std::aligned_storage<data_size, data_align>::type; using helper_type = detail::variant_helper<Types...>; std::size_t type_index; data_type data; -public: - VARIANT_INLINE variant() noexcept(std::is_nothrow_default_constructible<first_type>::value) - : type_index(sizeof...(Types)-1) + public: + VARIANT_INLINE variant() noexcept( + std::is_nothrow_default_constructible<first_type>::value) : + type_index(sizeof...(Types) - 1) { - static_assert(std::is_default_constructible<first_type>::value, "First type in variant must be default constructible to allow default construction of variant"); + static_assert(std::is_default_constructible<first_type>::value, + "First type in variant must be default constructible to " + "allow default construction of variant"); new (&data) first_type(); } - VARIANT_INLINE variant(no_init) noexcept - : type_index(detail::invalid_value) {} + VARIANT_INLINE variant(no_init) noexcept : type_index(detail::invalid_value) + { + } // http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers template <typename T, typename Traits = detail::value_traits<T, Types...>, typename Enable = typename std::enable_if<Traits::is_valid>::type> - VARIANT_INLINE variant(T&& val) noexcept(std::is_nothrow_constructible<typename Traits::target_type, T&&>::value) - : type_index(Traits::index) + VARIANT_INLINE variant(T&& val) noexcept( + std::is_nothrow_constructible<typename Traits::target_type, + T&&>::value) : + type_index(Traits::index) { new (&data) typename Traits::target_type(std::forward<T>(val)); } - VARIANT_INLINE variant(variant<Types...> const& old) - : type_index(old.type_index) + VARIANT_INLINE variant(variant<Types...> const& old) : + type_index(old.type_index) { helper_type::copy(old.type_index, &old.data, &data); } - VARIANT_INLINE variant(variant<Types...>&& old) noexcept(std::is_nothrow_move_constructible<std::tuple<Types...>>::value) - : type_index(old.type_index) + VARIANT_INLINE variant(variant<Types...>&& old) noexcept( + std::is_nothrow_move_constructible<std::tuple<Types...>>::value) : + type_index(old.type_index) { helper_type::move(old.type_index, &old.data, &data); } -private: + private: VARIANT_INLINE void copy_assign(variant<Types...> const& rhs) { helper_type::destroy(type_index, &data); @@ -603,7 +667,7 @@ private: type_index = rhs.type_index; } -public: + public: VARIANT_INLINE variant<Types...>& operator=(variant<Types...>&& other) { move_assign(std::move(other)); @@ -636,17 +700,21 @@ public: } template <typename T, typename std::enable_if< - (detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr> + (detail::direct_type<T, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE bool is() const { return type_index == detail::direct_type<T, Types...>::index; } - template <typename T,typename std::enable_if< - (detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr> + template <typename T, + typename std::enable_if< + (detail::direct_type<recursive_wrapper<T>, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE bool is() const { - return type_index == detail::direct_type<recursive_wrapper<T>, Types...>::index; + return type_index == + detail::direct_type<recursive_wrapper<T>, Types...>::index; } VARIANT_INLINE bool valid() const @@ -665,7 +733,8 @@ public: // get_unchecked<T>() template <typename T, typename std::enable_if< - (detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr> + (detail::direct_type<T, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T& get_unchecked() { return *reinterpret_cast<T*>(&data); @@ -674,7 +743,8 @@ public: #ifdef HAS_EXCEPTIONS // get<T>() template <typename T, typename std::enable_if< - (detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr> + (detail::direct_type<T, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T& get() { if (type_index == detail::direct_type<T, Types...>::index) @@ -689,7 +759,8 @@ public: #endif template <typename T, typename std::enable_if< - (detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr> + (detail::direct_type<T, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T const& get_unchecked() const { return *reinterpret_cast<T const*>(&data); @@ -697,7 +768,8 @@ public: #ifdef HAS_EXCEPTIONS template <typename T, typename std::enable_if< - (detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr> + (detail::direct_type<T, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T const& get() const { if (type_index == detail::direct_type<T, Types...>::index) @@ -712,8 +784,10 @@ public: #endif // get_unchecked<T>() - T stored as recursive_wrapper<T> - template <typename T, typename std::enable_if< - (detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr> + template <typename T, + typename std::enable_if< + (detail::direct_type<recursive_wrapper<T>, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T& get_unchecked() { return (*reinterpret_cast<recursive_wrapper<T>*>(&data)).get(); @@ -721,11 +795,14 @@ public: #ifdef HAS_EXCEPTIONS // get<T>() - T stored as recursive_wrapper<T> - template <typename T, typename std::enable_if< - (detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr> + template <typename T, + typename std::enable_if< + (detail::direct_type<recursive_wrapper<T>, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T& get() { - if (type_index == detail::direct_type<recursive_wrapper<T>, Types...>::index) + if (type_index == + detail::direct_type<recursive_wrapper<T>, Types...>::index) { return (*reinterpret_cast<recursive_wrapper<T>*>(&data)).get(); } @@ -736,21 +813,27 @@ public: } #endif - template <typename T, typename std::enable_if< - (detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr> + template <typename T, + typename std::enable_if< + (detail::direct_type<recursive_wrapper<T>, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T const& get_unchecked() const { return (*reinterpret_cast<recursive_wrapper<T> const*>(&data)).get(); } #ifdef HAS_EXCEPTIONS - template <typename T, typename std::enable_if< - (detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr> + template <typename T, + typename std::enable_if< + (detail::direct_type<recursive_wrapper<T>, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T const& get() const { - if (type_index == detail::direct_type<recursive_wrapper<T>, Types...>::index) + if (type_index == + detail::direct_type<recursive_wrapper<T>, Types...>::index) { - return (*reinterpret_cast<recursive_wrapper<T> const*>(&data)).get(); + return (*reinterpret_cast<recursive_wrapper<T> const*>(&data)) + .get(); } else { @@ -760,8 +843,11 @@ public: #endif // get_unchecked<T>() - T stored as std::reference_wrapper<T> - template <typename T, typename std::enable_if< - (detail::direct_type<std::reference_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr> + template < + typename T, + typename std::enable_if< + (detail::direct_type<std::reference_wrapper<T>, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T& get_unchecked() { return (*reinterpret_cast<std::reference_wrapper<T>*>(&data)).get(); @@ -769,11 +855,15 @@ public: #ifdef HAS_EXCEPTIONS // get<T>() - T stored as std::reference_wrapper<T> - template <typename T, typename std::enable_if< - (detail::direct_type<std::reference_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr> + template < + typename T, + typename std::enable_if< + (detail::direct_type<std::reference_wrapper<T>, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T& get() { - if (type_index == detail::direct_type<std::reference_wrapper<T>, Types...>::index) + if (type_index == + detail::direct_type<std::reference_wrapper<T>, Types...>::index) { return (*reinterpret_cast<std::reference_wrapper<T>*>(&data)).get(); } @@ -784,21 +874,32 @@ public: } #endif - template <typename T, typename std::enable_if< - (detail::direct_type<std::reference_wrapper<T const>, Types...>::index != detail::invalid_value)>::type* = nullptr> + template <typename T, + typename std::enable_if< + (detail::direct_type<std::reference_wrapper<T const>, + Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T const& get_unchecked() const { - return (*reinterpret_cast<std::reference_wrapper<T const> const*>(&data)).get(); + return (*reinterpret_cast<std::reference_wrapper<T const> const*>( + &data)) + .get(); } #ifdef HAS_EXCEPTIONS - template <typename T, typename std::enable_if< - (detail::direct_type<std::reference_wrapper<T const>, Types...>::index != detail::invalid_value)>::type* = nullptr> + template <typename T, + typename std::enable_if< + (detail::direct_type<std::reference_wrapper<T const>, + Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE T const& get() const { - if (type_index == detail::direct_type<std::reference_wrapper<T const>, Types...>::index) + if (type_index == detail::direct_type<std::reference_wrapper<T const>, + Types...>::index) { - return (*reinterpret_cast<std::reference_wrapper<T const> const*>(&data)).get(); + return (*reinterpret_cast<std::reference_wrapper<T const> const*>( + &data)) + .get(); } else { @@ -816,46 +917,63 @@ public: VARIANT_INLINE int which() const noexcept { - return static_cast<int>(sizeof...(Types)-type_index - 1); + return static_cast<int>(sizeof...(Types) - type_index - 1); } template <typename T, typename std::enable_if< - (detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr> + (detail::direct_type<T, Types...>::index != + detail::invalid_value)>::type* = nullptr> VARIANT_INLINE static constexpr int which() noexcept { - return static_cast<int>(sizeof...(Types)-detail::direct_type<T, Types...>::index - 1); + return static_cast<int>(sizeof...(Types) - + detail::direct_type<T, Types...>::index - 1); } // visitor // unary - template <typename F, typename V, typename R = typename detail::result_of_unary_visit<F, first_type>::type> + template <typename F, typename V, + typename R = + typename detail::result_of_unary_visit<F, first_type>::type> auto VARIANT_INLINE static visit(V const& v, F&& f) - -> decltype(detail::dispatcher<F, V, R, Types...>::apply_const(v, std::forward<F>(f))) + -> decltype(detail::dispatcher<F, V, R, Types...>::apply_const( + v, std::forward<F>(f))) { - return detail::dispatcher<F, V, R, Types...>::apply_const(v, std::forward<F>(f)); + return detail::dispatcher<F, V, R, Types...>::apply_const( + v, std::forward<F>(f)); } // non-const - template <typename F, typename V, typename R = typename detail::result_of_unary_visit<F, first_type>::type> - auto VARIANT_INLINE static visit(V& v, F&& f) - -> decltype(detail::dispatcher<F, V, R, Types...>::apply(v, std::forward<F>(f))) + template <typename F, typename V, + typename R = + typename detail::result_of_unary_visit<F, first_type>::type> + auto VARIANT_INLINE static visit(V& v, F&& f) -> decltype( + detail::dispatcher<F, V, R, Types...>::apply(v, std::forward<F>(f))) { - return detail::dispatcher<F, V, R, Types...>::apply(v, std::forward<F>(f)); + return detail::dispatcher<F, V, R, Types...>::apply(v, + std::forward<F>(f)); } // binary // const - template <typename F, typename V, typename R = typename detail::result_of_binary_visit<F, first_type>::type> + template <typename F, typename V, + typename R = + typename detail::result_of_binary_visit<F, first_type>::type> auto VARIANT_INLINE static binary_visit(V const& v0, V const& v1, F&& f) - -> decltype(detail::binary_dispatcher<F, V, R, Types...>::apply_const(v0, v1, std::forward<F>(f))) + -> decltype(detail::binary_dispatcher<F, V, R, Types...>::apply_const( + v0, v1, std::forward<F>(f))) { - return detail::binary_dispatcher<F, V, R, Types...>::apply_const(v0, v1, std::forward<F>(f)); + return detail::binary_dispatcher<F, V, R, Types...>::apply_const( + v0, v1, std::forward<F>(f)); } // non-const - template <typename F, typename V, typename R = typename detail::result_of_binary_visit<F, first_type>::type> + template <typename F, typename V, + typename R = + typename detail::result_of_binary_visit<F, first_type>::type> auto VARIANT_INLINE static binary_visit(V& v0, V& v1, F&& f) - -> decltype(detail::binary_dispatcher<F, V, R, Types...>::apply(v0, v1, std::forward<F>(f))) + -> decltype(detail::binary_dispatcher<F, V, R, Types...>::apply( + v0, v1, std::forward<F>(f))) { - return detail::binary_dispatcher<F, V, R, Types...>::apply(v0, v1, std::forward<F>(f)); + return detail::binary_dispatcher<F, V, R, Types...>::apply( + v0, v1, std::forward<F>(f)); } ~variant() noexcept // no-throw destructor @@ -909,14 +1027,16 @@ public: // unary visitor interface // const template <typename F, typename V> -auto VARIANT_INLINE apply_visitor(F&& f, V const& v) -> decltype(V::visit(v, std::forward<F>(f))) +auto VARIANT_INLINE apply_visitor(F&& f, V const& v) + -> decltype(V::visit(v, std::forward<F>(f))) { return V::visit(v, std::forward<F>(f)); } // non-const template <typename F, typename V> -auto VARIANT_INLINE apply_visitor(F&& f, V& v) -> decltype(V::visit(v, std::forward<F>(f))) +auto VARIANT_INLINE apply_visitor(F&& f, V& v) + -> decltype(V::visit(v, std::forward<F>(f))) { return V::visit(v, std::forward<F>(f)); } @@ -924,37 +1044,38 @@ auto VARIANT_INLINE apply_visitor(F&& f, V& v) -> decltype(V::visit(v, std::forw // binary visitor interface // const template <typename F, typename V> -auto VARIANT_INLINE apply_visitor(F&& f, V const& v0, V const& v1) -> decltype(V::binary_visit(v0, v1, std::forward<F>(f))) +auto VARIANT_INLINE apply_visitor(F&& f, V const& v0, V const& v1) + -> decltype(V::binary_visit(v0, v1, std::forward<F>(f))) { return V::binary_visit(v0, v1, std::forward<F>(f)); } // non-const template <typename F, typename V> -auto VARIANT_INLINE apply_visitor(F&& f, V& v0, V& v1) -> decltype(V::binary_visit(v0, v1, std::forward<F>(f))) +auto VARIANT_INLINE apply_visitor(F&& f, V& v0, V& v1) + -> decltype(V::binary_visit(v0, v1, std::forward<F>(f))) { return V::binary_visit(v0, v1, std::forward<F>(f)); } -// getter interface + // getter interface #ifdef HAS_EXCEPTIONS template <typename ResultType, typename T> -auto get(T& var)->decltype(var.template get<ResultType>()) +auto get(T& var) -> decltype(var.template get<ResultType>()) { return var.template get<ResultType>(); } #endif -template <typename ResultType, typename T> -ResultType& get_unchecked(T& var) +template <typename ResultType, typename T> ResultType& get_unchecked(T& var) { return var.template get_unchecked<ResultType>(); } #ifdef HAS_EXCEPTIONS template <typename ResultType, typename T> -auto get(T const& var)->decltype(var.template get<ResultType>()) +auto get(T const& var) -> decltype(var.template get<ResultType>()) { return var.template get<ResultType>(); } diff --git a/sdbusplus/bus/match.hpp b/sdbusplus/bus/match.hpp index 62c0370..10cd679 100644 --- a/sdbusplus/bus/match.hpp +++ b/sdbusplus/bus/match.hpp @@ -41,8 +41,8 @@ struct match * @param[in] context - An optional context to pass to the handler. */ match(sdbusplus::bus::bus& bus, const char* match, - sd_bus_message_handler_t handler, void* context = nullptr) - : _slot(nullptr) + sd_bus_message_handler_t handler, void* context = nullptr) : + _slot(nullptr) { sd_bus_slot* slot = nullptr; sd_bus_add_match(bus.get(), &slot, match, handler, context); @@ -50,8 +50,10 @@ struct match _slot = decltype(_slot){slot}; } match(sdbusplus::bus::bus& bus, const std::string& _match, - sd_bus_message_handler_t handler, void* context = nullptr) - : match(bus, _match.c_str(), handler, context) {} + sd_bus_message_handler_t handler, void* context = nullptr) : + match(bus, _match.c_str(), handler, context) + { + } using callback_t = std::function<void(sdbusplus::message::message&)>; @@ -61,10 +63,9 @@ struct match * @param[in] match - The match to register. * @param[in] callback - The callback for matches. */ - match(sdbusplus::bus::bus& bus, const char* match, - callback_t callback) - : _slot(nullptr), - _callback(std::make_unique<callback_t>(std::move(callback))) + match(sdbusplus::bus::bus& bus, const char* match, callback_t callback) : + _slot(nullptr), + _callback(std::make_unique<callback_t>(std::move(callback))) { sd_bus_slot* slot = nullptr; sd_bus_add_match(bus.get(), &slot, match, callCallback, @@ -73,23 +74,24 @@ struct match _slot = decltype(_slot){slot}; } match(sdbusplus::bus::bus& bus, const std::string& _match, - callback_t callback) - : match(bus, _match.c_str(), callback) {} + callback_t callback) : + match(bus, _match.c_str(), callback) + { + } - private: - slot::slot _slot; - std::unique_ptr<callback_t> _callback = nullptr; + private: + slot::slot _slot; + std::unique_ptr<callback_t> _callback = nullptr; - static int callCallback(sd_bus_message *m, void* context, - sd_bus_error* e) - { - auto c = static_cast<callback_t*>(context); - message::message message{m}; + static int callCallback(sd_bus_message* m, void* context, sd_bus_error* e) + { + auto c = static_cast<callback_t*>(context); + message::message message{m}; - (*c)(message); + (*c)(message); - return 0; - } + return 0; + } }; /** Utilities for defining match rules based on the DBus specification */ @@ -101,29 +103,65 @@ using namespace std::string_literals; namespace type { -inline auto signal() { return "type='signal',"s; } -inline auto method() { return "type='method',"s; } -inline auto method_return() { return "type='method_return',"s; } -inline auto error() { return "type='error',"s; } +inline auto signal() +{ + return "type='signal',"s; +} +inline auto method() +{ + return "type='method',"s; +} +inline auto method_return() +{ + return "type='method_return',"s; +} +inline auto error() +{ + return "type='error',"s; +} } // namespace type -inline auto sender(const std::string& s) { return "sender='"s + s + "',"; } +inline auto sender(const std::string& s) +{ + return "sender='"s + s + "',"; +} inline auto interface(const std::string& s) - { return "interface='"s + s + "',"; } -inline auto member(const std::string& s) { return "member='"s + s + "',"; } -inline auto path(const std::string& s) { return "path='"s + s + "',"; } +{ + return "interface='"s + s + "',"; +} +inline auto member(const std::string& s) +{ + return "member='"s + s + "',"; +} +inline auto path(const std::string& s) +{ + return "path='"s + s + "',"; +} inline auto path_namespace(const std::string& s) - { return "path_namespace='"s + s + "',"; } +{ + return "path_namespace='"s + s + "',"; +} inline auto destination(const std::string& s) - { return "destination='"s + s + "',"; } +{ + return "destination='"s + s + "',"; +} inline auto argN(size_t n, const std::string& s) - { return "arg"s + std::to_string(n) + "='"s + s + "',"; } +{ + return "arg"s + std::to_string(n) + "='"s + s + "',"; +} inline auto argNpath(size_t n, const std::string& s) - { return "arg"s + std::to_string(n) + "path='"s + s + "',"; } +{ + return "arg"s + std::to_string(n) + "path='"s + s + "',"; +} inline auto arg0namespace(const std::string& s) - { return "arg0namespace='"s + s + "',"; } -inline auto eavesdrop() { return "eavesdrop='true',"s; } +{ + return "arg0namespace='"s + s + "',"; +} +inline auto eavesdrop() +{ + return "eavesdrop='true',"s; +} inline auto nameOwnerChanged() { @@ -158,11 +196,8 @@ inline auto interfacesRemoved(const std::string& p) inline auto propertiesChanged(const std::string& p, const std::string& i) { - return type::signal() + - path(p) + - member("PropertiesChanged"s) + - interface("org.freedesktop.DBus.Properties"s) + - argN(0, i); + return type::signal() + path(p) + member("PropertiesChanged"s) + + interface("org.freedesktop.DBus.Properties"s) + argN(0, i); } /** diff --git a/sdbusplus/message.hpp b/sdbusplus/message.hpp index 21d3eb3..31ca95d 100644 --- a/sdbusplus/message.hpp +++ b/sdbusplus/message.hpp @@ -10,8 +10,11 @@ namespace sdbusplus { - // Forward declare sdbusplus::bus::bus for 'friend'ship. -namespace bus { struct bus; }; +// Forward declare sdbusplus::bus::bus for 'friend'ship. +namespace bus +{ +struct bus; +}; namespace message { @@ -41,14 +44,14 @@ using msg = std::unique_ptr<sd_bus_message, MsgDeleter>; */ struct message { - /* Define all of the basic class operations: - * Not allowed: - * - Default constructor to avoid nullptrs. - * - Copy operations due to internal unique_ptr. - * Allowed: - * - Move operations. - * - Destructor. - */ + /* Define all of the basic class operations: + * Not allowed: + * - Default constructor to avoid nullptrs. + * - Copy operations due to internal unique_ptr. + * Allowed: + * - Move operations. + * - Destructor. + */ message() = delete; message(const message&) = delete; message& operator=(const message&) = delete; @@ -61,27 +64,36 @@ struct message * Takes increment ref-count of the msg-pointer and release when * destructed. */ - explicit message(msgp_t m) : _msg(sd_bus_message_ref(m)) {} + explicit message(msgp_t m) : _msg(sd_bus_message_ref(m)) + { + } /** @brief Constructor for 'msgp_t'. * * Takes ownership of the msg-pointer and releases it when done. */ - message(msgp_t m, std::false_type) : _msg(m) {} + message(msgp_t m, std::false_type) : _msg(m) + { + } /** @brief Release ownership of the stored msg-pointer. */ - msgp_t release() { return _msg.release(); } + msgp_t release() + { + return _msg.release(); + } /** @brief Check if message contains a real pointer. (non-nullptr). */ - explicit operator bool() const { return bool(_msg); } - + explicit operator bool() const + { + return bool(_msg); + } /** @brief Perform sd_bus_message_append, with automatic type deduction. * * @tparam ...Args - Type of items to append to message. * @param[in] args - Items to append to message. */ - template <typename ...Args> void append(Args&&... args) + template <typename... Args> void append(Args&&... args) { sdbusplus::message::append(_msg.get(), std::forward<Args>(args)...); } @@ -91,7 +103,7 @@ struct message * @tparam ...Args - Type of items to read from message. * @param[out] args - Items to read from message. */ - template <typename ...Args> void read(Args&&... args) + template <typename... Args> void read(Args&&... args) { sdbusplus::message::read(_msg.get(), std::forward<Args>(args)...); } @@ -164,9 +176,9 @@ struct message } /** @brief Get the transaction cookie of a message. - * - * @return The transaction cookie of a message. - */ + * + * @return The transaction cookie of a message. + */ auto get_cookie() { uint64_t cookie; @@ -216,14 +228,20 @@ struct message } /** @brief Perform a 'signal-send' call. */ - void signal_send() { method_return(); } + void signal_send() + { + method_return(); + } friend struct sdbusplus::bus::bus; - private: - /** @brief Get a pointer to the owned 'msgp_t'. */ - msgp_t get() { return _msg.get(); } - details::msg _msg; + private: + /** @brief Get a pointer to the owned 'msgp_t'. */ + msgp_t get() + { + return _msg.get(); + } + details::msg _msg; }; } // namespace message diff --git a/sdbusplus/message/append.hpp b/sdbusplus/message/append.hpp index 8818220..6558fd9 100644 --- a/sdbusplus/message/append.hpp +++ b/sdbusplus/message/append.hpp @@ -17,7 +17,7 @@ namespace message * (This is an empty no-op function that is useful in some cases for * variadic template reasons.) */ -inline void append(sd_bus_message* m) {}; +inline void append(sd_bus_message* m){}; /** @brief Append data into an sdbus message. * * @param[in] msg - The message to append to. @@ -29,7 +29,7 @@ inline void append(sd_bus_message* m) {}; * appropriate type parameters. It may also do conversions, where needed, * to convert C++ types into C representations (eg. string, vector). */ -template <typename ...Args> void append(sd_bus_message* m, Args&&... args); +template <typename... Args> void append(sd_bus_message* m, Args&&... args); namespace details { @@ -44,30 +44,50 @@ namespace details * User-defined types are expected to inherit from std::false_type. * */ -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 {}; - // object_path needs a c_str() call. -template<> struct can_append_multiple<object_path> : std::false_type {}; - // signature needs a c_str() call. -template<> struct can_append_multiple<signature> : 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 {}; - // std::pair needs to be broken down into components. -template<typename T1, typename T2> -struct can_append_multiple<std::pair<T1,T2>> : std::false_type {}; - // std::map needs a loop. -template<typename T1, typename T2> -struct can_append_multiple<std::map<T1,T2>> : std::false_type {}; - // std::tuple needs to be broken down into components. -template<typename ...Args> -struct can_append_multiple<std::tuple<Args...>> : std::false_type {}; - // variant needs to be broken down into components. -template<typename ...Args> -struct can_append_multiple<variant<Args...>> : std::false_type {}; +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 +{ +}; +// object_path needs a c_str() call. +template <> struct can_append_multiple<object_path> : std::false_type +{ +}; +// signature needs a c_str() call. +template <> struct can_append_multiple<signature> : 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 +{ +}; +// std::pair needs to be broken down into components. +template <typename T1, typename T2> +struct can_append_multiple<std::pair<T1, T2>> : std::false_type +{ +}; +// std::map needs a loop. +template <typename T1, typename T2> +struct can_append_multiple<std::map<T1, T2>> : std::false_type +{ +}; +// std::tuple needs to be broken down into components. +template <typename... Args> +struct can_append_multiple<std::tuple<Args...>> : std::false_type +{ +}; +// variant needs to be broken down into components. +template <typename... Args> +struct can_append_multiple<variant<Args...>> : std::false_type +{ +}; /** @struct append_single * @brief Utility to append a single C++ element into a sd_bus_message. @@ -77,11 +97,10 @@ struct can_append_multiple<variant<Args...>> : std::false_type {}; * * @tparam S - Type of element to append. */ -template<typename S> struct append_single +template <typename S> struct append_single { // Downcast - template<typename T> - using Td = types::details::type_id_downcast_t<T>; + template <typename T> using Td = types::details::type_id_downcast_t<T>; // sd_bus_message_append_basic expects a T* (cast to void*) for most types, // so t& is appropriate. In the case of char*, it expects the void* is @@ -89,13 +108,16 @@ template<typename S> struct append_single // // Use these helper templates 'address_of(t)' in place of '&t' to // handle both cases. - template<typename T> - static auto address_of_helper(T&& t, std::false_type) { return &t; } - template<typename T> - static auto address_of_helper(T&& t, std::true_type) { return t; } + template <typename T> static auto address_of_helper(T&& t, std::false_type) + { + return &t; + } + template <typename T> static auto address_of_helper(T&& t, std::true_type) + { + return t; + } - template<typename T> - static auto address_of(T&& t) + template <typename T> static auto address_of(T&& t) { return address_of_helper(std::forward<T>(t), std::is_pointer<std::remove_reference_t<T>>()); @@ -114,14 +136,14 @@ template<typename S> struct append_single * @param[in] m - sd_bus_message to append into. * @param[in] t - The item to append. */ - template<typename T, - typename = std::enable_if_t<std::is_same<S, Td<T>>::value>> + template <typename T, + typename = std::enable_if_t<std::is_same<S, Td<T>>::value>> static void op(sd_bus_message* m, T&& t) { // For this default implementation, we need to ensure that only // basic types are used. static_assert(std::is_fundamental<Td<T>>::value || - std::is_convertible<Td<T>, const char*>::value, + std::is_convertible<Td<T>, const char*>::value, "Non-basic types are not allowed."); constexpr auto dbusType = std::get<0>(types::type_id<T>()); @@ -130,14 +152,13 @@ template<typename S> struct append_single } }; -template<typename T> using append_single_t = - append_single<types::details::type_id_downcast_t<T>>; +template <typename T> +using append_single_t = append_single<types::details::type_id_downcast_t<T>>; /** @brief Specialization of append_single for std::strings. */ template <> struct append_single<std::string> { - template<typename T> - static void op(sd_bus_message* m, T&& s) + template <typename T> static void op(sd_bus_message* m, T&& s) { constexpr auto dbusType = std::get<0>(types::type_id<T>()); sd_bus_message_append_basic(m, dbusType, s.c_str()); @@ -147,20 +168,17 @@ template <> struct append_single<std::string> /** @brief Specialization of append_single for details::string_wrapper. */ template <typename T> struct append_single<details::string_wrapper<T>> { - template<typename S> - static void op(sd_bus_message* m, S&& s) + template <typename S> static void op(sd_bus_message* m, S&& s) { constexpr auto dbusType = std::get<0>(types::type_id<S>()); sd_bus_message_append_basic(m, dbusType, s.str.c_str()); } }; - /** @brief Specialization of append_single for bool. */ template <> struct append_single<bool> { - template<typename T> - static void op(sd_bus_message* m, T&& b) + template <typename T> static void op(sd_bus_message* m, T&& b) { constexpr auto dbusType = std::get<0>(types::type_id<T>()); int i = b; @@ -171,13 +189,15 @@ template <> struct append_single<bool> /** @brief Specialization of append_single for std::vectors. */ template <typename T> struct append_single<std::vector<T>> { - template<typename S> - static void op(sd_bus_message* m, S&& s) + template <typename S> static void op(sd_bus_message* m, S&& s) { constexpr auto dbusType = utility::tuple_to_array(types::type_id<T>()); sd_bus_message_open_container(m, SD_BUS_TYPE_ARRAY, dbusType.data()); - for(auto& i : s) { sdbusplus::message::append(m, i); } + for (auto& i : s) + { + sdbusplus::message::append(m, i); + } sd_bus_message_close_container(m); } }; @@ -185,15 +205,13 @@ template <typename T> struct append_single<std::vector<T>> /** @brief Specialization of append_single for std::pairs. */ template <typename T1, typename T2> struct append_single<std::pair<T1, T2>> { - template <typename S> - static void op(sd_bus_message* m, S&& s) + template <typename S> static void op(sd_bus_message* m, S&& s) { constexpr auto dbusType = utility::tuple_to_array( - std::tuple_cat(types::type_id_nonull<T1>(), - types::type_id<T2>())); + std::tuple_cat(types::type_id_nonull<T1>(), types::type_id<T2>())); - sd_bus_message_open_container( - m, SD_BUS_TYPE_DICT_ENTRY, dbusType.data()); + sd_bus_message_open_container(m, SD_BUS_TYPE_DICT_ENTRY, + dbusType.data()); sdbusplus::message::append(m, s.first, s.second); sd_bus_message_close_container(m); } @@ -202,63 +220,57 @@ template <typename T1, typename T2> struct append_single<std::pair<T1, T2>> /** @brief Specialization of append_single for std::maps. */ template <typename T1, typename T2> struct append_single<std::map<T1, T2>> { - template<typename S> - static void op(sd_bus_message* m, S&& s) + template <typename S> static void op(sd_bus_message* m, S&& s) { constexpr auto dbusType = utility::tuple_to_array( - types::type_id<typename std::map<T1, T2>::value_type>()); + types::type_id<typename std::map<T1, T2>::value_type>()); sd_bus_message_open_container(m, SD_BUS_TYPE_ARRAY, dbusType.data()); - for(auto& i : s) { sdbusplus::message::append(m, i); } + for (auto& i : s) + { + sdbusplus::message::append(m, i); + } sd_bus_message_close_container(m); } }; /** @brief Specialization of append_single for std::tuples. */ -template <typename ...Args> struct append_single<std::tuple<Args...>> +template <typename... Args> struct append_single<std::tuple<Args...>> { - template<typename S, std::size_t... I> + template <typename S, std::size_t... I> static void _op(sd_bus_message* m, S&& s, std::integer_sequence<std::size_t, I...>) { sdbusplus::message::append(m, std::get<I>(s)...); } - template<typename S> - static void op(sd_bus_message* m, S&& s) + template <typename S> static void op(sd_bus_message* m, S&& s) { constexpr auto dbusType = utility::tuple_to_array(std::tuple_cat( - types::type_id_nonull<Args...>(), - std::make_tuple('\0') /* null terminator for C-string */)); + types::type_id_nonull<Args...>(), + std::make_tuple('\0') /* null terminator for C-string */)); - sd_bus_message_open_container( - m, SD_BUS_TYPE_STRUCT, dbusType.data()); - _op(m, std::forward<S>(s), - std::make_index_sequence<sizeof...(Args)>()); + sd_bus_message_open_container(m, SD_BUS_TYPE_STRUCT, dbusType.data()); + _op(m, std::forward<S>(s), std::make_index_sequence<sizeof...(Args)>()); sd_bus_message_close_container(m); - } }; /** @brief Specialization of append_single for std::variant. */ -template <typename ...Args> struct append_single<variant<Args...>> +template <typename... Args> struct append_single<variant<Args...>> { - template<typename S, - typename = std::enable_if_t<0 < sizeof...(Args)>> + template <typename S, typename = std::enable_if_t<0 < sizeof...(Args)>> static void op(sd_bus_message* m, S&& s) { - auto apply = - [m](auto&& arg) - { - constexpr auto dbusType = utility::tuple_to_array( - types::type_id<decltype(arg)>()); - - sd_bus_message_open_container(m, - SD_BUS_TYPE_VARIANT, - dbusType.data()); - sdbusplus::message::append(m, arg); - sd_bus_message_close_container(m); - }; + auto apply = [m](auto&& arg) { + constexpr auto dbusType = + utility::tuple_to_array(types::type_id<decltype(arg)>()); + + sd_bus_message_open_container(m, SD_BUS_TYPE_VARIANT, + dbusType.data()); + sdbusplus::message::append(m, arg); + sd_bus_message_close_container(m); + }; std::remove_reference_t<S>::visit(s, apply); } @@ -274,8 +286,8 @@ template <typename ...Args> struct append_single<variant<Args...>> template <typename Tuple, size_t... I> void append_tuple(sd_bus_message* m, Tuple&& t, std::index_sequence<I...>) { - auto dbusTypes = utility::tuple_to_array( - types::type_id<decltype(std::get<I>(t))...>()); + auto dbusTypes = + utility::tuple_to_array(types::type_id<decltype(std::get<I>(t))...>()); sd_bus_message_append(m, dbusTypes.data(), std::get<I>(t)...); } @@ -288,7 +300,8 @@ void append_tuple(sd_bus_message* m, Tuple&& t, std::index_sequence<I...>) * A tuple of 2 or more entries can be added as a set with * sd_bus_message_append. */ -template <typename Tuple> std::enable_if_t<2 <= std::tuple_size<Tuple>::value> +template <typename Tuple> +std::enable_if_t<2 <= std::tuple_size<Tuple>::value> append_tuple(sd_bus_message* m, Tuple&& t) { append_tuple(m, std::move(t), @@ -305,7 +318,8 @@ append_tuple(sd_bus_message* m, Tuple&& t) * Note: Some 1-entry tuples may need special handling due to * can_append_multiple::value == false. */ -template <typename Tuple> std::enable_if_t<1 == std::tuple_size<Tuple>::value> +template <typename Tuple> +std::enable_if_t<1 == std::tuple_size<Tuple>::value> append_tuple(sd_bus_message* m, Tuple&& t) { using itemType = decltype(std::get<0>(t)); @@ -316,8 +330,11 @@ append_tuple(sd_bus_message* m, Tuple&& t) * * This a no-op function that is useful due to variadic templates. */ -template <typename Tuple> std::enable_if_t<0 == std::tuple_size<Tuple>::value> -inline append_tuple(sd_bus_message* m, Tuple&& t) {} +template <typename Tuple> +std::enable_if_t<0 == std::tuple_size<Tuple>::value> inline append_tuple( + sd_bus_message* m, Tuple&& t) +{ +} /** @brief Group a sequence of C++ types for appending into an sd_bus_message. * @tparam Tuple - A tuple of previously analyzed types. @@ -325,8 +342,9 @@ inline append_tuple(sd_bus_message* m, Tuple&& t) {} * * Specialization for when can_append_multiple<Arg> is true. */ -template <typename Tuple, typename Arg> std::enable_if_t< - can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg> +std::enable_if_t< + can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg); /** @brief Group a sequence of C++ types for appending into an sd_bus_message. * @tparam Tuple - A tuple of previously analyzed types. @@ -334,8 +352,9 @@ append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg); * * Specialization for when can_append_multiple<Arg> is false. */ -template <typename Tuple, typename Arg> std::enable_if_t< - !can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg> +std::enable_if_t< + !can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg); /** @brief Group a sequence of C++ types for appending into an sd_bus_message. * @tparam Tuple - A tuple of previously analyzed types. @@ -344,8 +363,9 @@ append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg); * * Specialization for when can_append_multiple<Arg> is true. */ -template <typename Tuple, typename Arg, typename ...Rest> std::enable_if_t< - can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg, typename... Rest> +std::enable_if_t< + can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest); /** @brief Group a sequence of C++ types for appending into an sd_bus_message. * @tparam Tuple - A tuple of previously analyzed types. @@ -354,24 +374,27 @@ append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest); * * Specialization for when can_append_multiple<Arg> is false. */ -template <typename Tuple, typename Arg, typename ...Rest> std::enable_if_t< - !can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg, typename... Rest> +std::enable_if_t< + !can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest); -template <typename Tuple, typename Arg> std::enable_if_t< - can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg> +std::enable_if_t< + can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg) { // Last element of a sequence and can_append_multiple, so add it to // the tuple and call append_tuple. - append_tuple(m, std::tuple_cat(std::forward<Tuple>(t), - std::forward_as_tuple( - std::forward<Arg>(arg)))); + append_tuple(m, + std::tuple_cat(std::forward<Tuple>(t), + std::forward_as_tuple(std::forward<Arg>(arg)))); } -template <typename Tuple, typename Arg> std::enable_if_t< - !can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg> +std::enable_if_t< + !can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg) { // Last element of a sequence but !can_append_multiple, so call @@ -382,21 +405,24 @@ append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg) append_tuple(m, std::forward_as_tuple(std::forward<Arg>(arg))); } -template <typename Tuple, typename Arg, typename ...Rest> std::enable_if_t< - can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg, typename... Rest> +std::enable_if_t< + can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest) { // Not the last element of a sequence and can_append_multiple, so add it // to the tuple and keep grouping. - append_grouping(m, std::tuple_cat(std::forward<Tuple>(t), - std::forward_as_tuple( - std::forward<Arg>(arg))), - std::forward<Rest>(rest)...); + append_grouping( + m, + std::tuple_cat(std::forward<Tuple>(t), + std::forward_as_tuple(std::forward<Arg>(arg))), + std::forward<Rest>(rest)...); } -template <typename Tuple, typename Arg, typename ...Rest> std::enable_if_t< - !can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg, typename... Rest> +std::enable_if_t< + !can_append_multiple<types::details::type_id_downcast_t<Arg>>::value> append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest) { // Not the last element of a sequence but !can_append_multiple, so call @@ -410,7 +436,7 @@ append_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest) } // namespace details -template <typename ...Args> void append(sd_bus_message* m, Args&&... args) +template <typename... Args> void append(sd_bus_message* m, Args&&... args) { details::append_grouping(m, std::make_tuple(), std::forward<Args>(args)...); } diff --git a/sdbusplus/message/native_types.hpp b/sdbusplus/message/native_types.hpp index ce50f8e..11a4b23 100644 --- a/sdbusplus/message/native_types.hpp +++ b/sdbusplus/message/native_types.hpp @@ -13,8 +13,7 @@ namespace details /** Simple wrapper class for std::string to allow conversion to and from an * alternative typename. */ -template <typename T> -struct string_wrapper +template <typename T> struct string_wrapper { std::string str; @@ -25,17 +24,42 @@ struct string_wrapper string_wrapper& operator=(string_wrapper&&) = default; ~string_wrapper() = default; - string_wrapper(const std::string& str) : str(str) {} - string_wrapper(std::string&& str) : str(std::move(str)) {} + string_wrapper(const std::string& str) : str(str) + { + } + string_wrapper(std::string&& str) : str(std::move(str)) + { + } - operator std::string() const { return str; } - operator const std::string&() const { return str; } - operator std::string&&() { return std::move(str); } + operator std::string() const + { + return str; + } + operator const std::string&() const + { + return str; + } + operator std::string &&() + { + return std::move(str); + } - bool operator==(const string_wrapper<T>& r) const { return str == r.str; } - bool operator<(const string_wrapper<T>& r) const { return str < r.str; } - bool operator==(const std::string& r) const { return str == r; } - bool operator<(const std::string& r) const { return str < r; } + bool operator==(const string_wrapper<T>& r) const + { + return str == r.str; + } + bool operator<(const string_wrapper<T>& r) const + { + return str < r.str; + } + bool operator==(const std::string& r) const + { + return str == r; + } + bool operator<(const std::string& r) const + { + return str < r; + } friend bool operator==(const std::string& l, const string_wrapper& r) { @@ -48,9 +72,13 @@ struct string_wrapper }; /** Typename for sdbus OBJECT_PATH types. */ -struct object_path_type {}; +struct object_path_type +{ +}; /** Typename for sdbus SIGNATURE types. */ -struct signature_type {}; +struct signature_type +{ +}; } // namespace details diff --git a/sdbusplus/message/read.hpp b/sdbusplus/message/read.hpp index f7ab4d3..31fd594 100644 --- a/sdbusplus/message/read.hpp +++ b/sdbusplus/message/read.hpp @@ -17,7 +17,7 @@ namespace message * (This is an empty no-op function that is useful in some cases for * variadic template reasons.) */ -inline void read(sd_bus_message* m) {}; +inline void read(sd_bus_message* m){}; /** @brief Read data from an sdbus message. * * @param[in] msg - The message to read from. @@ -29,7 +29,7 @@ inline void read(sd_bus_message* m) {}; * appropriate type parameters. It may also do conversions, where needed, * to convert C++ types into C representations (eg. string, vector). */ -template <typename ...Args> void read(sd_bus_message* m, Args&&... args); +template <typename... Args> void read(sd_bus_message* m, Args&&... args); namespace details { @@ -44,30 +44,49 @@ namespace details * User-defined types are expected to inherit from std::false_type. * */ -template<typename T> struct can_read_multiple : std::true_type {}; - // std::string needs a char* conversion. -template<> struct can_read_multiple<std::string> : std::false_type {}; - // object_path needs a char* conversion. -template<> struct can_read_multiple<object_path> : std::false_type {}; - // signature needs a char* conversion. -template<> struct can_read_multiple<signature> : 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 {}; - // std::pair needs to be broken down into components. -template<typename T1, typename T2> -struct can_read_multiple<std::pair<T1,T2>> : std::false_type {}; - // std::map needs a loop. -template<typename T1, typename T2> -struct can_read_multiple<std::map<T1,T2>> : std::false_type {}; - // std::tuple needs to be broken down into components. -template<typename ...Args> -struct can_read_multiple<std::tuple<Args...>> : std::false_type {}; - // variant needs to be broken down into components. -template<typename ...Args> -struct can_read_multiple<variant<Args...>> : std::false_type {}; +template <typename T> struct can_read_multiple : std::true_type +{ +}; +// std::string needs a char* conversion. +template <> struct can_read_multiple<std::string> : std::false_type +{ +}; +// object_path needs a char* conversion. +template <> struct can_read_multiple<object_path> : std::false_type +{ +}; +// signature needs a char* conversion. +template <> struct can_read_multiple<signature> : 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 +{ +}; +// std::pair needs to be broken down into components. +template <typename T1, typename T2> +struct can_read_multiple<std::pair<T1, T2>> : std::false_type +{ +}; +// std::map needs a loop. +template <typename T1, typename T2> +struct can_read_multiple<std::map<T1, T2>> : std::false_type +{ +}; +// std::tuple needs to be broken down into components. +template <typename... Args> +struct can_read_multiple<std::tuple<Args...>> : std::false_type +{ +}; +// variant needs to be broken down into components. +template <typename... Args> +struct can_read_multiple<variant<Args...>> : std::false_type +{ +}; /** @struct read_single * @brief Utility to read a single C++ element from a sd_bus_message. @@ -77,11 +96,10 @@ struct can_read_multiple<variant<Args...>> : std::false_type {}; * * @tparam S - Type of element to read. */ -template<typename S> struct read_single +template <typename S> struct read_single { // Downcast - template<typename T> - using Td = types::details::type_id_downcast_t<T>; + template <typename T> using Td = types::details::type_id_downcast_t<T>; /** @brief Do the operation to read element. * @@ -96,14 +114,14 @@ template<typename S> struct read_single * @param[in] m - sd_bus_message to read from. * @param[out] t - The reference to read item into. */ - template<typename T, - typename = std::enable_if_t<std::is_same<S, Td<T>>::value>> + template <typename T, + typename = std::enable_if_t<std::is_same<S, Td<T>>::value>> static void op(sd_bus_message* m, T&& t) { // For this default implementation, we need to ensure that only // basic types are used. static_assert(std::is_fundamental<Td<T>>::value || - std::is_convertible<Td<T>, const char*>::value, + std::is_convertible<Td<T>, const char*>::value, "Non-basic types are not allowed."); constexpr auto dbusType = std::get<0>(types::type_id<T>()); @@ -111,14 +129,13 @@ template<typename S> struct read_single } }; -template<typename T> using read_single_t = - read_single<types::details::type_id_downcast_t<T>>; +template <typename T> +using read_single_t = read_single<types::details::type_id_downcast_t<T>>; /** @brief Specialization of read_single for std::strings. */ template <> struct read_single<std::string> { - template<typename T> - static void op(sd_bus_message* m, T&& s) + template <typename T> static void op(sd_bus_message* m, T&& s) { constexpr auto dbusType = std::get<0>(types::type_id<T>()); const char* str = nullptr; @@ -130,8 +147,7 @@ template <> struct read_single<std::string> /** @brief Specialization of read_single for details::string_wrapper. */ template <typename T> struct read_single<details::string_wrapper<T>> { - template<typename S> - static void op(sd_bus_message* m, S&& s) + template <typename S> static void op(sd_bus_message* m, S&& s) { constexpr auto dbusType = std::get<0>(types::type_id<S>()); const char* str = nullptr; @@ -140,12 +156,10 @@ template <typename T> struct read_single<details::string_wrapper<T>> } }; - /** @brief Specialization of read_single for bools. */ template <> struct read_single<bool> { - template<typename T> - static void op(sd_bus_message* m, T&& b) + template <typename T> static void op(sd_bus_message* m, T&& b) { constexpr auto dbusType = std::get<0>(types::type_id<T>()); int i = 0; @@ -154,19 +168,17 @@ template <> struct read_single<bool> } }; - /** @brief Specialization of read_single for std::vectors. */ template <typename T> struct read_single<std::vector<T>> { - template<typename S> - static void op(sd_bus_message* m, S&& s) + template <typename S> static void op(sd_bus_message* m, S&& s) { s.clear(); constexpr auto dbusType = utility::tuple_to_array(types::type_id<T>()); sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, dbusType.data()); - while(!sd_bus_message_at_end(m, false)) + while (!sd_bus_message_at_end(m, false)) { std::remove_const_t<T> t{}; sdbusplus::message::read(m, t); @@ -180,15 +192,13 @@ template <typename T> struct read_single<std::vector<T>> /** @brief Specialization of read_single for std::pairs. */ template <typename T1, typename T2> struct read_single<std::pair<T1, T2>> { - template <typename S> - static void op(sd_bus_message* m, S&& s) + template <typename S> static void op(sd_bus_message* m, S&& s) { constexpr auto dbusType = utility::tuple_to_array( - std::tuple_cat(types::type_id_nonull<T1>(), - types::type_id<T2>())); + std::tuple_cat(types::type_id_nonull<T1>(), types::type_id<T2>())); - sd_bus_message_enter_container( - m, SD_BUS_TYPE_DICT_ENTRY, dbusType.data()); + sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, + dbusType.data()); sdbusplus::message::read(m, s.first, s.second); sd_bus_message_exit_container(m); } @@ -197,17 +207,16 @@ template <typename T1, typename T2> struct read_single<std::pair<T1, T2>> /** @brief Specialization of read_single for std::maps. */ template <typename T1, typename T2> struct read_single<std::map<T1, T2>> { - template<typename S> - static void op(sd_bus_message* m, S&& s) + template <typename S> static void op(sd_bus_message* m, S&& s) { s.clear(); constexpr auto dbusType = utility::tuple_to_array( - types::type_id<typename std::map<T1, T2>::value_type>()); + types::type_id<typename std::map<T1, T2>::value_type>()); sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, dbusType.data()); - while(!sd_bus_message_at_end(m, false)) + while (!sd_bus_message_at_end(m, false)) { std::pair<std::remove_const_t<T1>, std::remove_const_t<T2>> p{}; sdbusplus::message::read(m, p); @@ -219,42 +228,37 @@ template <typename T1, typename T2> struct read_single<std::map<T1, T2>> }; /** @brief Specialization of read_single for std::tuples. */ -template <typename ...Args> struct read_single<std::tuple<Args...>> +template <typename... Args> struct read_single<std::tuple<Args...>> { - template<typename S, std::size_t... I> + template <typename S, std::size_t... I> static void _op(sd_bus_message* m, S&& s, std::integer_sequence<std::size_t, I...>) { sdbusplus::message::read(m, std::get<I>(s)...); } - template<typename S> - static void op(sd_bus_message* m, S&& s) + template <typename S> static void op(sd_bus_message* m, S&& s) { constexpr auto dbusType = utility::tuple_to_array(std::tuple_cat( - types::type_id_nonull<Args...>(), - std::make_tuple('\0') /* null terminator for C-string */)); + types::type_id_nonull<Args...>(), + std::make_tuple('\0') /* null terminator for C-string */)); - sd_bus_message_enter_container( - m, SD_BUS_TYPE_STRUCT, dbusType.data()); - _op(m, std::forward<S>(s), - std::make_index_sequence<sizeof...(Args)>()); + sd_bus_message_enter_container(m, SD_BUS_TYPE_STRUCT, dbusType.data()); + _op(m, std::forward<S>(s), std::make_index_sequence<sizeof...(Args)>()); sd_bus_message_exit_container(m); - } }; /** @brief Specialization of read_single for std::variant. */ -template <typename ...Args> struct read_single<variant<Args...>> +template <typename... Args> struct read_single<variant<Args...>> { - template<typename S, typename S1, typename ...Args1> + template <typename S, typename S1, typename... Args1> static void read(sd_bus_message* m, S&& s) { constexpr auto dbusType = utility::tuple_to_array(types::type_id<S1>()); - auto rc = sd_bus_message_verify_type(m, - SD_BUS_TYPE_VARIANT, - dbusType.data()); + auto rc = + sd_bus_message_verify_type(m, SD_BUS_TYPE_VARIANT, dbusType.data()); if (0 >= rc) { read<S, Args1...>(m, s); @@ -270,15 +274,13 @@ template <typename ...Args> struct read_single<variant<Args...>> s = std::move(s1); } - template<typename S> - static void read(sd_bus_message* m, S&& s) + template <typename S> static void read(sd_bus_message* m, S&& s) { sd_bus_message_skip(m, "v"); s = std::remove_reference_t<S>{}; } - template<typename S, - typename = std::enable_if_t<0 < sizeof...(Args)>> + template <typename S, typename = std::enable_if_t<0 < sizeof...(Args)>> static void op(sd_bus_message* m, S&& s) { read<S, Args...>(m, s); @@ -295,8 +297,8 @@ template <typename ...Args> struct read_single<variant<Args...>> template <typename Tuple, size_t... I> void read_tuple(sd_bus_message* m, Tuple&& t, std::index_sequence<I...>) { - auto dbusTypes = utility::tuple_to_array( - types::type_id<decltype(std::get<I>(t))...>()); + auto dbusTypes = + utility::tuple_to_array(types::type_id<decltype(std::get<I>(t))...>()); sd_bus_message_read(m, dbusTypes.data(), &std::get<I>(t)...); } @@ -309,7 +311,8 @@ void read_tuple(sd_bus_message* m, Tuple&& t, std::index_sequence<I...>) * A tuple of 2 or more entries can be read as a set with * sd_bus_message_read. */ -template <typename Tuple> std::enable_if_t<2 <= std::tuple_size<Tuple>::value> +template <typename Tuple> +std::enable_if_t<2 <= std::tuple_size<Tuple>::value> read_tuple(sd_bus_message* m, Tuple&& t) { read_tuple(m, std::move(t), @@ -326,7 +329,8 @@ read_tuple(sd_bus_message* m, Tuple&& t) * Note: Some 1-entry tuples may need special handling due to * can_read_multiple::value == false. */ -template <typename Tuple> std::enable_if_t<1 == std::tuple_size<Tuple>::value> +template <typename Tuple> +std::enable_if_t<1 == std::tuple_size<Tuple>::value> read_tuple(sd_bus_message* m, Tuple&& t) { using itemType = decltype(std::get<0>(t)); @@ -337,8 +341,11 @@ read_tuple(sd_bus_message* m, Tuple&& t) * * This a no-op function that is useful due to variadic templates. */ -template <typename Tuple> std::enable_if_t<0 == std::tuple_size<Tuple>::value> -inline read_tuple(sd_bus_message* m, Tuple&& t) {} +template <typename Tuple> +std::enable_if_t<0 == std::tuple_size<Tuple>::value> inline read_tuple( + sd_bus_message* m, Tuple&& t) +{ +} /** @brief Group a sequence of C++ types for reading from an sd_bus_message. * @tparam Tuple - A tuple of previously analyzed types. @@ -346,8 +353,9 @@ inline read_tuple(sd_bus_message* m, Tuple&& t) {} * * Specialization for when can_read_multiple<Arg> is true. */ -template <typename Tuple, typename Arg> std::enable_if_t< - can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg> +std::enable_if_t< + can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg); /** @brief Group a sequence of C++ types for reading from an sd_bus_message. * @tparam Tuple - A tuple of previously analyzed types. @@ -355,8 +363,9 @@ read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg); * * Specialization for when can_read_multiple<Arg> is false. */ -template <typename Tuple, typename Arg> std::enable_if_t< - !can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg> +std::enable_if_t< + !can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg); /** @brief Group a sequence of C++ types for reading from an sd_bus_message. * @tparam Tuple - A tuple of previously analyzed types. @@ -365,8 +374,9 @@ read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg); * * Specialization for when can_read_multiple<Arg> is true. */ -template <typename Tuple, typename Arg, typename ...Rest> std::enable_if_t< - can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg, typename... Rest> +std::enable_if_t< + can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest); /** @brief Group a sequence of C++ types for reading from an sd_bus_message. * @tparam Tuple - A tuple of previously analyzed types. @@ -375,24 +385,27 @@ read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest); * * Specialization for when can_read_multiple<Arg> is false. */ -template <typename Tuple, typename Arg, typename ...Rest> std::enable_if_t< - !can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg, typename... Rest> +std::enable_if_t< + !can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest); -template <typename Tuple, typename Arg> std::enable_if_t< - can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg> +std::enable_if_t< + can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg) { // Last element of a sequence and can_read_multiple, so add it to // the tuple and call read_tuple. - read_tuple(m, std::tuple_cat(std::forward<Tuple>(t), - std::forward_as_tuple( - std::forward<Arg>(arg)))); + read_tuple(m, + std::tuple_cat(std::forward<Tuple>(t), + std::forward_as_tuple(std::forward<Arg>(arg)))); } -template <typename Tuple, typename Arg> std::enable_if_t< - !can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg> +std::enable_if_t< + !can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg) { // Last element of a sequence but !can_read_multiple, so call @@ -403,21 +416,23 @@ read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg) read_tuple(m, std::forward_as_tuple(std::forward<Arg>(arg))); } -template <typename Tuple, typename Arg, typename ...Rest> std::enable_if_t< - can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg, typename... Rest> +std::enable_if_t< + can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest) { // Not the last element of a sequence and can_read_multiple, so add it // to the tuple and keep grouping. - read_grouping(m, std::tuple_cat(std::forward<Tuple>(t), - std::forward_as_tuple( - std::forward<Arg>(arg))), + read_grouping(m, + std::tuple_cat(std::forward<Tuple>(t), + std::forward_as_tuple(std::forward<Arg>(arg))), std::forward<Rest>(rest)...); } -template <typename Tuple, typename Arg, typename ...Rest> std::enable_if_t< - !can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> +template <typename Tuple, typename Arg, typename... Rest> +std::enable_if_t< + !can_read_multiple<types::details::type_id_downcast_t<Arg>>::value> read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest) { // Not the last element of a sequence but !can_read_multiple, so call @@ -431,7 +446,7 @@ read_grouping(sd_bus_message* m, Tuple&& t, Arg&& arg, Rest&&... rest) } // namespace details -template <typename ...Args> void read(sd_bus_message* m, Args&&... args) +template <typename... Args> void read(sd_bus_message* m, Args&&... args) { details::read_grouping(m, std::make_tuple(), std::forward<Args>(args)...); } diff --git a/sdbusplus/message/types.hpp b/sdbusplus/message/types.hpp index a65bc31..8dccbef 100644 --- a/sdbusplus/message/types.hpp +++ b/sdbusplus/message/types.hpp @@ -18,9 +18,7 @@ namespace message namespace variant_ns = mapbox::util; -template <typename ...Args> -using variant = variant_ns::variant<Args...>; - +template <typename... Args> using variant = variant_ns::variant<Args...>; namespace types { @@ -39,13 +37,13 @@ namespace types * options at compile-time the use of type-deduced dbus strings is equal to * the cost of hard-coded type string constants. */ -template <typename ...Args> constexpr auto type_id(); +template <typename... Args> constexpr auto type_id(); /** @fn type_id_nonull() * @brief A non-null-terminated version of type_id. * * This is useful when type-ids may need to be concatenated. */ -template <typename ...Args> constexpr auto type_id_nonull(); +template <typename... Args> constexpr auto type_id_nonull(); namespace details { @@ -62,11 +60,11 @@ namespace details template <typename T> struct type_id_downcast { using type = typename utility::array_to_ptr_t< - char, std::remove_cv_t<std::remove_reference_t<T>>>; + char, std::remove_cv_t<std::remove_reference_t<T>>>; }; -template <typename T> using type_id_downcast_t = - typename type_id_downcast<T>::type; +template <typename T> +using type_id_downcast_t = typename type_id_downcast<T>::type; /** @struct undefined_type_id * @brief Special type indicating no dbus-type_id is defined for a C++ type. @@ -93,10 +91,10 @@ struct undefined_type_id template <char C1, char... C> struct tuple_type_id { - /* This version check is required because a fix for auto is in 5.2+. - * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66421 - */ - /** A tuple containing the type-characters. */ +/* This version check is required because a fix for auto is in 5.2+. + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66421 + */ +/** A tuple containing the type-characters. */ #if (__GNUC__ > 5) || (__GNUC__ == 5 && (__GNUC_MINOR__ >= 2)) static constexpr auto value = std::make_tuple(C1, C...); #else @@ -119,7 +117,7 @@ template <typename T> constexpr auto& type_id_single(); * @tparam T - The first type to get the dbus type character(s) for. * @tparam ...Args - The remaining types. */ -template <typename T, typename ...Args> constexpr auto type_id_multiple(); +template <typename T, typename... Args> constexpr auto type_id_multiple(); /** @struct type_id * @brief Defined dbus type tuple for a C++ type. @@ -129,84 +127,113 @@ template <typename T, typename ...Args> constexpr auto type_id_multiple(); * Struct must have a 'value' tuple containing the dbus type. The default * value is an empty tuple, which is used to indicate an unsupported type. */ -template <typename T> struct type_id : public undefined_type_id {}; - // Specializations for built-in types. -template <> struct type_id<bool> : tuple_type_id<SD_BUS_TYPE_BOOLEAN> {}; -template <> struct type_id<uint8_t> : tuple_type_id<SD_BUS_TYPE_BYTE> {}; +template <typename T> struct type_id : public undefined_type_id +{ +}; +// Specializations for built-in types. +template <> struct type_id<bool> : tuple_type_id<SD_BUS_TYPE_BOOLEAN> +{ +}; +template <> struct type_id<uint8_t> : tuple_type_id<SD_BUS_TYPE_BYTE> +{ +}; // int8_t isn't supported by dbus. -template <> struct type_id<uint16_t> : tuple_type_id<SD_BUS_TYPE_UINT16> {}; -template <> struct type_id<int16_t> : tuple_type_id<SD_BUS_TYPE_INT16> {}; -template <> struct type_id<uint32_t> : tuple_type_id<SD_BUS_TYPE_UINT32> {}; -template <> struct type_id<int32_t> : tuple_type_id<SD_BUS_TYPE_INT32> {}; -template <> struct type_id<uint64_t> : tuple_type_id<SD_BUS_TYPE_UINT64> {}; -template <> struct type_id<int64_t> : tuple_type_id<SD_BUS_TYPE_INT64> {}; +template <> struct type_id<uint16_t> : tuple_type_id<SD_BUS_TYPE_UINT16> +{ +}; +template <> struct type_id<int16_t> : tuple_type_id<SD_BUS_TYPE_INT16> +{ +}; +template <> struct type_id<uint32_t> : tuple_type_id<SD_BUS_TYPE_UINT32> +{ +}; +template <> struct type_id<int32_t> : tuple_type_id<SD_BUS_TYPE_INT32> +{ +}; +template <> struct type_id<uint64_t> : tuple_type_id<SD_BUS_TYPE_UINT64> +{ +}; +template <> struct type_id<int64_t> : tuple_type_id<SD_BUS_TYPE_INT64> +{ +}; // float isn't supported by dbus. -template <> struct type_id<double> : tuple_type_id<SD_BUS_TYPE_DOUBLE> {}; -template <> struct type_id<const char*> : tuple_type_id<SD_BUS_TYPE_STRING> {}; -template <> struct type_id<char*> : tuple_type_id<SD_BUS_TYPE_STRING> {}; -template <> struct type_id<std::string> : tuple_type_id<SD_BUS_TYPE_STRING> {}; -template <> struct type_id<object_path> : - tuple_type_id<SD_BUS_TYPE_OBJECT_PATH> {}; -template <> struct type_id<signature> : - tuple_type_id<SD_BUS_TYPE_SIGNATURE> {}; +template <> struct type_id<double> : tuple_type_id<SD_BUS_TYPE_DOUBLE> +{ +}; +template <> struct type_id<const char*> : tuple_type_id<SD_BUS_TYPE_STRING> +{ +}; +template <> struct type_id<char*> : tuple_type_id<SD_BUS_TYPE_STRING> +{ +}; +template <> struct type_id<std::string> : tuple_type_id<SD_BUS_TYPE_STRING> +{ +}; +template <> struct type_id<object_path> : tuple_type_id<SD_BUS_TYPE_OBJECT_PATH> +{ +}; +template <> struct type_id<signature> : tuple_type_id<SD_BUS_TYPE_SIGNATURE> +{ +}; template <typename T> struct type_id<std::vector<T>> { - static constexpr auto value = std::tuple_cat( - tuple_type_id<SD_BUS_TYPE_ARRAY>::value, - type_id<type_id_downcast_t<T>>::value); + static constexpr auto value = + std::tuple_cat(tuple_type_id<SD_BUS_TYPE_ARRAY>::value, + type_id<type_id_downcast_t<T>>::value); }; template <typename T1, typename T2> struct type_id<std::pair<T1, T2>> { - static constexpr auto value = std::tuple_cat( - tuple_type_id<SD_BUS_TYPE_DICT_ENTRY_BEGIN>::value, - type_id<type_id_downcast_t<T1>>::value, - type_id<type_id_downcast_t<T2>>::value, - tuple_type_id<SD_BUS_TYPE_DICT_ENTRY_END>::value); + static constexpr auto value = + std::tuple_cat(tuple_type_id<SD_BUS_TYPE_DICT_ENTRY_BEGIN>::value, + type_id<type_id_downcast_t<T1>>::value, + type_id<type_id_downcast_t<T2>>::value, + tuple_type_id<SD_BUS_TYPE_DICT_ENTRY_END>::value); }; template <typename T1, typename T2> struct type_id<std::map<T1, T2>> { - static constexpr auto value = std::tuple_cat( - tuple_type_id<SD_BUS_TYPE_ARRAY>::value, - type_id<typename std::map<T1,T2>::value_type>::value); + static constexpr auto value = + std::tuple_cat(tuple_type_id<SD_BUS_TYPE_ARRAY>::value, + type_id<typename std::map<T1, T2>::value_type>::value); }; -template <typename ...Args> struct type_id<std::tuple<Args...>> +template <typename... Args> struct type_id<std::tuple<Args...>> { - static constexpr auto value = std::tuple_cat( - tuple_type_id<SD_BUS_TYPE_STRUCT_BEGIN>::value, - type_id<type_id_downcast_t<Args>>::value..., - tuple_type_id<SD_BUS_TYPE_STRUCT_END>::value); + static constexpr auto value = + std::tuple_cat(tuple_type_id<SD_BUS_TYPE_STRUCT_BEGIN>::value, + type_id<type_id_downcast_t<Args>>::value..., + tuple_type_id<SD_BUS_TYPE_STRUCT_END>::value); }; -template <typename ...Args> -struct type_id<variant<Args...>> : tuple_type_id<SD_BUS_TYPE_VARIANT> {}; +template <typename... Args> +struct type_id<variant<Args...>> : tuple_type_id<SD_BUS_TYPE_VARIANT> +{ +}; template <typename T> constexpr auto& type_id_single() { static_assert(!std::is_base_of<undefined_type_id, type_id<T>>::value, - "No dbus type conversion provided for type."); + "No dbus type conversion provided for type."); return type_id<T>::value; } -template <typename T, typename ...Args> constexpr auto type_id_multiple() +template <typename T, typename... Args> constexpr auto type_id_multiple() { - return std::tuple_cat(type_id_single<T>(), - type_id_single<Args>()...); + return std::tuple_cat(type_id_single<T>(), type_id_single<Args>()...); } } // namespace details -template <typename ...Args> constexpr auto type_id() +template <typename... Args> constexpr auto type_id() { return std::tuple_cat( details::type_id_multiple<details::type_id_downcast_t<Args>...>(), - std::make_tuple('\0') /* null terminator for C-string */ ); + std::make_tuple('\0') /* null terminator for C-string */); } -template <typename ...Args> constexpr auto type_id_nonull() +template <typename... Args> constexpr auto type_id_nonull() { return details::type_id_multiple<details::type_id_downcast_t<Args>...>(); } diff --git a/sdbusplus/server/bindings.hpp b/sdbusplus/server/bindings.hpp index 88b0610..9d67ae3 100644 --- a/sdbusplus/server/bindings.hpp +++ b/sdbusplus/server/bindings.hpp @@ -17,12 +17,10 @@ namespace details * can be inserted into a message. This template provides a general no-op * implementation for all other types. */ -template <typename T> -T&& convertForMessage(T&& t) +template <typename T> T&& convertForMessage(T&& t) { return std::forward<T>(t); } - } } } diff --git a/sdbusplus/server/interface.hpp b/sdbusplus/server/interface.hpp index f3f6399..c09d301 100644 --- a/sdbusplus/server/interface.hpp +++ b/sdbusplus/server/interface.hpp @@ -31,14 +31,14 @@ namespace interface */ struct interface final { - /* Define all of the basic class operations: - * Not allowed: - * - Default constructor to avoid nullptrs. - * - Copy operations due to internal unique_ptr. - * Allowed: - * - Move operations. - * - Destructor. - */ + /* Define all of the basic class operations: + * Not allowed: + * - Default constructor to avoid nullptrs. + * - Copy operations due to internal unique_ptr. + * Allowed: + * - Move operations. + * - Destructor. + */ interface() = delete; interface(const interface&) = delete; interface& operator=(const interface&) = delete; @@ -55,20 +55,16 @@ struct interface final * @param[in] context - User-defined context, which is often 'this' from * the interface implementation class. */ - interface(sdbusplus::bus::bus& bus, - const char* path, - const char* interf, - const sdbusplus::vtable::vtable_t* vtable, - void* context) : - _bus(bus.get()), _path(path), _interf(interf), - _slot(nullptr) + interface(sdbusplus::bus::bus& bus, const char* path, const char* interf, + const sdbusplus::vtable::vtable_t* vtable, void* context) : + _bus(bus.get()), + _path(path), _interf(interf), _slot(nullptr) { sd_bus_slot* slot = nullptr; sd_bus_add_object_vtable(_bus.get(), &slot, _path.c_str(), _interf.c_str(), vtable, context); _slot = decltype(_slot){slot}; - } /** @brief Create a new signal message. @@ -90,14 +86,20 @@ struct interface final _interf.c_str(), property, nullptr); } - bus::bus& bus() { return _bus; } - const std::string& path() { return _path; } + bus::bus& bus() + { + return _bus; + } + const std::string& path() + { + return _path; + } - private: - bus::bus _bus; - std::string _path; - std::string _interf; - slot::slot _slot; + private: + bus::bus _bus; + std::string _path; + std::string _interf; + slot::slot _slot; }; } // namespace interface diff --git a/sdbusplus/server/manager.hpp b/sdbusplus/server/manager.hpp index 5228b5f..55c2011 100644 --- a/sdbusplus/server/manager.hpp +++ b/sdbusplus/server/manager.hpp @@ -20,14 +20,14 @@ namespace manager */ struct manager { - /* Define all of the basic class operations: - * Not allowed: - * - Default constructor to avoid nullptrs. - * - Copy operations due to internal unique_ptr. - * Allowed: - * - Move operations. - * - Destructor. - */ + /* Define all of the basic class operations: + * Not allowed: + * - Default constructor to avoid nullptrs. + * - Copy operations due to internal unique_ptr. + * Allowed: + * - Move operations. + * - Destructor. + */ manager() = delete; manager(const manager&) = delete; manager& operator=(const manager&) = delete; @@ -48,9 +48,8 @@ struct manager _slot = decltype(_slot){slot}; } - private: - slot::slot _slot; - + private: + slot::slot _slot; }; } // namespace manager diff --git a/sdbusplus/server/object.hpp b/sdbusplus/server/object.hpp index 6928164..802947b 100644 --- a/sdbusplus/server/object.hpp +++ b/sdbusplus/server/object.hpp @@ -18,31 +18,36 @@ namespace details * These allow an object to group multiple dbus interface bindings into a * single class. */ -template <class T, class... Rest> struct compose_impl : - T, compose_impl<Rest...> +template <class T, class... Rest> struct compose_impl : T, compose_impl<Rest...> { compose_impl(bus::bus& bus, const char* path) : - T(bus, path), compose_impl<Rest...>(bus, path) {} + T(bus, path), compose_impl<Rest...>(bus, path) + { + } }; /** Specialization for single element. */ template <class T> struct compose_impl<T> : T { - compose_impl(bus::bus& bus, const char* path) : - T(bus, path) {} + compose_impl(bus::bus& bus, const char* path) : T(bus, path) + { + } }; /** Default compose operation for variadic arguments. */ template <class... Args> struct compose : compose_impl<Args...> { - compose(bus::bus& bus, const char* path) : - compose_impl<Args...>(bus, path) {} + compose(bus::bus& bus, const char* path) : compose_impl<Args...>(bus, path) + { + } }; /** Specialization for zero variadic arguments. */ template <> struct compose<> { - compose(bus::bus& bus, const char* path) {} + compose(bus::bus& bus, const char* path) + { + } }; } // namespace details @@ -59,17 +64,16 @@ template <> struct compose<> * 'sd_bus_emit_object_removed' signals are emitted. * */ -template<class... Args> -struct object : details::compose<Args...> +template <class... Args> struct object : details::compose<Args...> { - /* Define all of the basic class operations: - * Not allowed: - * - Default constructor to avoid nullptrs. - * - Copy operations due to internal unique_ptr. - * Allowed: - * - Move operations. - * - Destructor. - */ + /* Define all of the basic class operations: + * Not allowed: + * - Default constructor to avoid nullptrs. + * - Copy operations due to internal unique_ptr. + * Allowed: + * - Move operations. + * - Destructor. + */ object() = delete; object(const object&) = delete; object& operator=(const object&) = delete; @@ -85,13 +89,11 @@ struct object : details::compose<Args...> * object needs custom property init before the * signal can be sent. */ - object(bus::bus& bus, - const char* path, - bool deferSignal = false) - : details::compose<Args...>(bus, path), - __sdbusplus_server_object_bus(bus.get()), - __sdbusplus_server_object_path(path), - __sdbusplus_server_object_emitremoved(false) + object(bus::bus& bus, const char* path, bool deferSignal = false) : + details::compose<Args...>(bus, path), + __sdbusplus_server_object_bus(bus.get()), + __sdbusplus_server_object_path(path), + __sdbusplus_server_object_emitremoved(false) { if (!deferSignal) { @@ -119,15 +121,14 @@ struct object : details::compose<Args...> } } - private: - // These member names are purposefully chosen as long and, hopefully, - // unique. Since an object is 'composed' via multiple-inheritence, - // all members need to have unique names to ensure there is no - // ambiguity. - bus::bus __sdbusplus_server_object_bus; - std::string __sdbusplus_server_object_path; - bool __sdbusplus_server_object_emitremoved; - + private: + // These member names are purposefully chosen as long and, hopefully, + // unique. Since an object is 'composed' via multiple-inheritence, + // all members need to have unique names to ensure there is no + // ambiguity. + bus::bus __sdbusplus_server_object_bus; + std::string __sdbusplus_server_object_path; + bool __sdbusplus_server_object_emitremoved; }; } // namespace object diff --git a/sdbusplus/server/transaction.hpp b/sdbusplus/server/transaction.hpp index 9e76a87..db07504 100644 --- a/sdbusplus/server/transaction.hpp +++ b/sdbusplus/server/transaction.hpp @@ -17,8 +17,9 @@ extern thread_local uint64_t id; struct Transaction { - Transaction(): time(std::time(nullptr)), thread(std::this_thread::get_id()) - {} + Transaction() : time(std::time(nullptr)), thread(std::this_thread::get_id()) + { + } int time; std::thread::id thread; @@ -28,8 +29,10 @@ struct Transaction struct Transaction { - Transaction(sdbusplus::bus::bus &bus, sdbusplus::message::message& msg): - bus(bus), msg(msg) {} + Transaction(sdbusplus::bus::bus& bus, sdbusplus::message::message& msg) : + bus(bus), msg(msg) + { + } sdbusplus::bus::bus& bus; sdbusplus::message::message& msg; @@ -43,11 +46,9 @@ namespace std { /** @ brief Overload of std::hash for sdbusplus::bus::bus */ -template <> -struct hash<sdbusplus::bus::bus> +template <> struct hash<sdbusplus::bus::bus> { - auto operator() - (sdbusplus::bus::bus& b) const + auto operator()(sdbusplus::bus::bus& b) const { auto name = b.get_unique_name(); return std::hash<std::string>{}(name); @@ -55,11 +56,9 @@ struct hash<sdbusplus::bus::bus> }; /** @ brief Overload of std::hash for sdbusplus::message::message */ -template <> -struct hash<sdbusplus::message::message> +template <> struct hash<sdbusplus::message::message> { - auto operator() - (sdbusplus::message::message& m) const + auto operator()(sdbusplus::message::message& m) const { auto cookie = m.get_cookie(); return std::hash<uint64_t>{}(cookie); @@ -67,34 +66,31 @@ struct hash<sdbusplus::message::message> }; /** @ brief Overload of std::hash for Transaction */ -template <> -struct hash<sdbusplus::server::transaction::Transaction> +template <> struct hash<sdbusplus::server::transaction::Transaction> { - auto operator() - (sdbusplus::server::transaction::Transaction const& t) const + auto operator()(sdbusplus::server::transaction::Transaction const& t) const { auto hash1 = std::hash<sdbusplus::bus::bus>{}(t.bus); auto hash2 = std::hash<sdbusplus::message::message>{}(t.msg); // boost::hash_combine() algorithm. - return static_cast<size_t>(hash1 ^ (hash2 + 0x9e3779b9 + (hash1 << 6) + - (hash1 >> 2))); + return static_cast<size_t>( + hash1 ^ (hash2 + 0x9e3779b9 + (hash1 << 6) + (hash1 >> 2))); } }; /** @ brief Overload of std::hash for details::Transaction */ -template <> -struct hash<sdbusplus::server::transaction::details::Transaction> +template <> struct hash<sdbusplus::server::transaction::details::Transaction> { - auto operator() - (sdbusplus::server::transaction::details::Transaction const& t) const + auto operator()( + sdbusplus::server::transaction::details::Transaction const& t) const { auto hash1 = std::hash<int>{}(t.time); auto hash2 = std::hash<std::thread::id>{}(t.thread); // boost::hash_combine() algorithm. - return static_cast<size_t>(hash1 ^ (hash2 + 0x9e3779b9 + (hash1 << 6) + - (hash1 >> 2))); + return static_cast<size_t>( + hash1 ^ (hash2 + 0x9e3779b9 + (hash1 << 6) + (hash1 >> 2))); } }; @@ -108,9 +104,9 @@ namespace transaction { /** @brief Get transaction id - * - * @return The value of the transaction id - */ + * + * @return The value of the transaction id + */ inline uint64_t get_id() { // If the transaction id has not been initialized, generate one. @@ -123,9 +119,9 @@ inline uint64_t get_id() } /** @brief Set transaction id - * - * @param[in] value - Desired value for the transaction id - */ + * + * @param[in] value - Desired value for the transaction id + */ inline void set_id(uint64_t value) { details::id = value; diff --git a/sdbusplus/slot.hpp b/sdbusplus/slot.hpp index 039f520..364d002 100644 --- a/sdbusplus/slot.hpp +++ b/sdbusplus/slot.hpp @@ -33,14 +33,14 @@ using slot = std::unique_ptr<sd_bus_slot, SlotDeleter>; */ struct slot { - /* Define all of the basic class operations: - * Not allowed: - * - Default constructor to avoid nullptrs. - * - Copy operations due to internal unique_ptr. - * Allowed: - * - Move operations. - * - Destructor. - */ + /* Define all of the basic class operations: + * Not allowed: + * - Default constructor to avoid nullptrs. + * - Copy operations due to internal unique_ptr. + * Allowed: + * - Move operations. + * - Destructor. + */ slot() = delete; slot(const slot&) = delete; slot& operator=(const slot&) = delete; @@ -52,17 +52,24 @@ struct slot * * Takes ownership of the slot-pointer and releases it when done. */ - explicit slot(slotp_t s) : _slot(s) {} + explicit slot(slotp_t s) : _slot(s) + { + } /** @brief Release ownership of the stored slot-pointer. */ - slotp_t release() { return _slot.release(); } + slotp_t release() + { + return _slot.release(); + } /** @brief Check if slot contains a real pointer. (non-nullptr). */ - explicit operator bool() const { return bool(_slot); } - - private: - details::slot _slot; + explicit operator bool() const + { + return bool(_slot); + } + private: + details::slot _slot; }; } // namespace slot diff --git a/sdbusplus/utility/tuple_to_array.hpp b/sdbusplus/utility/tuple_to_array.hpp index b5ab2a5..fd57d1d 100644 --- a/sdbusplus/utility/tuple_to_array.hpp +++ b/sdbusplus/utility/tuple_to_array.hpp @@ -26,11 +26,12 @@ namespace details * @return A std::array where each I-th element is tuple's I-th element. */ template <typename V, typename... Types, std::size_t... I> -constexpr auto tuple_to_array( - std::tuple<V, Types...>&& tuple, - std::integer_sequence<std::size_t, I...>) +constexpr auto tuple_to_array(std::tuple<V, Types...>&& tuple, + std::integer_sequence<std::size_t, I...>) { - return std::array<V, sizeof...(I) >({ std::get<I>(tuple)..., }); + return std::array<V, sizeof...(I)>({ + std::get<I>(tuple)..., + }); } } // namespace details diff --git a/sdbusplus/utility/type_traits.hpp b/sdbusplus/utility/type_traits.hpp index c5bf965..cad5168 100644 --- a/sdbusplus/utility/type_traits.hpp +++ b/sdbusplus/utility/type_traits.hpp @@ -15,12 +15,10 @@ namespace utility */ template <typename Tbase, typename T> using array_to_ptr_t = typename std::conditional_t< - std::is_array<T>::value, - std::conditional_t<std::is_same<Tbase, - std::remove_extent_t<T>>::value, - std::add_pointer_t<std::remove_extent_t<T>>, - T>, - T>; + std::is_array<T>::value, + std::conditional_t<std::is_same<Tbase, std::remove_extent_t<T>>::value, + std::add_pointer_t<std::remove_extent_t<T>>, T>, + T>; } // namespace utility diff --git a/sdbusplus/vtable.hpp b/sdbusplus/vtable.hpp index 7d9dfe8..939346e 100644 --- a/sdbusplus/vtable.hpp +++ b/sdbusplus/vtable.hpp @@ -7,13 +7,13 @@ namespace sdbusplus namespace vtable { - /** Alias typedef for sd_bus_vtable */ +/** Alias typedef for sd_bus_vtable */ using vtable_t = sd_bus_vtable; - /** Create a SD_BUS_VTABLE_START entry. */ +/** Create a SD_BUS_VTABLE_START entry. */ constexpr vtable_t start(decltype(vtable_t::flags) flags = 0); - /** Create a SD_BUS_VTABLE_END entry. */ +/** Create a SD_BUS_VTABLE_END entry. */ constexpr vtable_t end(); /** Create a SD_BUS_VTABLE_METHOD entry. @@ -39,8 +39,8 @@ constexpr vtable_t method(const char* member, const char* signature, */ constexpr vtable_t method_o(const char* member, const char* signature, const char* result, - sd_bus_message_handler_t handler, - size_t offset, decltype(vtable_t::flags) flags = 0); + sd_bus_message_handler_t handler, size_t offset, + decltype(vtable_t::flags) flags = 0); /** Create a SD_BUS_SIGNAL entry. * @@ -100,16 +100,15 @@ constexpr vtable_t property_o(const char* member, const char* signature, namespace method_ { - constexpr auto no_reply = SD_BUS_VTABLE_METHOD_NO_REPLY; +constexpr auto no_reply = SD_BUS_VTABLE_METHOD_NO_REPLY; } // namespace method_ namespace property_ { - constexpr auto const_ = SD_BUS_VTABLE_PROPERTY_CONST; - constexpr auto emits_change = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE; - constexpr auto emits_invalidation = - SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION; - constexpr auto explicit_ = SD_BUS_VTABLE_PROPERTY_EXPLICIT; +constexpr auto const_ = SD_BUS_VTABLE_PROPERTY_CONST; +constexpr auto emits_change = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE; +constexpr auto emits_invalidation = SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION; +constexpr auto explicit_ = SD_BUS_VTABLE_PROPERTY_EXPLICIT; } // namespace property_ constexpr vtable_t start(decltype(vtable_t::flags) flags) @@ -117,7 +116,7 @@ constexpr vtable_t start(decltype(vtable_t::flags) flags) vtable_t v{}; v.type = _SD_BUS_VTABLE_START; v.flags = flags; - v.x.start = decltype(v.x.start){ sizeof(vtable_t) }; + v.x.start = decltype(v.x.start){sizeof(vtable_t)}; return v; } @@ -139,14 +138,14 @@ constexpr vtable_t method(const char* member, const char* signature, constexpr vtable_t method_o(const char* member, const char* signature, const char* result, - sd_bus_message_handler_t handler, - size_t offset, decltype(vtable_t::flags) flags) + sd_bus_message_handler_t handler, size_t offset, + decltype(vtable_t::flags) flags) { vtable_t v{}; v.type = _SD_BUS_VTABLE_METHOD; v.flags = flags; v.x.method = - decltype(v.x.method){ member, signature, result, handler, offset }; + decltype(v.x.method){member, signature, result, handler, offset}; return v; } @@ -157,7 +156,7 @@ constexpr vtable_t signal(const char* member, const char* signature, vtable_t v{}; v.type = _SD_BUS_VTABLE_SIGNAL; v.flags = flags; - v.x.signal = decltype(v.x.signal){ member, signature }; + v.x.signal = decltype(v.x.signal){member, signature}; return v; } @@ -169,7 +168,7 @@ constexpr vtable_t property(const char* member, const char* signature, vtable_t v{}; v.type = _SD_BUS_VTABLE_PROPERTY; v.flags = flags; - v.x.property = decltype(v.x.property){ member, signature, get, nullptr, 0 }; + v.x.property = decltype(v.x.property){member, signature, get, nullptr, 0}; return v; } @@ -182,20 +181,19 @@ constexpr vtable_t property(const char* member, const char* signature, vtable_t v{}; v.type = _SD_BUS_VTABLE_WRITABLE_PROPERTY; v.flags = flags; - v.x.property = decltype(v.x.property){ member, signature, get, set, 0 }; + v.x.property = decltype(v.x.property){member, signature, get, set, 0}; return v; } constexpr vtable_t property_o(const char* member, const char* signature, - size_t offset, - decltype(vtable_t::flags) flags) + size_t offset, decltype(vtable_t::flags) flags) { vtable_t v{}; v.type = _SD_BUS_VTABLE_PROPERTY; v.flags = flags; - v.x.property = decltype(v.x.property) - { member, signature, nullptr, nullptr, offset }; + v.x.property = + decltype(v.x.property){member, signature, nullptr, nullptr, offset}; return v; } @@ -207,11 +205,10 @@ constexpr vtable_t property_o(const char* member, const char* signature, vtable_t v{}; v.type = _SD_BUS_VTABLE_WRITABLE_PROPERTY; v.flags = flags; - v.x.property = decltype(v.x.property) - { member, signature, nullptr, set, offset }; + v.x.property = + decltype(v.x.property){member, signature, nullptr, set, offset}; return v; - } } // namespace vtable diff --git a/test/bus/list_names.cpp b/test/bus/list_names.cpp index 65333b7..a1967d9 100644 --- a/test/bus/list_names.cpp +++ b/test/bus/list_names.cpp @@ -5,17 +5,15 @@ constexpr auto this_name = "xyz.openbmc_project.sdbusplus.test.ListNames"; class ListNames : public ::testing::Test { - protected: - decltype(sdbusplus::bus::new_default()) bus = - sdbusplus::bus::new_default(); + protected: + decltype(sdbusplus::bus::new_default()) bus = sdbusplus::bus::new_default(); }; TEST_F(ListNames, NoServiceNameWithoutRequestName) { auto names = bus.list_names_acquired(); - EXPECT_EQ(names.cend(), - std::find(names.cbegin(), names.cend(), this_name)); + EXPECT_EQ(names.cend(), std::find(names.cbegin(), names.cend(), this_name)); } TEST_F(ListNames, HasServiceNameAfterRequestName) @@ -38,7 +36,6 @@ TEST_F(ListNames, HasUniqueName) std::find(names.cbegin(), names.cend(), bus.get_unique_name())); } - TEST_F(ListNames, HasDbusServer) { auto names = bus.list_names_acquired(); diff --git a/test/bus/match.cpp b/test/bus/match.cpp index c69c76b..80bc259 100644 --- a/test/bus/match.cpp +++ b/test/bus/match.cpp @@ -4,41 +4,37 @@ class Match : public ::testing::Test { - protected: - decltype(sdbusplus::bus::new_default()) bus = - sdbusplus::bus::new_default(); + protected: + decltype(sdbusplus::bus::new_default()) bus = sdbusplus::bus::new_default(); - static constexpr auto busName = - "xyz.openbmc_project.sdbusplus.test.Match"; + static constexpr auto busName = "xyz.openbmc_project.sdbusplus.test.Match"; + static auto matchRule() + { + using namespace sdbusplus::bus::match::rules; + return nameOwnerChanged() + argN(0, busName); + } - static auto matchRule() - { - using namespace sdbusplus::bus::match::rules; - return nameOwnerChanged() + argN(0, busName); - } - - void waitForIt(bool& triggered) + void waitForIt(bool& triggered) + { + for (size_t i = 0; (i < 16) && !triggered; ++i) { - for (size_t i = 0; (i < 16) && !triggered; ++i) - { - bus.wait(0); - bus.process_discard(); - } + bus.wait(0); + bus.process_discard(); } + } }; TEST_F(Match, FunctorIs_sd_bus_message_handler_t) { bool triggered = false; - auto trigger = [](sd_bus_message *m, void* context, sd_bus_error* e) - { - *static_cast<bool*>(context) = true; - return 0; - }; + auto trigger = [](sd_bus_message* m, void* context, sd_bus_error* e) { + *static_cast<bool*>(context) = true; + return 0; + }; sdbusplus::bus::match_t m{bus, matchRule(), trigger, &triggered}; - auto m2 = std::move(m); // ensure match is move-safe. + auto m2 = std::move(m); // ensure match is move-safe. waitForIt(triggered); ASSERT_FALSE(triggered); @@ -52,13 +48,12 @@ TEST_F(Match, FunctorIs_sd_bus_message_handler_t) TEST_F(Match, FunctorIs_LambdaTakingMessage) { bool triggered = false; - auto trigger = [&triggered](sdbusplus::message::message& m) - { - triggered = true; - }; + auto trigger = [&triggered](sdbusplus::message::message& m) { + triggered = true; + }; sdbusplus::bus::match_t m{bus, matchRule(), trigger}; - auto m2 = std::move(m); // ensure match is move-safe. + auto m2 = std::move(m); // ensure match is move-safe. waitForIt(triggered); ASSERT_FALSE(triggered); @@ -74,20 +69,20 @@ TEST_F(Match, FunctorIs_MemberFunctionTakingMessage) class BoolHolder { - public: - bool triggered = false; + public: + bool triggered = false; - void callback(sdbusplus::message::message& m) - { - triggered = true; - } + void callback(sdbusplus::message::message& m) + { + triggered = true; + } }; BoolHolder b; sdbusplus::bus::match_t m{bus, matchRule(), - std::bind(std::mem_fn(&BoolHolder::callback), - &b, std::placeholders::_1)}; - auto m2 = std::move(m); // ensure match is move-safe. + std::bind(std::mem_fn(&BoolHolder::callback), &b, + std::placeholders::_1)}; + auto m2 = std::move(m); // ensure match is move-safe. waitForIt(b.triggered); ASSERT_FALSE(b.triggered); diff --git a/test/message/append.cpp b/test/message/append.cpp index c3a06db..7782f02 100644 --- a/test/message/append.cpp +++ b/test/message/append.cpp @@ -6,7 +6,7 @@ // Global to share the dbus type string between client and server. static std::string verifyTypeString; -using verifyCallback_t = void(*)(sd_bus_message*); +using verifyCallback_t = void (*)(sd_bus_message*); verifyCallback_t verifyCallback = nullptr; static constexpr auto SERVICE = "sdbusplus.test.message.append"; @@ -28,12 +28,12 @@ void* server(void* b) { auto bus = sdbusplus::bus::bus(reinterpret_cast<sdbusplus::bus::busp_t>(b)); - while(1) + while (1) { // Wait for messages. auto m = bus.process().release(); - if(m == nullptr) + if (m == nullptr) { bus.wait(); continue; @@ -50,8 +50,8 @@ void* server(void* b) } else { - std::cout << "Warning: No verification for " - << verifyTypeString << std::endl; + std::cout << "Warning: No verification for " << verifyTypeString + << std::endl; } // Reply to client. sd_bus_reply_method_return(m, nullptr); @@ -233,8 +233,7 @@ void runTests() const char* str3 = "1234"; const char* const str4 = "5678"; const auto str5 = "!@#$"; - m.append(1, "asdf", "ASDF"s, str, - std::move(str2), str3, str4, str5, 5); + m.append(1, "asdf", "ASDF"s, str, std::move(str2), str3, str4, str5, 5); verifyTypeString = "isssssssi"; struct verify @@ -245,8 +244,8 @@ void runTests() const char *s0 = nullptr, *s1 = nullptr, *s2 = nullptr, *s3 = nullptr, *s4 = nullptr, *s5 = nullptr, *s6 = nullptr; - sd_bus_message_read(m, "isssssssi", &a, &s0, &s1, &s2, &s3, - &s4, &s5, &s6, &b); + sd_bus_message_read(m, "isssssssi", &a, &s0, &s1, &s2, &s3, &s4, + &s5, &s6, &b); assert(a == 1); assert(b == 5); assert(0 == strcmp("asdf", s0)); @@ -283,7 +282,6 @@ void runTests() assert(b == 4); assert(0 == strcmp("/asdf", s0)); assert(0 == strcmp("iii", s1)); - } }; verifyCallback = &verify::op; @@ -294,7 +292,7 @@ void runTests() // Test vector. { auto m = newMethodCall__test(b); - std::vector<std::string> s{ "1", "2", "3"}; + std::vector<std::string> s{"1", "2", "3"}; m.append(1, s, 2); verifyTypeString = "iasi"; @@ -306,9 +304,8 @@ void runTests() sd_bus_message_read(m, "i", &a); assert(a == 1); - auto rc = sd_bus_message_enter_container(m, - SD_BUS_TYPE_ARRAY, - "s"); + auto rc = + sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "s"); assert(0 <= rc); const char* s = nullptr; @@ -324,19 +321,17 @@ void runTests() sd_bus_message_read(m, "i", &a); assert(a == 2); - } }; verifyCallback = &verify::op; - b.call_noreply(m); } // Test map. { auto m = newMethodCall__test(b); - std::map<std::string, int> s = { { "asdf", 3 }, { "jkl;", 4 } }; + std::map<std::string, int> s = {{"asdf", 3}, {"jkl;", 4}}; m.append(1, s, 2); verifyTypeString = "ia{si}i"; @@ -348,13 +343,11 @@ void runTests() sd_bus_message_read(m, "i", &a); assert(a == 1); - auto rc = sd_bus_message_enter_container(m, - SD_BUS_TYPE_ARRAY, + auto rc = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{si}"); assert(0 <= rc); - rc = sd_bus_message_enter_container(m, - SD_BUS_TYPE_DICT_ENTRY, + rc = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "si"); assert(0 <= rc); @@ -367,8 +360,7 @@ void runTests() assert(1 == sd_bus_message_at_end(m, false)); sd_bus_message_exit_container(m); - rc = sd_bus_message_enter_container(m, - SD_BUS_TYPE_DICT_ENTRY, + rc = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "si"); assert(0 <= rc); @@ -395,7 +387,7 @@ void runTests() // Test tuple. { auto m = newMethodCall__test(b); - std::tuple<int, double, std::string> a{ 3, 4.1, "asdf" }; + std::tuple<int, double, std::string> a{3, 4.1, "asdf"}; m.append(1, a, 2); verifyTypeString = "i(ids)i"; @@ -410,8 +402,7 @@ void runTests() sd_bus_message_read(m, "i", &a); assert(a == 1); - auto rc = sd_bus_message_enter_container(m, - SD_BUS_TYPE_STRUCT, + auto rc = sd_bus_message_enter_container(m, SD_BUS_TYPE_STRUCT, "ids"); assert(0 <= rc); @@ -470,8 +461,8 @@ void runTests() // Test map-variant. { auto m = newMethodCall__test(b); - std::map<std::string, sdbusplus::message::variant<int, double>> a1 = - { { "asdf", 3 }, { "jkl;", 4.1 } }; + std::map<std::string, sdbusplus::message::variant<int, double>> a1 = { + {"asdf", 3}, {"jkl;", 4.1}}; m.append(1, a1, 2); verifyTypeString = "ia{sv}i"; diff --git a/test/message/native_types.cpp b/test/message/native_types.cpp index 3b46457..eed7669 100644 --- a/test/message/native_types.cpp +++ b/test/message/native_types.cpp @@ -28,24 +28,24 @@ TEST(MessageNativeTypeConversions, Signature) TEST(MessageNativeTypeConversions, SignatureInVector) { - std::vector<sdbusplus::message::signature> v = - { sdbusplus::message::signature("iii") }; + std::vector<sdbusplus::message::signature> v = { + sdbusplus::message::signature("iii")}; ASSERT_EQ(v.front(), "iii"); } TEST(MessageNativeTypeConversions, SignatureInMap) { - std::map<sdbusplus::message::signature, int> m = - { { sdbusplus::message::signature("iii"), 1 } }; + std::map<sdbusplus::message::signature, int> m = { + {sdbusplus::message::signature("iii"), 1}}; ASSERT_EQ(m[sdbusplus::message::signature("iii")], 1); } TEST(MessageNativeTypeConversions, SignatureInUnorderedMap) { - std::unordered_map<sdbusplus::message::signature, int> u = - { { sdbusplus::message::signature("iii"), 2 } }; + std::unordered_map<sdbusplus::message::signature, int> u = { + {sdbusplus::message::signature("iii"), 2}}; ASSERT_EQ(u[sdbusplus::message::signature("iii")], 2); } diff --git a/test/message/read.cpp b/test/message/read.cpp index 2b137d7..8c2c4ea 100644 --- a/test/message/read.cpp +++ b/test/message/read.cpp @@ -6,7 +6,7 @@ // Global to share the dbus type string between client and server. static std::string verifyTypeString; -using verifyCallback_t = void(*)(sdbusplus::message::message&); +using verifyCallback_t = void (*)(sdbusplus::message::message&); verifyCallback_t verifyCallback = nullptr; static constexpr auto SERVICE = "sdbusplus.test.message.read"; @@ -28,12 +28,12 @@ void* server(void* b) { auto bus = sdbusplus::bus::bus(reinterpret_cast<sdbusplus::bus::busp_t>(b)); - while(1) + while (1) { // Wait for messages. auto m = bus.process(); - if(!m) + if (!m) { bus.wait(); continue; @@ -52,8 +52,8 @@ void* server(void* b) } else { - std::cout << "Warning: No verification for " - << verifyTypeString << std::endl; + std::cout << "Warning: No verification for " << verifyTypeString + << std::endl; } // Reply to client. sd_bus_reply_method_return(m.release(), nullptr); @@ -133,7 +133,7 @@ void runTests() static void op(sdbusplus::message::message& m) { int32_t a = 0, b = 0, c = 0, d = 0, e = 0; - m.read(a,b,c,d,e); + m.read(a, b, c, d, e); assert(a == 1); assert(b == 2); assert(c == 3); @@ -200,8 +200,7 @@ void runTests() auto m = newMethodCall__test(b); auto str = "jkl;"s; auto str2 = "JKL:"s; - m.append(1, "asdf", "ASDF"s, str, - std::move(str2), 5); + m.append(1, "asdf", "ASDF"s, str, std::move(str2), 5); verifyTypeString = "issssi"; struct verify @@ -251,11 +250,10 @@ void runTests() b.call_noreply(m); } - // Test vector. { auto m = newMethodCall__test(b); - std::vector<std::string> s{ "1", "2", "3"}; + std::vector<std::string> s{"1", "2", "3"}; m.append(1, s, 2); verifyTypeString = "iasi"; @@ -270,7 +268,7 @@ void runTests() assert(s[0] == "1"); assert(s[1] == "2"); assert(s[2] == "3"); - decltype(s) s2 = { "1" , "2" , "3" }; + decltype(s) s2 = {"1", "2", "3"}; assert(s == s2); } }; @@ -282,7 +280,7 @@ void runTests() // Test map. { auto m = newMethodCall__test(b); - std::map<std::string, int> s = { { "asdf", 3 }, { "jkl;", 4 } }; + std::map<std::string, int> s = {{"asdf", 3}, {"jkl;", 4}}; m.append(1, s, 2); verifyTypeString = "ia{si}i"; @@ -309,7 +307,7 @@ void runTests() // Test tuple. { auto m = newMethodCall__test(b); - std::tuple<int, double, std::string> a{ 3, 4.1, "asdf" }; + std::tuple<int, double, std::string> a{3, 4.1, "asdf"}; m.append(1, a, 2); verifyTypeString = "i(ids)i"; @@ -386,8 +384,8 @@ void runTests() // Test map-variant. { auto m = newMethodCall__test(b); - std::map<std::string, sdbusplus::message::variant<int, double>> a1 = - { { "asdf", 3 }, { "jkl;", 4.1 } }; + std::map<std::string, sdbusplus::message::variant<int, double>> a1 = { + {"asdf", 3}, {"jkl;", 4.1}}; m.append(1, a1, 2); verifyTypeString = "ia{sv}i"; @@ -396,8 +394,8 @@ void runTests() static void op(sdbusplus::message::message& m) { int32_t a = 0, b = 0; - std::map<std::string, - sdbusplus::message::variant<int, double>> a1{}; + std::map<std::string, sdbusplus::message::variant<int, double>> + a1{}; m.read(a, a1, b); assert(a == 1); @@ -411,7 +409,6 @@ void runTests() b.call_noreply(m); } - // Shutdown server. { auto m = b.new_method_call(SERVICE, "/", INTERFACE, QUIT_METHOD); diff --git a/test/message/types.cpp b/test/message/types.cpp index 604996e..e779c79 100644 --- a/test/message/types.cpp +++ b/test/message/types.cpp @@ -2,17 +2,16 @@ #include <sdbusplus/message/types.hpp> #include <sdbusplus/utility/tuple_to_array.hpp> -template <typename ...Args> -auto dbus_string(Args&& ... args) +template <typename... Args> auto dbus_string(Args&&... args) { - return std::string( - sdbusplus::utility::tuple_to_array( - sdbusplus::message::types::type_id<Args...>()).data()); + return std::string(sdbusplus::utility::tuple_to_array( + sdbusplus::message::types::type_id<Args...>()) + .data()); } TEST(MessageTypes, Integer) { - ASSERT_EQ(dbus_string(1),"i"); + ASSERT_EQ(dbus_string(1), "i"); } TEST(MessageTypes, Double) diff --git a/test/utility/type_traits.cpp b/test/utility/type_traits.cpp index 3a31d06..f2beed7 100644 --- a/test/utility/type_traits.cpp +++ b/test/utility/type_traits.cpp @@ -4,17 +4,14 @@ int main() { using sdbusplus::utility::array_to_ptr_t; - static_assert( - std::is_same<char, array_to_ptr_t<char, char>>::value, - "array_to_ptr_t<char, char> != char"); + static_assert(std::is_same<char, array_to_ptr_t<char, char>>::value, + "array_to_ptr_t<char, char> != char"); - static_assert( - std::is_same<char*, array_to_ptr_t<char, char*>>::value, - "array_to_ptr_t<char, char*> != char*"); + static_assert(std::is_same<char*, array_to_ptr_t<char, char*>>::value, + "array_to_ptr_t<char, char*> != char*"); - static_assert( - std::is_same<char*, array_to_ptr_t<char, char[100]>>::value, - "array_to_ptr_t<char, char[100]> != char*"); + static_assert(std::is_same<char*, array_to_ptr_t<char, char[100]>>::value, + "array_to_ptr_t<char, char[100]> != char*"); static_assert( std::is_same<char[100], array_to_ptr_t<int, char[100]>>::value, diff --git a/test/vtable/vtable.cpp b/test/vtable/vtable.cpp index ab1e34a..bc67382 100644 --- a/test/vtable/vtable.cpp +++ b/test/vtable/vtable.cpp @@ -1,22 +1,19 @@ #include <sdbusplus/vtable.hpp> #include <gtest/gtest.h> -static const sdbusplus::vtable::vtable_t example[] = - { - sdbusplus::vtable::start(), - sdbusplus::vtable::method((const char*)1, (const char*)2, - (const char*)3, - (sd_bus_message_handler_t)4), - sdbusplus::vtable::signal((const char*)5, (const char*)6), - sdbusplus::vtable::property((const char*)7, (const char*)8, - (sd_bus_property_get_t)9, - sdbusplus::vtable::property_::const_), - sdbusplus::vtable::property((const char*)10, (const char*)11, - (sd_bus_property_get_t)12, - (sd_bus_property_set_t)13), - sdbusplus::vtable::property_o((const char*)14, (const char*)15, 16), - sdbusplus::vtable::end() - }; +static const sdbusplus::vtable::vtable_t example[] = { + sdbusplus::vtable::start(), + sdbusplus::vtable::method((const char*)1, (const char*)2, (const char*)3, + (sd_bus_message_handler_t)4), + sdbusplus::vtable::signal((const char*)5, (const char*)6), + sdbusplus::vtable::property((const char*)7, (const char*)8, + (sd_bus_property_get_t)9, + sdbusplus::vtable::property_::const_), + sdbusplus::vtable::property((const char*)10, (const char*)11, + (sd_bus_property_get_t)12, + (sd_bus_property_set_t)13), + sdbusplus::vtable::property_o((const char*)14, (const char*)15, 16), + sdbusplus::vtable::end()}; extern const sd_bus_vtable example2[]; extern const size_t example2_size; diff --git a/test/vtable/vtable_c.c b/test/vtable/vtable_c.c index 442d6c7..d01506b 100644 --- a/test/vtable/vtable_c.c +++ b/test/vtable/vtable_c.c @@ -1,21 +1,17 @@ #include <systemd/sd-bus.h> - -const sd_bus_vtable example2[] = - { - SD_BUS_VTABLE_START(0), - SD_BUS_METHOD((const char*)1, (const char*)2, - (const char*)3, (sd_bus_message_handler_t)4, 0), - SD_BUS_SIGNAL((const char*)5, (const char*)6, 0), - SD_BUS_PROPERTY((const char*)7, (const char*)8, - (sd_bus_property_get_t)9, 0, - SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_WRITABLE_PROPERTY((const char*)10, (const char*)11, - (sd_bus_property_get_t)12, - (sd_bus_property_set_t)13, 0, 0), - SD_BUS_PROPERTY((const char*)14, (const char*)15, NULL, 16, 0), - SD_BUS_VTABLE_END, - }; +const sd_bus_vtable example2[] = { + SD_BUS_VTABLE_START(0), + SD_BUS_METHOD((const char*)1, (const char*)2, (const char*)3, + (sd_bus_message_handler_t)4, 0), + SD_BUS_SIGNAL((const char*)5, (const char*)6, 0), + SD_BUS_PROPERTY((const char*)7, (const char*)8, (sd_bus_property_get_t)9, 0, + SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_WRITABLE_PROPERTY((const char*)10, (const char*)11, + (sd_bus_property_get_t)12, + (sd_bus_property_set_t)13, 0, 0), + SD_BUS_PROPERTY((const char*)14, (const char*)15, NULL, 16, 0), + SD_BUS_VTABLE_END, +}; const size_t example2_size = sizeof(example2); - |

