diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-03-29 10:32:41 -0400 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-03-29 10:33:05 -0400 |
commit | 615b2a8f8cc0cffc5773cb40f7f3d74b8ea1e81f (patch) | |
tree | 4d5e6426c3ae5074152a787abe38d033e7cbad2b | |
parent | 6211a430c196bcecbefb9bf52ab99e372e6006a8 (diff) | |
download | phosphor-inventory-manager-615b2a8f8cc0cffc5773cb40f7f3d74b8ea1e81f.tar.gz phosphor-inventory-manager-615b2a8f8cc0cffc5773cb40f7f3d74b8ea1e81f.zip |
Enable clang-format
Fix up problems and enable clang-format during CI builds.
Change-Id: Ia5c88281f7090c0aa09ba586d968f1fcd8aba4f1
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r-- | .clang-format | 85 | ||||
-rw-r--r-- | app.cpp | 5 | ||||
-rw-r--r-- | errors.cpp | 3 | ||||
-rw-r--r-- | errors.hpp | 48 | ||||
-rw-r--r-- | events.hpp | 13 | ||||
-rw-r--r-- | functor.cpp | 25 | ||||
-rw-r--r-- | functor.hpp | 335 | ||||
-rw-r--r-- | manager.cpp | 123 | ||||
-rw-r--r-- | manager.hpp | 430 | ||||
-rw-r--r-- | serialize.hpp | 5 | ||||
-rw-r--r-- | test/test.cpp | 652 | ||||
-rw-r--r-- | types.hpp | 13 | ||||
-rw-r--r-- | utils.hpp | 36 |
13 files changed, 844 insertions, 929 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..bbc1bb1 --- /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: true +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 +... + @@ -25,10 +25,7 @@ int main(int argc, char* argv[]) try { phosphor::inventory::manager::Manager manager( - sdbusplus::bus::new_system(), - BUSNAME, - INVENTORY_ROOT, - IFACE); + sdbusplus::bus::new_system(), BUSNAME, INVENTORY_ROOT, IFACE); manager.run(); exit(EXIT_SUCCESS); } @@ -25,8 +25,7 @@ namespace manager void InterfaceError::log() const { logging::log<logging::level::ERR>( - what(), - phosphor::logging::entry("INTERFACE=%s", interface)); + what(), phosphor::logging::entry("INTERFACE=%s", interface)); } } // namespace manager } // namespace inventory @@ -17,31 +17,29 @@ namespace manager */ class InterfaceError final : public std::invalid_argument { - public: - ~InterfaceError() = default; - InterfaceError() = delete; - InterfaceError(const InterfaceError&) = delete; - InterfaceError(InterfaceError&&) = default; - InterfaceError& operator=(const InterfaceError&) = delete; - InterfaceError& operator=(InterfaceError&&) = default; - - /** @brief Construct an interface error. - * - * @param[in] msg - The message to be returned by what(). - * @param[in] iface - The failing interface name. - */ - InterfaceError( - const char* msg, - const std::string& iface) : - std::invalid_argument(msg), - interface(iface) {} - - /** @brief Log the exception message to the systemd journal. */ - void log() const; - - private: - - std::string interface; + public: + ~InterfaceError() = default; + InterfaceError() = delete; + InterfaceError(const InterfaceError&) = delete; + InterfaceError(InterfaceError&&) = default; + InterfaceError& operator=(const InterfaceError&) = delete; + InterfaceError& operator=(InterfaceError&&) = default; + + /** @brief Construct an interface error. + * + * @param[in] msg - The message to be returned by what(). + * @param[in] iface - The failing interface name. + */ + InterfaceError(const char* msg, const std::string& iface) : + std::invalid_argument(msg), interface(iface) + { + } + + /** @brief Log the exception message to the systemd journal. */ + void log() const; + + private: + std::string interface; }; } // namespace manager @@ -36,10 +36,10 @@ struct Event : public std::vector<Filter> * @param[in] filters - An array of filter callbacks. * @param[in] t - The event type. */ - explicit Event( - const std::vector<Filter>& filters, Type t = Type::STARTUP) : - std::vector<Filter>(filters), - type(t) {} + explicit Event(const std::vector<Filter>& filters, Type t = Type::STARTUP) : + std::vector<Filter>(filters), type(t) + { + } /** @brief event class enumeration. */ Type type; @@ -70,8 +70,9 @@ struct DbusSignal final : public Event * match callback filtering functions. */ DbusSignal(const char* sig, const std::vector<Filter>& filters) : - Event(filters, Type::DBUS_SIGNAL), - signature(sig) {} + Event(filters, Type::DBUS_SIGNAL), signature(sig) + { + } const char* signature; }; diff --git a/functor.cpp b/functor.cpp index ffe272b..b9e2521 100644 --- a/functor.cpp +++ b/functor.cpp @@ -24,19 +24,16 @@ namespace manager { namespace functor { -bool PropertyConditionBase::operator()( - sdbusplus::bus::bus& bus, - sdbusplus::message::message&, - Manager& mgr) const +bool PropertyConditionBase::operator()(sdbusplus::bus::bus& bus, + sdbusplus::message::message&, + Manager& mgr) const { std::string path(_path); return (*this)(path, bus, mgr); } -bool PropertyConditionBase::operator()( - const std::string& path, - sdbusplus::bus::bus& bus, - Manager&) const +bool PropertyConditionBase::operator()(const std::string& path, + sdbusplus::bus::bus& bus, Manager&) const { std::string host; @@ -47,10 +44,9 @@ bool PropertyConditionBase::operator()( else { auto mapperCall = bus.new_method_call( - "xyz.openbmc_project.ObjectMapper", - "/xyz/openbmc_project/object_mapper", - "xyz.openbmc_project.ObjectMapper", - "GetObject"); + "xyz.openbmc_project.ObjectMapper", + "/xyz/openbmc_project/object_mapper", + "xyz.openbmc_project.ObjectMapper", "GetObject"); mapperCall.append(path); mapperCall.append(std::vector<std::string>({_iface})); @@ -77,10 +73,7 @@ bool PropertyConditionBase::operator()( } } auto hostCall = bus.new_method_call( - host.c_str(), - path.c_str(), - "org.freedesktop.DBus.Properties", - "Get"); + host.c_str(), path.c_str(), "org.freedesktop.DBus.Properties", "Get"); hostCall.append(_iface); hostCall.append(_property); diff --git a/functor.hpp b/functor.hpp index e48e6d3..fc763e5 100644 --- a/functor.hpp +++ b/functor.hpp @@ -24,8 +24,7 @@ class Manager; * * @tparam T - The type of the action being adapted. */ -template <typename T> -auto make_action(T&& action) +template <typename T> auto make_action(T&& action) { return Action(std::forward<T>(action)); } @@ -39,8 +38,7 @@ auto make_action(T&& action) * * @tparam T - The type of the filter being adapted. */ -template <typename T> -auto make_filter(T&& filter) +template <typename T> auto make_filter(T&& filter) { return Filter(std::forward<T>(filter)); } @@ -54,14 +52,13 @@ auto make_filter(T&& filter) * * @tparam T - The type of the functor being adapted. */ -template <typename T> -auto make_path_condition(T&& condition) +template <typename T> auto make_path_condition(T&& condition) { return PathCondition(std::forward<T>(condition)); } -template <typename T, typename ...Args> -auto callArrayWithStatus(T&& container, Args&& ...args) +template <typename T, typename... Args> +auto callArrayWithStatus(T&& container, Args&&... args) { for (auto f : container) { @@ -77,12 +74,10 @@ namespace functor { /** @brief Destroy objects action. */ -inline auto destroyObjects( - std::vector<const char*>&& paths, - std::vector<PathCondition>&& conditions) +inline auto destroyObjects(std::vector<const char*>&& paths, + std::vector<PathCondition>&& conditions) { - return [ = ](auto & b, auto & m) - { + return [=](auto& b, auto& m) { for (const auto& p : paths) { if (callArrayWithStatus(conditions, p, b, m)) @@ -94,13 +89,10 @@ inline auto destroyObjects( } /** @brief Create objects action. */ -inline auto createObjects( - std::map<sdbusplus::message::object_path, Object>&& objs) +inline auto + createObjects(std::map<sdbusplus::message::object_path, Object>&& objs) { - return [ = ](auto&, auto & m) - { - m.createObjects(objs); - }; + return [=](auto&, auto& m) { m.createObjects(objs); }; } /** @brief Set a property action. @@ -123,27 +115,24 @@ inline auto createObjects( * to the requested value. */ template <typename T, typename U, typename V> -auto setProperty( - std::vector<const char*>&& paths, - std::vector<PathCondition>&& conditions, - const char* iface, - U&& member, - V&& value) +auto setProperty(std::vector<const char*>&& paths, + std::vector<PathCondition>&& conditions, const char* iface, + U&& member, V&& value) { // The manager is the only parameter passed to actions. // Bind the path, interface, interface member function pointer, // and value to a lambda. When it is called, forward the // path, interface and value on to the manager member function. - return [paths, conditions = conditions, iface, - member, - value = std::forward<V>(value)](auto & b, auto & m) + return [ + paths, conditions = conditions, iface, member, + value = std::forward<V>(value) + ](auto& b, auto& m) { for (auto p : paths) { if (callArrayWithStatus(conditions, p, b, m)) { - m.template invokeMethod<T>( - p, iface, member, value); + m.template invokeMethod<T>(p, iface, member, value); } } }; @@ -155,57 +144,53 @@ auto setProperty( * @tparam T - The type of the property being tested. * @tparam U - The type of the condition checking functor. */ -template <typename T, typename U> -struct PropertyChangedCondition +template <typename T, typename U> struct PropertyChangedCondition { - PropertyChangedCondition() = delete; - ~PropertyChangedCondition() = default; - PropertyChangedCondition(const PropertyChangedCondition&) = default; - PropertyChangedCondition& operator=(const PropertyChangedCondition&) = default; - PropertyChangedCondition(PropertyChangedCondition&&) = default; - PropertyChangedCondition& operator=(PropertyChangedCondition&&) = default; - PropertyChangedCondition(const char* iface, const char* property, - U&& condition) : - _iface(iface), - _property(property), - _condition(std::forward<U>(condition)) { } - - /** @brief Test a property value. - * - * Extract the property from the PropertiesChanged - * message and run the condition test. - */ - bool operator()( - sdbusplus::bus::bus&, - sdbusplus::message::message& msg, - Manager&) const - { - std::map < - std::string, - sdbusplus::message::variant<T >> properties; - const char* iface = nullptr; + PropertyChangedCondition() = delete; + ~PropertyChangedCondition() = default; + PropertyChangedCondition(const PropertyChangedCondition&) = default; + PropertyChangedCondition& + operator=(const PropertyChangedCondition&) = default; + PropertyChangedCondition(PropertyChangedCondition&&) = default; + PropertyChangedCondition& operator=(PropertyChangedCondition&&) = default; + PropertyChangedCondition(const char* iface, const char* property, + U&& condition) : + _iface(iface), + _property(property), _condition(std::forward<U>(condition)) + { + } - msg.read(iface); - if (!iface || strcmp(iface, _iface)) - { - return false; - } + /** @brief Test a property value. + * + * Extract the property from the PropertiesChanged + * message and run the condition test. + */ + bool operator()(sdbusplus::bus::bus&, sdbusplus::message::message& msg, + Manager&) const + { + std::map<std::string, sdbusplus::message::variant<T>> properties; + const char* iface = nullptr; - msg.read(properties); - auto it = properties.find(_property); - if (it == properties.cend()) - { - return false; - } + msg.read(iface); + if (!iface || strcmp(iface, _iface)) + { + return false; + } - return _condition( - std::forward<T>(it->second.template get<T>())); + msg.read(properties); + auto it = properties.find(_property); + if (it == properties.cend()) + { + return false; } - private: - const char* _iface; - const char* _property; - U _condition; + return _condition(std::forward<T>(it->second.template get<T>())); + } + + private: + const char* _iface; + const char* _property; + U _condition; }; /** @struct PropertyConditionBase @@ -216,63 +201,55 @@ struct PropertyChangedCondition */ struct PropertyConditionBase { - PropertyConditionBase() = delete; - virtual ~PropertyConditionBase() = default; - PropertyConditionBase(const PropertyConditionBase&) = default; - PropertyConditionBase& operator=(const PropertyConditionBase&) = default; - PropertyConditionBase(PropertyConditionBase&&) = default; - PropertyConditionBase& operator=(PropertyConditionBase&&) = default; + PropertyConditionBase() = delete; + virtual ~PropertyConditionBase() = default; + PropertyConditionBase(const PropertyConditionBase&) = default; + PropertyConditionBase& operator=(const PropertyConditionBase&) = default; + PropertyConditionBase(PropertyConditionBase&&) = default; + PropertyConditionBase& operator=(PropertyConditionBase&&) = default; - /** @brief Constructor - * - * The service argument can be nullptr. If something - * else is provided the function will call the the - * service directly. If omitted, the function will - * look up the service in the ObjectMapper. - * - * @param path - The path of the object containing - * the property to be tested. - * @param iface - The interface hosting the property - * to be tested. - * @param property - The property to be tested. - * @param service - The DBus service hosting the object. - */ - PropertyConditionBase( - const char* path, - const char* iface, - const char* property, - const char* service) : - _path(path ? path : std::string()), - _iface(iface), - _property(property), - _service(service) {} + /** @brief Constructor + * + * The service argument can be nullptr. If something + * else is provided the function will call the the + * service directly. If omitted, the function will + * look up the service in the ObjectMapper. + * + * @param path - The path of the object containing + * the property to be tested. + * @param iface - The interface hosting the property + * to be tested. + * @param property - The property to be tested. + * @param service - The DBus service hosting the object. + */ + PropertyConditionBase(const char* path, const char* iface, + const char* property, const char* service) : + _path(path ? path : std::string()), + _iface(iface), _property(property), _service(service) + { + } - /** @brief Forward comparison to type specific implementation. */ - virtual bool eval(sdbusplus::message::message&) const = 0; + /** @brief Forward comparison to type specific implementation. */ + virtual bool eval(sdbusplus::message::message&) const = 0; - /** @brief Test a property value. - * - * Make a DBus call and test the value of any property. - */ - bool operator()( - sdbusplus::bus::bus&, - sdbusplus::message::message&, - Manager&) const; + /** @brief Test a property value. + * + * Make a DBus call and test the value of any property. + */ + bool operator()(sdbusplus::bus::bus&, sdbusplus::message::message&, + Manager&) const; - /** @brief Test a property value. - * - * Make a DBus call and test the value of any property. - */ - bool operator()( - const std::string&, - sdbusplus::bus::bus&, - Manager&) const; + /** @brief Test a property value. + * + * Make a DBus call and test the value of any property. + */ + bool operator()(const std::string&, sdbusplus::bus::bus&, Manager&) const; - private: - std::string _path; - std::string _iface; - std::string _property; - const char* _service; + private: + std::string _path; + std::string _iface; + std::string _property; + const char* _service; }; /** @struct PropertyCondition @@ -284,85 +261,75 @@ struct PropertyConditionBase template <typename T, typename U> struct PropertyCondition final : public PropertyConditionBase { - PropertyCondition() = delete; - ~PropertyCondition() = default; - PropertyCondition(const PropertyCondition&) = default; - PropertyCondition& operator=(const PropertyCondition&) = default; - PropertyCondition(PropertyCondition&&) = default; - PropertyCondition& operator=(PropertyCondition&&) = default; + PropertyCondition() = delete; + ~PropertyCondition() = default; + PropertyCondition(const PropertyCondition&) = default; + PropertyCondition& operator=(const PropertyCondition&) = default; + PropertyCondition(PropertyCondition&&) = default; + PropertyCondition& operator=(PropertyCondition&&) = default; - /** @brief Constructor - * - * The service argument can be nullptr. If something - * else is provided the function will call the the - * service directly. If omitted, the function will - * look up the service in the ObjectMapper. - * - * @param path - The path of the object containing - * the property to be tested. - * @param iface - The interface hosting the property - * to be tested. - * @param property - The property to be tested. - * @param condition - The test to run on the property. - * @param service - The DBus service hosting the object. - */ - PropertyCondition( - const char* path, - const char* iface, - const char* property, - U&& condition, - const char* service) : - PropertyConditionBase(path, iface, property, service), - _condition(std::forward<decltype(condition)>(condition)) {} + /** @brief Constructor + * + * The service argument can be nullptr. If something + * else is provided the function will call the the + * service directly. If omitted, the function will + * look up the service in the ObjectMapper. + * + * @param path - The path of the object containing + * the property to be tested. + * @param iface - The interface hosting the property + * to be tested. + * @param property - The property to be tested. + * @param condition - The test to run on the property. + * @param service - The DBus service hosting the object. + */ + PropertyCondition(const char* path, const char* iface, const char* property, + U&& condition, const char* service) : + PropertyConditionBase(path, iface, property, service), + _condition(std::forward<decltype(condition)>(condition)) + { + } - /** @brief Test a property value. - * - * Make a DBus call and test the value of any property. - */ - bool eval(sdbusplus::message::message& msg) const override - { - sdbusplus::message::variant<T> value; - msg.read(value); - return _condition( - std::forward<T>(value.template get<T>())); - } + /** @brief Test a property value. + * + * Make a DBus call and test the value of any property. + */ + bool eval(sdbusplus::message::message& msg) const override + { + sdbusplus::message::variant<T> value; + msg.read(value); + return _condition(std::forward<T>(value.template get<T>())); + } - private: - U _condition; + private: + U _condition; }; -/** @brief Implicit type deduction for constructing PropertyChangedCondition. */ +/** @brief Implicit type deduction for constructing PropertyChangedCondition. */ template <typename T> -auto propertyChangedTo( - const char* iface, - const char* property, - T&& val) +auto propertyChangedTo(const char* iface, const char* property, T&& val) { auto condition = [val = std::forward<T>(val)](T && arg) { return arg == val; }; using U = decltype(condition); - return PropertyChangedCondition<T, U>( - iface, property, std::move(condition)); + return PropertyChangedCondition<T, U>(iface, property, + std::move(condition)); } /** @brief Implicit type deduction for constructing PropertyCondition. */ template <typename T> -auto propertyIs( - const char* path, - const char* iface, - const char* property, - T&& val, - const char* service = nullptr) +auto propertyIs(const char* path, const char* iface, const char* property, + T&& val, const char* service = nullptr) { auto condition = [val = std::forward<T>(val)](T && arg) { return arg == val; }; using U = decltype(condition); - return PropertyCondition<T, U>( - path, iface, property, std::move(condition), service); + return PropertyCondition<T, U>(path, iface, property, std::move(condition), + service); } } // namespace functor } // namespace manager diff --git a/manager.cpp b/manager.cpp index 6049161..8b35a0a 100644 --- a/manager.cpp +++ b/manager.cpp @@ -43,11 +43,8 @@ auto _signal(sd_bus_message* m, void* data, sd_bus_error* e) noexcept auto& args = *static_cast<Manager::SigArg*>(data); sd_bus_message_ref(m); auto& mgr = *std::get<0>(args); - mgr.handleEvent( - msg, - static_cast<const DbusSignal&>( - *std::get<1>(args)), - *std::get<2>(args)); + mgr.handleEvent(msg, static_cast<const DbusSignal&>(*std::get<1>(args)), + *std::get<2>(args)); } catch (const std::exception& e) { @@ -57,49 +54,34 @@ auto _signal(sd_bus_message* m, void* data, sd_bus_error* e) noexcept return 0; } -Manager::Manager( - sdbusplus::bus::bus&& bus, - const char* busname, - const char* root, - const char* iface) : +Manager::Manager(sdbusplus::bus::bus&& bus, const char* busname, + const char* root, const char* iface) : ServerObject<ManagerIface>(bus, root), - _shutdown(false), - _root(root), - _bus(std::move(bus)), - _manager(_bus, root) + _shutdown(false), _root(root), _bus(std::move(bus)), _manager(_bus, root) { for (auto& group : _events) { - for (auto pEvent : std::get<std::vector<EventBasePtr>>( - group)) + for (auto pEvent : std::get<std::vector<EventBasePtr>>(group)) { - if (pEvent->type != - Event::Type::DBUS_SIGNAL) + if (pEvent->type != Event::Type::DBUS_SIGNAL) { continue; } // Create a callback context for this event group. - auto dbusEvent = static_cast<DbusSignal*>( - pEvent.get()); + auto dbusEvent = static_cast<DbusSignal*>(pEvent.get()); // Go ahead and store an iterator pointing at // the event data to avoid lookups later since // additional signal callbacks aren't added // after the manager is constructed. _sigargs.emplace_back( - std::make_unique<SigArg>( - this, - dbusEvent, - &group)); + std::make_unique<SigArg>(this, dbusEvent, &group)); // Register our callback and the context for // each signal event. - _matches.emplace_back( - _bus, - dbusEvent->signature, - _signal, - _sigargs.back().get()); + _matches.emplace_back(_bus, dbusEvent->signature, _signal, + _sigargs.back().get()); } } @@ -121,11 +103,9 @@ void Manager::run() noexcept // Run startup events. for (auto& group : _events) { - for (auto pEvent : std::get<std::vector<EventBasePtr>>( - group)) + for (auto pEvent : std::get<std::vector<EventBasePtr>>(group)) { - if (pEvent->type == - Event::Type::STARTUP) + if (pEvent->type == Event::Type::STARTUP) { handleEvent(unusedMsg, *pEvent, group); } @@ -146,12 +126,10 @@ void Manager::run() noexcept } } -void Manager::updateInterfaces( - const sdbusplus::message::object_path& path, - const Object& interfaces, - ObjectReferences::iterator pos, - bool newObject, - bool restoreFromCache) +void Manager::updateInterfaces(const sdbusplus::message::object_path& path, + const Object& interfaces, + ObjectReferences::iterator pos, bool newObject, + bool restoreFromCache) { auto& refaces = pos->second; auto ifaceit = interfaces.cbegin(); @@ -164,39 +142,28 @@ void Manager::updateInterfaces( try { // Find the binding ops for this interface. - opsit = std::lower_bound( - opsit, - _makers.cend(), - ifaceit->first, - compareFirst(_makers.key_comp())); + opsit = std::lower_bound(opsit, _makers.cend(), ifaceit->first, + compareFirst(_makers.key_comp())); if (opsit == _makers.cend() || opsit->first != ifaceit->first) { // This interface is not supported. - throw InterfaceError( - "Encountered unsupported interface.", - ifaceit->first); + throw InterfaceError("Encountered unsupported interface.", + ifaceit->first); } // Find the binding insertion point or the binding to update. - refaceit = std::lower_bound( - refaceit, - refaces.end(), - ifaceit->first, - compareFirst(refaces.key_comp())); + refaceit = std::lower_bound(refaceit, refaces.end(), ifaceit->first, + compareFirst(refaces.key_comp())); if (refaceit == refaces.end() || refaceit->first != ifaceit->first) { // Add the new interface. auto& ctor = std::get<MakerType>(opsit->second); refaceit = refaces.insert( - refaceit, - std::make_pair( - ifaceit->first, - ctor( - _bus, - path.str.c_str(), - ifaceit->second))); + refaceit, + std::make_pair(ifaceit->first, ctor(_bus, path.str.c_str(), + ifaceit->second))); signals.push_back(ifaceit->first); } else @@ -249,11 +216,8 @@ void Manager::updateObjects( while (objit != objs.cend()) { // Find the insertion point or the object to update. - refit = std::lower_bound( - refit, - _refs.end(), - objit->first, - compareFirst(RelPathCompare(_root))); + refit = std::lower_bound(refit, _refs.end(), objit->first, + compareFirst(RelPathCompare(_root))); absPath.assign(_root); absPath.append(objit->first); @@ -262,10 +226,7 @@ void Manager::updateObjects( if (refit == _refs.end() || refit->first != absPath) { refit = _refs.insert( - refit, - std::make_pair( - absPath, - decltype(_refs)::mapped_type())); + refit, std::make_pair(absPath, decltype(_refs)::mapped_type())); newObj = true; } @@ -280,10 +241,8 @@ void Manager::notify(std::map<sdbusplus::message::object_path, Object> objs) updateObjects(objs); } -void Manager::handleEvent( - sdbusplus::message::message& msg, - const Event& event, - const EventInfo& info) +void Manager::handleEvent(sdbusplus::message::message& msg, const Event& event, + const EventInfo& info) { auto& actions = std::get<1>(info); @@ -300,8 +259,7 @@ void Manager::handleEvent( } } -void Manager::destroyObjects( - const std::vector<const char*>& paths) +void Manager::destroyObjects(const std::vector<const char*>& paths) { std::string p; @@ -320,28 +278,25 @@ void Manager::createObjects( updateObjects(objs); } -any_ns::any& Manager::getInterfaceHolder( - const char* path, const char* interface) +any_ns::any& Manager::getInterfaceHolder(const char* path, + const char* interface) { return const_cast<any_ns::any&>( - const_cast<const Manager*>( - this)->getInterfaceHolder(path, interface)); + const_cast<const Manager*>(this)->getInterfaceHolder(path, interface)); } -const any_ns::any& Manager::getInterfaceHolder( - const char* path, const char* interface) const +const any_ns::any& Manager::getInterfaceHolder(const char* path, + const char* interface) const { std::string p{path}; auto oit = _refs.find(_root + p); if (oit == _refs.end()) - throw std::runtime_error( - _root + p + " was not found"); + throw std::runtime_error(_root + p + " was not found"); auto& obj = oit->second; auto iit = obj.find(interface); if (iit == obj.end()) - throw std::runtime_error( - "interface was not found"); + throw std::runtime_error("interface was not found"); return iit->second; } diff --git a/manager.hpp b/manager.hpp index 624eb60..9bbd3c7 100644 --- a/manager.hpp +++ b/manager.hpp @@ -18,8 +18,7 @@ namespace inventory namespace manager { -template <typename T> -using ServerObject = T; +template <typename T> using ServerObject = T; using ManagerIface = sdbusplus::xyz::openbmc_project::Inventory::server::Manager; @@ -33,11 +32,13 @@ using ManagerIface = * * @tparam T - The sdbusplus server binding type. */ -template <typename T, typename Enable = void> -struct PropertiesVariant {}; +template <typename T, typename Enable = void> struct PropertiesVariant +{ +}; template <typename T> -struct PropertiesVariant<T, typename std::enable_if<std::is_object<T>::value>::type> +struct PropertiesVariant< + T, typename std::enable_if<std::is_object<T>::value>::type> { using Type = typename T::PropertiesVariant; }; @@ -45,39 +46,35 @@ struct PropertiesVariant<T, typename std::enable_if<std::is_object<T>::value>::t template <typename T> using PropertiesVariantType = typename PropertiesVariant<T>::Type; -template <typename T, typename U = int> -struct HasProperties : std::false_type +template <typename T, typename U = int> struct HasProperties : std::false_type { }; template <typename T> -struct HasProperties <T, - decltype((void) std::declval<typename T::PropertiesVariant>(), 0)> : - std::true_type +struct HasProperties< + T, decltype((void)std::declval<typename T::PropertiesVariant>(), 0)> + : std::true_type { }; template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> -any_ns::any propMake( - sdbusplus::bus::bus& bus, const char* path, const Interface& props) +any_ns::any propMake(sdbusplus::bus::bus& bus, const char* path, + const Interface& props) { - using InterfaceVariant = - std::map<std::string, PropertiesVariantType<T>>; + using InterfaceVariant = std::map<std::string, PropertiesVariantType<T>>; InterfaceVariant v; for (const auto& p : props) { - v.emplace( - p.first, - convertVariant<PropertiesVariantType<T>>(p.second)); + v.emplace(p.first, convertVariant<PropertiesVariantType<T>>(p.second)); } return any_ns::any(std::make_shared<T>(bus, path, v)); } template <typename T, std::enable_if_t<!HasProperties<T>::value, bool> = false> -any_ns::any propMake( - sdbusplus::bus::bus& bus, const char* path, const Interface& props) +any_ns::any propMake(sdbusplus::bus::bus& bus, const char* path, + const Interface& props) { return any_ns::any(std::make_shared<T>(bus, path)); } @@ -85,7 +82,7 @@ any_ns::any propMake( template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> void propAssign(const Interface& props, any_ns::any& holder) { - auto& iface = *any_ns::any_cast<std::shared_ptr<T> &>(holder); + auto& iface = *any_ns::any_cast<std::shared_ptr<T>&>(holder); for (const auto& p : props) { iface.setPropertyByName( @@ -99,38 +96,34 @@ void propAssign(const Interface& props, any_ns::any& holder) } template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> -void propSerialize( - const std::string& path, const std::string& iface, - const any_ns::any& holder) +void propSerialize(const std::string& path, const std::string& iface, + const any_ns::any& holder) { - const auto& object = - *any_ns::any_cast<const std::shared_ptr<T> &>(holder); + const auto& object = *any_ns::any_cast<const std::shared_ptr<T>&>(holder); cereal::serialize(path, iface, object); } template <typename T, std::enable_if_t<!HasProperties<T>::value, bool> = false> -void propSerialize( - const std::string& path, const std::string& iface, - const any_ns::any& holder) +void propSerialize(const std::string& path, const std::string& iface, + const any_ns::any& holder) { cereal::serialize(path, iface); } template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> -void propDeSerialize( - const std::string& path, const std::string& iface, any_ns::any& holder) +void propDeSerialize(const std::string& path, const std::string& iface, + any_ns::any& holder) { - auto& object = *any_ns::any_cast<std::shared_ptr<T> &>(holder); + auto& object = *any_ns::any_cast<std::shared_ptr<T>&>(holder); cereal::deserialize(path, iface, object); } template <typename T, std::enable_if_t<!HasProperties<T>::value, bool> = false> -void propDeSerialize( - const std::string& path, const std::string& iface, any_ns::any& holder) +void propDeSerialize(const std::string& path, const std::string& iface, + any_ns::any& holder) { } - /** @struct MakeInterface * @brief Adapt an sdbusplus interface proxy. * @@ -140,11 +133,10 @@ void propDeSerialize( * @tparam T - The type of the interface being adapted. */ -template <typename T> -struct MakeInterface +template <typename T> struct MakeInterface { - static any_ns::any make( - sdbusplus::bus::bus& bus, const char* path, const Interface& props) + static any_ns::any make(sdbusplus::bus::bus& bus, const char* path, + const Interface& props) { return propMake<T>(bus, path, props); } @@ -154,19 +146,17 @@ struct MakeInterface propAssign<T>(props, holder); } - static void serialize( - const std::string& path, const std::string& iface, - const any_ns::any& holder) + static void serialize(const std::string& path, const std::string& iface, + const any_ns::any& holder) { propSerialize<T>(path, iface, holder); } - static void deserialize( - const std::string& path, const std::string& iface, any_ns::any& holder) + static void deserialize(const std::string& path, const std::string& iface, + any_ns::any& holder) { propDeSerialize<T>(path, iface, holder); } - }; /** @class Manager @@ -175,189 +165,177 @@ struct MakeInterface * A concrete implementation for the xyz.openbmc_project.Inventory.Manager * DBus API. */ -class Manager final : - public ServerObject<ManagerIface> +class Manager final : public ServerObject<ManagerIface> { - public: - Manager() = delete; - Manager(const Manager&) = delete; - Manager& operator=(const Manager&) = delete; - Manager(Manager&&) = default; - Manager& operator=(Manager&&) = default; - ~Manager() = default; - - /** @brief Construct an inventory manager. - * - * @param[in] bus - An sdbusplus bus connection. - * @param[in] busname - The DBus busname to own. - * @param[in] root - The DBus path on which to implement - * an inventory manager. - * @param[in] iface - The DBus inventory interface to implement. - */ - Manager(sdbusplus::bus::bus&&, const char*, const char*, const char*); - - using EventInfo = std::tuple < - std::vector<EventBasePtr>, - std::vector<Action >>; - - /** @brief Start processing DBus messages. */ - void run() noexcept; - - /** @brief Provided for testing only. */ - void shutdown() noexcept; - - /** @brief sd_bus Notify method implementation callback. */ - void notify( - std::map<sdbusplus::message::object_path, Object> objs) override; - - /** @brief Event processing entry point. */ - void handleEvent(sdbusplus::message::message&, - const Event& event, - const EventInfo& info); - - /** @brief Drop one or more objects from DBus. */ - void destroyObjects( - const std::vector<const char*>& paths); - - /** @brief Add objects to DBus. */ - void createObjects( - const std::map<sdbusplus::message::object_path, Object>& objs); - - /** @brief Add or update objects on DBus. */ - void updateObjects( - const std::map<sdbusplus::message::object_path, Object>& objs, - bool restoreFromCache = false); - - /** @brief Restore persistent inventory items */ - void restore(); - - /** @brief Invoke an sdbusplus server binding method. - * - * Invoke the requested method with a reference to the requested - * sdbusplus server binding interface as a parameter. - * - * @tparam T - The sdbusplus server binding interface type. - * @tparam U - The type of the sdbusplus server binding member. - * @tparam Args - Argument types of the binding member. - * - * @param[in] path - The DBus path on which the method should - * be invoked. - * @param[in] interface - The DBus interface hosting the method. - * @param[in] member - Pointer to sdbusplus server binding member. - * @param[in] args - Arguments to forward to the binding member. - * - * @returns - The return/value type of the binding method being - * called. - */ - template<typename T, typename U, typename ...Args> - decltype(auto) invokeMethod(const char* path, const char* interface, - U&& member, Args&& ...args) - { - auto& iface = getInterface<T>(path, interface); - return (iface.*member)(std::forward<Args>(args)...); - } - - using SigArgs = std::vector < - std::unique_ptr < - std::tuple < - Manager*, - const DbusSignal*, - const EventInfo* >>>; - using SigArg = SigArgs::value_type::element_type; - - private: - using InterfaceComposite = std::map<std::string, any_ns::any>; - using ObjectReferences = std::map<std::string, InterfaceComposite>; - using Events = std::vector<EventInfo>; - - // The int instantiations are safe since the signature of these - // functions don't change from one instantiation to the next. - using MakerType = std::add_pointer_t < - decltype(MakeInterface<int>::make) >; - using AssignerType = std::add_pointer_t < - decltype(MakeInterface<int>::assign) >; - using SerializerType = std::add_pointer_t < - decltype(MakeInterface<int>::serialize) >; - using DeserializerType = std::add_pointer_t < - decltype(MakeInterface<int>::deserialize) >; - using Makers = std::map<std::string, - std::tuple<MakerType, AssignerType, - SerializerType, DeserializerType>>; - - /** @brief Provides weak references to interface holders. - * - * Common code for all types for the templated getInterface - * methods. - * - * @param[in] path - The DBus path for which the interface - * holder instance should be provided. - * @param[in] interface - The DBus interface for which the - * holder instance should be provided. - * - * @returns A weak reference to the holder instance. - */ - const any_ns::any& getInterfaceHolder( - const char*, const char*) const; - any_ns::any& getInterfaceHolder( - const char*, const char*); - - /** @brief Provides weak references to interface holders. - * - * @tparam T - The sdbusplus server binding interface type. - * - * @param[in] path - The DBus path for which the interface - * should be provided. - * @param[in] interface - The DBus interface to obtain. - * - * @returns A weak reference to the interface holder. - */ - template<typename T> - auto& getInterface(const char* path, const char* interface) - { - auto& holder = getInterfaceHolder(path, interface); - return *any_ns::any_cast<std::shared_ptr<T> &>(holder); - } - template<typename T> - auto& getInterface(const char* path, const char* interface) const - { - auto& holder = getInterfaceHolder(path, interface); - return *any_ns::any_cast<T>(holder); - } - - /** @brief Add or update interfaces on DBus. */ - void updateInterfaces( - const sdbusplus::message::object_path& path, - const Object& interfaces, - ObjectReferences::iterator pos, - bool emitSignals = true, - bool restoreFromCache = false); - - /** @brief Provided for testing only. */ - volatile bool _shutdown; - - /** @brief Path prefix applied to any relative paths. */ - const char* _root; - - /** @brief A container of sdbusplus server interface references. */ - ObjectReferences _refs; - - /** @brief A container contexts for signal callbacks. */ - SigArgs _sigargs; - - /** @brief A container of sdbusplus signal matches. */ - std::vector<sdbusplus::bus::match_t> _matches; - - /** @brief Persistent sdbusplus DBus bus connection. */ - sdbusplus::bus::bus _bus; - - /** @brief sdbusplus org.freedesktop.DBus.ObjectManager reference. */ - sdbusplus::server::manager::manager _manager; - - /** @brief A container of pimgen generated events and responses. */ - static const Events _events; - - /** @brief A container of pimgen generated factory methods. */ - static const Makers _makers; + public: + Manager() = delete; + Manager(const Manager&) = delete; + Manager& operator=(const Manager&) = delete; + Manager(Manager&&) = default; + Manager& operator=(Manager&&) = default; + ~Manager() = default; + + /** @brief Construct an inventory manager. + * + * @param[in] bus - An sdbusplus bus connection. + * @param[in] busname - The DBus busname to own. + * @param[in] root - The DBus path on which to implement + * an inventory manager. + * @param[in] iface - The DBus inventory interface to implement. + */ + Manager(sdbusplus::bus::bus&&, const char*, const char*, const char*); + + using EventInfo = + std::tuple<std::vector<EventBasePtr>, std::vector<Action>>; + + /** @brief Start processing DBus messages. */ + void run() noexcept; + + /** @brief Provided for testing only. */ + void shutdown() noexcept; + + /** @brief sd_bus Notify method implementation callback. */ + void + notify(std::map<sdbusplus::message::object_path, Object> objs) override; + + /** @brief Event processing entry point. */ + void handleEvent(sdbusplus::message::message&, const Event& event, + const EventInfo& info); + + /** @brief Drop one or more objects from DBus. */ + void destroyObjects(const std::vector<const char*>& paths); + + /** @brief Add objects to DBus. */ + void createObjects( + const std::map<sdbusplus::message::object_path, Object>& objs); + + /** @brief Add or update objects on DBus. */ + void updateObjects( + const std::map<sdbusplus::message::object_path, Object>& objs, + bool restoreFromCache = false); + + /** @brief Restore persistent inventory items */ + void restore(); + + /** @brief Invoke an sdbusplus server binding method. + * + * Invoke the requested method with a reference to the requested + * sdbusplus server binding interface as a parameter. + * + * @tparam T - The sdbusplus server binding interface type. + * @tparam U - The type of the sdbusplus server binding member. + * @tparam Args - Argument types of the binding member. + * + * @param[in] path - The DBus path on which the method should + * be invoked. + * @param[in] interface - The DBus interface hosting the method. + * @param[in] member - Pointer to sdbusplus server binding member. + * @param[in] args - Arguments to forward to the binding member. + * + * @returns - The return/value type of the binding method being + * called. + */ + template <typename T, typename U, typename... Args> + decltype(auto) invokeMethod(const char* path, const char* interface, + U&& member, Args&&... args) + { + auto& iface = getInterface<T>(path, interface); + return (iface.*member)(std::forward<Args>(args)...); + } + + using SigArgs = std::vector<std::unique_ptr< + std::tuple<Manager*, const DbusSignal*, const EventInfo*>>>; + using SigArg = SigArgs::value_type::element_type; + + private: + using InterfaceComposite = std::map<std::string, any_ns::any>; + using ObjectReferences = std::map<std::string, InterfaceComposite>; + using Events = std::vector<EventInfo>; + + // The int instantiations are safe since the signature of these + // functions don't change from one instantiation to the next. + using MakerType = std::add_pointer_t<decltype(MakeInterface<int>::make)>; + using AssignerType = + std::add_pointer_t<decltype(MakeInterface<int>::assign)>; + using SerializerType = + std::add_pointer_t<decltype(MakeInterface<int>::serialize)>; + using DeserializerType = + std::add_pointer_t<decltype(MakeInterface<int>::deserialize)>; + using Makers = + std::map<std::string, std::tuple<MakerType, AssignerType, + SerializerType, DeserializerType>>; + + /** @brief Provides weak references to interface holders. + * + * Common code for all types for the templated getInterface + * methods. + * + * @param[in] path - The DBus path for which the interface + * holder instance should be provided. + * @param[in] interface - The DBus interface for which the + * holder instance should be provided. + * + * @returns A weak reference to the holder instance. + */ + const any_ns::any& getInterfaceHolder(const char*, const char*) const; + any_ns::any& getInterfaceHolder(const char*, const char*); + + /** @brief Provides weak references to interface holders. + * + * @tparam T - The sdbusplus server binding interface type. + * + * @param[in] path - The DBus path for which the interface + * should be provided. + * @param[in] interface - The DBus interface to obtain. + * + * @returns A weak reference to the interface holder. + */ + template <typename T> + auto& getInterface(const char* path, const char* interface) + { + auto& holder = getInterfaceHolder(path, interface); + return *any_ns::any_cast<std::shared_ptr<T>&>(holder); + } + template <typename T> + auto& getInterface(const char* path, const char* interface) const + { + auto& holder = getInterfaceHolder(path, interface); + return *any_ns::any_cast<T>(holder); + } + + /** @brief Add or update interfaces on DBus. */ + void updateInterfaces(const sdbusplus::message::object_path& path, + const Object& interfaces, + ObjectReferences::iterator pos, + bool emitSignals = true, + bool restoreFromCache = false); + + /** @brief Provided for testing only. */ + volatile bool _shutdown; + + /** @brief Path prefix applied to any relative paths. */ + const char* _root; + + /** @brief A container of sdbusplus server interface references. */ + ObjectReferences _refs; + + /** @brief A container contexts for signal callbacks. */ + SigArgs _sigargs; + + /** @brief A container of sdbusplus signal matches. */ + std::vector<sdbusplus::bus::match_t> _matches; + + /** @brief Persistent sdbusplus DBus bus connection. */ + sdbusplus::bus::bus _bus; + + /** @brief sdbusplus org.freedesktop.DBus.ObjectManager reference. */ + sdbusplus::server::manager::manager _manager; + + /** @brief A container of pimgen generated events and responses. */ + static const Events _events; + + /** @brief A container of pimgen generated factory methods. */ + static const Makers _makers; }; } // namespace manager diff --git a/serialize.hpp b/serialize.hpp index 84463b3..132df58 100644 --- a/serialize.hpp +++ b/serialize.hpp @@ -56,8 +56,7 @@ inline void serialize(const Path& path, const Interface& iface) * @param[in] object - Object to be serialized */ template <typename T> -inline void deserialize( - const Path& path, const Interface& iface, T& object) +inline void deserialize(const Path& path, const Interface& iface, T& object) { fs::path p(PIM_PERSIST_PATH); p /= path; @@ -71,7 +70,7 @@ inline void deserialize( iarchive(object); } } - catch(cereal::Exception& e) + catch (cereal::Exception& e) { log<level::ERR>(e.what()); fs::remove(p); diff --git a/test/test.cpp b/test/test.cpp index 5d89f0d..5cadbe0 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -35,16 +35,16 @@ constexpr auto MGR_ROOT = "/testing/inventory"; constexpr auto EXAMPLE_SERVICE = "phosphor.inventory.test.example"; constexpr auto EXAMPLE_ROOT = "/testing"; -const auto trigger1 = sdbusplus::message::object_path(EXAMPLE_ROOT + - "/trigger1"s); -const auto trigger2 = sdbusplus::message::object_path(EXAMPLE_ROOT + - "/trigger2"s); -const auto trigger3 = sdbusplus::message::object_path(EXAMPLE_ROOT + - "/trigger3"s); -const auto trigger4 = sdbusplus::message::object_path(EXAMPLE_ROOT + - "/trigger4"s); -const auto trigger5 = sdbusplus::message::object_path(EXAMPLE_ROOT + - "/trigger5"s); +const auto trigger1 = + sdbusplus::message::object_path(EXAMPLE_ROOT + "/trigger1"s); +const auto trigger2 = + sdbusplus::message::object_path(EXAMPLE_ROOT + "/trigger2"s); +const auto trigger3 = + sdbusplus::message::object_path(EXAMPLE_ROOT + "/trigger3"s); +const auto trigger4 = + sdbusplus::message::object_path(EXAMPLE_ROOT + "/trigger4"s); +const auto trigger5 = + sdbusplus::message::object_path(EXAMPLE_ROOT + "/trigger5"s); const sdbusplus::message::object_path relDeleteMeOne{"/deleteme1"}; const sdbusplus::message::object_path relDeleteMeTwo{"/deleteme2"}; @@ -65,8 +65,7 @@ struct ExampleService { ~ExampleService() = default; ExampleService() : - shutdown(false), - bus(sdbusplus::bus::new_default()), + shutdown(false), bus(sdbusplus::bus::new_default()), objmgr(sdbusplus::server::manager::manager(bus, MGR_ROOT)) { bus.request_name(EXAMPLE_SERVICE); @@ -74,16 +73,16 @@ struct ExampleService void run() { - sdbusplus::server::object::object < - ExampleIface1, ExampleIface2 > t1(bus, trigger1.str.c_str()); - sdbusplus::server::object::object < - ExampleIface1, ExampleIface2 > t2(bus, trigger2.str.c_str()); - sdbusplus::server::object::object < - ExampleIface1, ExampleIface2 > t3(bus, trigger3.str.c_str()); - sdbusplus::server::object::object < - ExampleIface1, ExampleIface2 > t4(bus, trigger4.str.c_str()); - sdbusplus::server::object::object < - ExampleIface1, ExampleIface2 > t5(bus, trigger5.str.c_str()); + sdbusplus::server::object::object<ExampleIface1, ExampleIface2> t1( + bus, trigger1.str.c_str()); + sdbusplus::server::object::object<ExampleIface1, ExampleIface2> t2( + bus, trigger2.str.c_str()); + sdbusplus::server::object::object<ExampleIface1, ExampleIface2> t3( + bus, trigger3.str.c_str()); + sdbusplus::server::object::object<ExampleIface1, ExampleIface2> t4( + bus, trigger4.str.c_str()); + sdbusplus::server::object::object<ExampleIface1, ExampleIface2> t5( + bus, trigger5.str.c_str()); while (!shutdown) { @@ -97,62 +96,56 @@ struct ExampleService sdbusplus::server::manager::manager objmgr; }; - /** @class SignalQueue * @brief Store DBus signals in a queue. */ class SignalQueue { - public: - ~SignalQueue() = default; - SignalQueue() = delete; - SignalQueue(const SignalQueue&) = delete; - SignalQueue(SignalQueue&&) = default; - SignalQueue& operator=(const SignalQueue&) = delete; - SignalQueue& operator=(SignalQueue&&) = default; - explicit SignalQueue(const std::string& match) : - _bus(sdbusplus::bus::new_default()), - _match(_bus, match.c_str(), &callback, this), - _next(nullptr) - { - } + public: + ~SignalQueue() = default; + SignalQueue() = delete; + SignalQueue(const SignalQueue&) = delete; + SignalQueue(SignalQueue&&) = default; + SignalQueue& operator=(const SignalQueue&) = delete; + SignalQueue& operator=(SignalQueue&&) = default; + explicit SignalQueue(const std::string& match) : + _bus(sdbusplus::bus::new_default()), + _match(_bus, match.c_str(), &callback, this), _next(nullptr) + { + } - auto&& pop(unsigned timeout = 1000000) + auto&& pop(unsigned timeout = 1000000) + { + while (timeout > 0 && !_next) { - while (timeout > 0 && !_next) - { - _bus.process_discard(); - _bus.wait(50000); - timeout -= 50000; - } - return std::move(_next); + _bus.process_discard(); + _bus.wait(50000); + timeout -= 50000; } + return std::move(_next); + } - private: - static int callback(sd_bus_message* m, void* context, sd_bus_error*) - { - auto* me = static_cast<SignalQueue*>(context); - sd_bus_message_ref(m); - sdbusplus::message::message msg{m}; - me->_next = std::move(msg); - return 0; - } + private: + static int callback(sd_bus_message* m, void* context, sd_bus_error*) + { + auto* me = static_cast<SignalQueue*>(context); + sd_bus_message_ref(m); + sdbusplus::message::message msg{m}; + me->_next = std::move(msg); + return 0; + } - sdbusplus::bus::bus _bus; - sdbusplus::bus::match_t _match; - sdbusplus::message::message _next; + sdbusplus::bus::bus _bus; + sdbusplus::bus::match_t _match; + sdbusplus::message::message _next; }; /**@brief Find a subset of interfaces and properties in an object. */ auto hasProperties(const Object& l, const Object& r) { Object result; - std::set_difference( - r.cbegin(), - r.cend(), - l.cbegin(), - l.cend(), - std::inserter(result, result.end())); + std::set_difference(r.cbegin(), r.cend(), l.cbegin(), l.cend(), + std::inserter(result, result.end())); return result.empty(); } @@ -160,20 +153,10 @@ auto hasProperties(const Object& l, const Object& r) auto hasInterfaces(const std::vector<std::string>& l, const Object& r) { std::vector<std::string> stripped, interfaces; - std::transform( - r.cbegin(), - r.cend(), - std::back_inserter(stripped), - [](auto & p) - { - return p.first; - }); - std::set_difference( - stripped.cbegin(), - stripped.cend(), - l.cbegin(), - l.cend(), - std::back_inserter(interfaces)); + std::transform(r.cbegin(), r.cend(), std::back_inserter(stripped), + [](auto& p) { return p.first; }); + std::set_difference(stripped.cbegin(), stripped.cend(), l.cbegin(), + l.cend(), std::back_inserter(interfaces)); return interfaces.empty(); } @@ -182,35 +165,21 @@ void runTests() const std::string exampleRoot{EXAMPLE_ROOT}; auto b = sdbusplus::bus::new_default(); - auto notify = [&]() - { - return b.new_method_call( - MGR_SERVICE, - MGR_ROOT, - MGR_INTERFACE, - "Notify"); + auto notify = [&]() { + return b.new_method_call(MGR_SERVICE, MGR_ROOT, MGR_INTERFACE, + "Notify"); }; - auto set = [&](const std::string & path) - { - return b.new_method_call( - EXAMPLE_SERVICE, - path.c_str(), - "org.freedesktop.DBus.Properties", - "Set"); + auto set = [&](const std::string& path) { + return b.new_method_call(EXAMPLE_SERVICE, path.c_str(), + "org.freedesktop.DBus.Properties", "Set"); }; - Object obj - { - { - "xyz.openbmc_project.Example.Iface1", - {{"ExampleProperty1", "test1"s}} - }, - { - "xyz.openbmc_project.Example.Iface2", - { {"ExampleProperty2", "test2"s}, - {"ExampleProperty3", static_cast<int64_t>(0ll)} - } - }, + Object obj{ + {"xyz.openbmc_project.Example.Iface1", + {{"ExampleProperty1", "test1"s}}}, + {"xyz.openbmc_project.Example.Iface2", + {{"ExampleProperty2", "test2"s}, + {"ExampleProperty3", static_cast<int64_t>(0ll)}}}, }; // Validate startup events occurred. @@ -218,11 +187,9 @@ void runTests() sdbusplus::message::object_path relCreateMe3{"/createme3"}; std::string createMe3{root + relCreateMe3.str}; - auto get = b.new_method_call( - MGR_SERVICE, - createMe3.c_str(), - "org.freedesktop.DBus.Properties", - "GetAll"); + auto get = + b.new_method_call(MGR_SERVICE, createMe3.c_str(), + "org.freedesktop.DBus.Properties", "GetAll"); get.append("xyz.openbmc_project.Example.Iface1"); auto resp = b.call(get); @@ -236,8 +203,7 @@ void runTests() sdbusplus::message::object_path relPath{"/foo"}; std::string path(root + relPath.str); - SignalQueue queue( - "path='" + root + "',member='InterfacesAdded'"); + SignalQueue queue("path='" + root + "',member='InterfacesAdded'"); auto m = notify(); m.append(ObjectMap({{relPath, obj}})); @@ -256,282 +222,260 @@ void runTests() } // Validate the propertyIs filter. - { - // Create an object to be deleted. - { - auto m = notify(); - m.append(ObjectMap({{relDeleteMeThree, obj}})); - b.call(m); - } + {// Create an object to be deleted. + {auto m = notify(); + m.append(ObjectMap({{relDeleteMeThree, obj}})); + b.call(m); +} - // Validate that the action does not run if the property doesn't match. - { - SignalQueue queue( - "path='" + root + "',member='InterfacesRemoved'"); - auto m = set(trigger4.str); - m.append("xyz.openbmc_project.Example.Iface2"); - m.append("ExampleProperty2"); - m.append(sdbusplus::message::variant<std::string>("123")); - b.call(m); - auto sig{queue.pop()}; - assert(!sig); - } +// Validate that the action does not run if the property doesn't match. +{ + SignalQueue queue("path='" + root + "',member='InterfacesRemoved'"); + auto m = set(trigger4.str); + m.append("xyz.openbmc_project.Example.Iface2"); + m.append("ExampleProperty2"); + m.append(sdbusplus::message::variant<std::string>("123")); + b.call(m); + auto sig{queue.pop()}; + assert(!sig); +} - // Validate that the action does run if the property matches. - { - // Set ExampleProperty2 to something else to the 123 filter - // matches. - SignalQueue queue( - "path='" + root + "',member='InterfacesRemoved'"); - auto m = set(trigger4.str); - m.append("xyz.openbmc_project.Example.Iface2"); - m.append("ExampleProperty2"); - m.append(sdbusplus::message::variant<std::string>("xyz")); - b.call(m); - auto sig{queue.pop()}; - assert(!sig); - } - { - // Set ExampleProperty3 to 99. - SignalQueue queue( - "path='" + root + "',member='InterfacesRemoved'"); - auto m = set(trigger4.str); - m.append("xyz.openbmc_project.Example.Iface2"); - m.append("ExampleProperty3"); - m.append(sdbusplus::message::variant<int64_t>(99)); - b.call(m); - auto sig{queue.pop()}; - assert(!sig); - } - { - SignalQueue queue( - "path='" + root + "',member='InterfacesRemoved'"); - auto m = set(trigger4.str); - m.append("xyz.openbmc_project.Example.Iface2"); - m.append("ExampleProperty2"); - m.append(sdbusplus::message::variant<std::string>("123")); - b.call(m); - - sdbusplus::message::object_path sigpath; - std::vector<std::string> interfaces; - { - std::vector<std::string> interfaces; - auto sig{queue.pop()}; - assert(static_cast<bool>(sig)); - sig.read(sigpath); - assert(sigpath == deleteMeThree); - sig.read(interfaces); - std::sort(interfaces.begin(), interfaces.end()); - assert(hasInterfaces(interfaces, obj)); - } - } +// Validate that the action does run if the property matches. +{ + // Set ExampleProperty2 to something else to the 123 filter + // matches. + SignalQueue queue("path='" + root + "',member='InterfacesRemoved'"); + auto m = set(trigger4.str); + m.append("xyz.openbmc_project.Example.Iface2"); + m.append("ExampleProperty2"); + m.append(sdbusplus::message::variant<std::string>("xyz")); + b.call(m); + auto sig{queue.pop()}; + assert(!sig); +} +{ + // Set ExampleProperty3 to 99. + SignalQueue queue("path='" + root + "',member='InterfacesRemoved'"); + auto m = set(trigger4.str); + m.append("xyz.openbmc_project.Example.Iface2"); + m.append("ExampleProperty3"); + m.append(sdbusplus::message::variant<int64_t>(99)); + b.call(m); + auto sig{queue.pop()}; + assert(!sig); +} +{ + SignalQueue queue("path='" + root + "',member='InterfacesRemoved'"); + auto m = set(trigger4.str); + m.append("xyz.openbmc_project.Example.Iface2"); + m.append("ExampleProperty2"); + m.append(sdbusplus::message::variant<std::string>("123")); + b.call(m); + + sdbusplus::message::object_path sigpath; + std::vector<std::string> interfaces; + { + std::vector<std::string> interfaces; + auto sig{queue.pop()}; + assert(static_cast<bool>(sig)); + sig.read(sigpath); + assert(sigpath == deleteMeThree); + sig.read(interfaces); + std::sort(interfaces.begin(), interfaces.end()); + assert(hasInterfaces(interfaces, obj)); } +} +} - // Make sure DBus signals are handled. - { - // Create some objects to be deleted by an action. - { - auto m = notify(); - m.append(ObjectMap({{relDeleteMeOne, obj}})); - b.call(m); - } - { - auto m = notify(); - m.append(ObjectMap({{relDeleteMeTwo, obj}})); - b.call(m); - } - { - auto m = notify(); - m.append(ObjectMap({{relDeleteMeThree, obj}})); - b.call(m); - } +// Make sure DBus signals are handled. +{// Create some objects to be deleted by an action. + {auto m = notify(); +m.append(ObjectMap({{relDeleteMeOne, obj}})); +b.call(m); +} +{ + auto m = notify(); + m.append(ObjectMap({{relDeleteMeTwo, obj}})); + b.call(m); +} +{ + auto m = notify(); + m.append(ObjectMap({{relDeleteMeThree, obj}})); + b.call(m); +} - // Set some properties that should not trigger due to a filter. - { - SignalQueue queue( - "path='" + root + "',member='InterfacesRemoved'"); - auto m = set(trigger1.str); - m.append("xyz.openbmc_project.Example.Iface2"); - m.append("ExampleProperty2"); - m.append(sdbusplus::message::variant<std::string>("abc123")); - b.call(m); - auto sig{queue.pop()}; - assert(!sig); - } - { - SignalQueue queue( - "path='" + root + "',member='InterfacesRemoved'"); - auto m = set(trigger3.str); - m.append("xyz.openbmc_project.Example.Iface2"); - m.append("ExampleProperty3"); - m.append(sdbusplus::message::variant<int64_t>(11)); - b.call(m); - auto sig{queue.pop()}; - assert(!sig); - } +// Set some properties that should not trigger due to a filter. +{ + SignalQueue queue("path='" + root + "',member='InterfacesRemoved'"); + auto m = set(trigger1.str); + m.append("xyz.openbmc_project.Example.Iface2"); + m.append("ExampleProperty2"); + m.append(sdbusplus::message::variant<std::string>("abc123")); + b.call(m); + auto sig{queue.pop()}; + assert(!sig); +} +{ + SignalQueue queue("path='" + root + "',member='InterfacesRemoved'"); + auto m = set(trigger3.str); + m.append("xyz.openbmc_project.Example.Iface2"); + m.append("ExampleProperty3"); + m.append(sdbusplus::message::variant<int64_t>(11)); + b.call(m); + auto sig{queue.pop()}; + assert(!sig); +} - // Set some properties that should trigger. - { - SignalQueue queue( - "path='" + root + "',member='InterfacesRemoved'"); +// Set some properties that should trigger. +{ + SignalQueue queue("path='" + root + "',member='InterfacesRemoved'"); - auto m = set(trigger1.str); - m.append("xyz.openbmc_project.Example.Iface2"); - m.append("ExampleProperty2"); - m.append(sdbusplus::message::variant<std::string>("xxxyyy")); - b.call(m); + auto m = set(trigger1.str); + m.append("xyz.openbmc_project.Example.Iface2"); + m.append("ExampleProperty2"); + m.append(sdbusplus::message::variant<std::string>("xxxyyy")); + b.call(m); - sdbusplus::message::object_path sigpath; - std::vector<std::string> interfaces; - { - std::vector<std::string> interfaces; - auto sig{queue.pop()}; - assert(static_cast<bool>(sig)); - sig.read(sigpath); - assert(sigpath == deleteMeOne); - sig.read(interfaces); - std::sort(interfaces.begin(), interfaces.end()); - assert(hasInterfaces(interfaces, obj)); - } - { - std::vector<std::string> interfaces; - auto sig{queue.pop()}; - assert(static_cast<bool>(sig)); - sig.read(sigpath); - assert(sigpath == deleteMeTwo); - sig.read(interfaces); - std::sort(interfaces.begin(), interfaces.end()); - assert(hasInterfaces(interfaces, obj)); - } - { - // Make sure there were only two signals. - auto sig{queue.pop()}; - assert(!sig); - } - } - { - SignalQueue queue( - "path='" + root + "',member='InterfacesRemoved'"); + sdbusplus::message::object_path sigpath; + std::vector<std::string> interfaces; + { + std::vector<std::string> interfaces; + auto sig{queue.pop()}; + assert(static_cast<bool>(sig)); + sig.read(sigpath); + assert(sigpath == deleteMeOne); + sig.read(interfaces); + std::sort(interfaces.begin(), interfaces.end()); + assert(hasInterfaces(interfaces, obj)); + } + { + std::vector<std::string> interfaces; + auto sig{queue.pop()}; + assert(static_cast<bool>(sig)); + sig.read(sigpath); + assert(sigpath == deleteMeTwo); + sig.read(interfaces); + std::sort(interfaces.begin(), interfaces.end()); + assert(hasInterfaces(interfaces, obj)); + } + { + // Make sure there were only two signals. + auto sig{queue.pop()}; + assert(!sig); + } +} +{ + SignalQueue queue("path='" + root + "',member='InterfacesRemoved'"); - auto m = set(trigger3.str); - m.append("xyz.openbmc_project.Example.Iface2"); - m.append("ExampleProperty3"); - m.append(sdbusplus::message::variant<int64_t>(10)); - b.call(m); + auto m = set(trigger3.str); + m.append("xyz.openbmc_project.Example.Iface2"); + m.append("ExampleProperty3"); + m.append(sdbusplus::message::variant<int64_t>(10)); + b.call(m); - sdbusplus::message::object_path sigpath; - std::vector<std::string> interfaces; - { - std::vector<std::string> interfaces; - auto sig{queue.pop()}; - assert(static_cast<bool>(sig)); - sig.read(sigpath); - assert(sigpath == deleteMeThree); - sig.read(interfaces); - std::sort(interfaces.begin(), interfaces.end()); - assert(hasInterfaces(interfaces, obj)); - } - { - // Make sure there was only one signal. - auto sig{queue.pop()}; - assert(!sig); - } - } + sdbusplus::message::object_path sigpath; + std::vector<std::string> interfaces; + { + std::vector<std::string> interfaces; + auto sig{queue.pop()}; + assert(static_cast<bool>(sig)); + sig.read(sigpath); + assert(sigpath == deleteMeThree); + sig.read(interfaces); + std::sort(interfaces.begin(), interfaces.end()); + assert(hasInterfaces(interfaces, obj)); + } + { + // Make sure there was only one signal. + auto sig{queue.pop()}; + assert(!sig); } +} +} + +// Validate the set property action. +{ + sdbusplus::message::object_path relChangeMe{"/changeme"}; + std::string changeMe{root + relChangeMe.str}; - // Validate the set property action. + // Create an object to be updated by the set property action. { - sdbusplus::message::object_path relChangeMe{"/changeme"}; - std::string changeMe{root + relChangeMe.str}; + auto m = notify(); + m.append(ObjectMap({{relChangeMe, obj}})); + b.call(m); + } - // Create an object to be updated by the set property action. - { - auto m = notify(); - m.append(ObjectMap({{relChangeMe, obj}})); - b.call(m); - } + // Trigger and validate the change. + { + SignalQueue queue("path='" + changeMe + "',member='PropertiesChanged'"); + auto m = set(trigger2.str); + m.append("xyz.openbmc_project.Example.Iface2"); + m.append("ExampleProperty2"); + m.append(sdbusplus::message::variant<std::string>("yyyxxx")); + b.call(m); - // Trigger and validate the change. + std::string sigInterface; + std::map<std::string, sdbusplus::message::variant<std::string>> + sigProperties; { - SignalQueue queue( - "path='" + changeMe + "',member='PropertiesChanged'"); - auto m = set(trigger2.str); - m.append("xyz.openbmc_project.Example.Iface2"); - m.append("ExampleProperty2"); - m.append(sdbusplus::message::variant<std::string>("yyyxxx")); - b.call(m); - - std::string sigInterface; - std::map < - std::string, - sdbusplus::message::variant<std::string >> sigProperties; - { - std::vector<std::string> interfaces; - auto sig{queue.pop()}; - sig.read(sigInterface); - assert(sigInterface == "xyz.openbmc_project.Example.Iface1"); - sig.read(sigProperties); - assert(sigProperties["ExampleProperty1"] == "changed"); - } + std::vector<std::string> interfaces; + auto sig{queue.pop()}; + sig.read(sigInterface); + assert(sigInterface == "xyz.openbmc_project.Example.Iface1"); + sig.read(sigProperties); + assert(sigProperties["ExampleProperty1"] == "changed"); } } +} + +// Validate the create object action. +{ + sdbusplus::message::object_path relCreateMe1{"/createme1"}; + sdbusplus::message::object_path relCreateMe2{"/createme2"}; + std::string createMe1{root + relCreateMe1.str}; + std::string createMe2{root + relCreateMe2.str}; - // Validate the create object action. + // Trigger the action. { - sdbusplus::message::object_path relCreateMe1{"/createme1"}; - sdbusplus::message::object_path relCreateMe2{"/createme2"}; - std::string createMe1{root + relCreateMe1.str}; - std::string createMe2{root + relCreateMe2.str}; + sdbusplus::message::object_path signalPath; + Object signalObject; + + SignalQueue queue("path='" + root + "',member='InterfacesAdded'"); - // Trigger the action. + auto m = set(trigger5.str); + m.append("xyz.openbmc_project.Example.Iface2"); + m.append("ExampleProperty2"); + m.append(sdbusplus::message::variant<std::string>("abc123")); + b.call(m); + { + auto sig{queue.pop()}; + assert(static_cast<bool>(sig)); + sig.read(signalPath); + assert(createMe1 == signalPath.str); + sig.read(signalObject); + } { - sdbusplus::message::object_path signalPath; - Object signalObject; - - SignalQueue queue( - "path='" + root + "',member='InterfacesAdded'"); - - auto m = set(trigger5.str); - m.append("xyz.openbmc_project.Example.Iface2"); - m.append("ExampleProperty2"); - m.append(sdbusplus::message::variant<std::string>("abc123")); - b.call(m); - { - auto sig{queue.pop()}; - assert(static_cast<bool>(sig)); - sig.read(signalPath); - assert(createMe1 == signalPath.str); - sig.read(signalObject); - } - { - auto sig{queue.pop()}; - assert(static_cast<bool>(sig)); - sig.read(signalPath); - assert(createMe2 == signalPath.str); - sig.read(signalObject); - } - - auto moreSignals{queue.pop()}; - assert(!moreSignals); + auto sig{queue.pop()}; + assert(static_cast<bool>(sig)); + sig.read(signalPath); + assert(createMe2 == signalPath.str); + sig.read(signalObject); } + + auto moreSignals{queue.pop()}; + assert(!moreSignals); } } +} int main() { phosphor::inventory::manager::Manager mgr( - sdbusplus::bus::new_default(), - MGR_SERVICE, MGR_ROOT, MGR_INTERFACE); + sdbusplus::bus::new_default(), MGR_SERVICE, MGR_ROOT, MGR_INTERFACE); ExampleService d; - auto f1 = [](auto mgr) - { - mgr->run(); - }; - auto f2 = [](auto d) - { - d->run(); - }; + auto f1 = [](auto mgr) { mgr->run(); }; + auto f2 = [](auto d) { d->run(); }; auto t1 = std::thread(f1, &mgr); auto t2 = std::thread(f2, &d); @@ -20,8 +20,7 @@ namespace any_ns = std::experimental; using InterfaceVariantType = sdbusplus::message::variant<bool, int64_t, std::string>; -template <typename T> -using InterfaceType = std::map<std::string, T>; +template <typename T> using InterfaceType = std::map<std::string, T>; template <typename T> using ObjectType = std::map<std::string, InterfaceType<T>>; @@ -29,11 +28,11 @@ using ObjectType = std::map<std::string, InterfaceType<T>>; using Interface = InterfaceType<InterfaceVariantType>; using Object = ObjectType<InterfaceVariantType>; -using Action = std::function<void (sdbusplus::bus::bus&, Manager&)>; -using Filter = std::function < - bool (sdbusplus::bus::bus&, sdbusplus::message::message&, Manager&) >; -using PathCondition = std::function < - bool (const std::string&, sdbusplus::bus::bus&, Manager&) >; +using Action = std::function<void(sdbusplus::bus::bus&, Manager&)>; +using Filter = std::function<bool(sdbusplus::bus::bus&, + sdbusplus::message::message&, Manager&)>; +using PathCondition = + std::function<bool(const std::string&, sdbusplus::bus::bus&, Manager&)>; } // namespace manager } // namespace inventory } // namespace phosphor @@ -11,8 +11,7 @@ namespace manager * * @tparam V - The desired variant type. */ -template <typename V> -struct MakeVariantVisitor +template <typename V> struct MakeVariantVisitor { /** @struct Make * @brief Return variant visitor. @@ -21,8 +20,7 @@ struct MakeVariantVisitor * @tparam Arg - The type being visited in the source variant. * @tparam Enable - Overload resolution removal. */ - template <typename T, typename Arg, typename Enable = void> - struct Make + template <typename T, typename Arg, typename Enable = void> struct Make { static auto make(Arg&& arg) { @@ -38,8 +36,9 @@ struct MakeVariantVisitor * struct Make specialization if Arg is in T (int -> variant<int, char>). */ template <typename T, typename Arg> - struct Make<T, Arg, - typename std::enable_if<std::is_convertible<Arg, T>::value>::type> + struct Make< + T, Arg, + typename std::enable_if<std::is_convertible<Arg, T>::value>::type> { static auto make(Arg&& arg) { @@ -48,8 +47,7 @@ struct MakeVariantVisitor }; /** @brief Make variant visitor. */ - template <typename Arg> - auto operator()(Arg&& arg) const + template <typename Arg> auto operator()(Arg&& arg) const { return Make<V, Arg>::make(arg); } @@ -63,11 +61,10 @@ struct MakeVariantVisitor * @param[in] v - The source variant. * @returns - The converted variant. */ -template <typename V, typename Arg> -auto convertVariant(Arg&& v) +template <typename V, typename Arg> auto convertVariant(Arg&& v) { return sdbusplus::message::variant_ns::apply_visitor( - MakeVariantVisitor<V>(), v); + MakeVariantVisitor<V>(), v); } /** @struct CompareFirst @@ -78,14 +75,15 @@ auto convertVariant(Arg&& v) * * @tparam Compare - The function object type being adapted. */ -template <typename Compare> -struct CompareFirst +template <typename Compare> struct CompareFirst { /** @brief Construct a CompareFirst adapter. * * @param[in] c - The function object being adapted. */ - explicit CompareFirst(Compare&& c) : compare(std::forward<Compare>(c)) {} + explicit CompareFirst(Compare&& c) : compare(std::forward<Compare>(c)) + { + } /** @brief Compare two pairs adapter. * @@ -100,7 +98,8 @@ struct CompareFirst * @returns - The result of the comparison. */ template <typename L1, typename L2, typename R1, typename R2> - bool operator()(const std::pair<L1, L2>& l, const std::pair<R1, R2>& r) const + bool operator()(const std::pair<L1, L2>& l, + const std::pair<R1, R2>& r) const { return compare(l.first, r.first); } @@ -144,8 +143,7 @@ struct CompareFirst }; /* @brief Implicit template instantation wrapper for CompareFirst. */ -template <typename Compare> -CompareFirst<Compare> compareFirst(Compare&& c) +template <typename Compare> CompareFirst<Compare> compareFirst(Compare&& c) { return CompareFirst<Compare>(std::forward<Compare>(c)); } @@ -159,7 +157,9 @@ struct RelPathCompare * * @param[in] p - The prefix to check for and remove. */ - explicit RelPathCompare(const char* p) : prefix(p) {} + explicit RelPathCompare(const char* p) : prefix(p) + { + } /** @brief Check for the prefix and remove if found. * |