From d1eac88d18ae7dd11033dba87b6aebb220da9064 Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Thu, 29 Mar 2018 10:34:05 -0400 Subject: Enable clang-format Fix up errors and enable clang-format during CI builds. Change-Id: I4176b81f8b85a287af9354165e09ff66aeb9fb29 Signed-off-by: Brad Bishop --- src/callback.hpp | 309 +++++++++--------- src/count.hpp | 127 ++++---- src/data_types.hpp | 38 +-- src/elog.cpp | 1 - src/elog.hpp | 196 ++++++------ src/event.hpp | 178 +++++------ src/event_entry.hpp | 66 ++-- src/event_manager.cpp | 29 +- src/event_manager.hpp | 61 ++-- src/format.hpp | 1 - src/journal.cpp | 6 +- src/journal.hpp | 94 +++--- src/method.hpp | 137 ++++---- src/propertywatch.hpp | 270 ++++++++-------- src/propertywatchimpl.hpp | 55 ++-- src/resolve_errors.cpp | 43 +-- src/resolve_errors.hpp | 78 +++-- src/sdbusplus.hpp | 172 +++++----- src/sdevent.hpp | 95 +++--- src/sdevent/event.hpp | 137 ++++---- src/sdevent/source.hpp | 145 ++++----- src/sdevent/timer.hpp | 184 +++++------ src/test/callbackgentest.cpp | 18 +- src/test/callbackgroupgentest.cpp | 14 +- src/test/conditiongentest.cpp | 20 +- src/test/pathgentest.cpp | 95 +++--- src/test/propertygentest.cpp | 65 ++-- src/test/propertywatchgentest.cpp | 80 +++-- src/test/propertywatchtest.cpp | 134 +++----- src/test/propertywatchtest.hpp | 637 +++++++++++++------------------------- src/tupleref.hpp | 17 +- src/watch.hpp | 23 +- 32 files changed, 1542 insertions(+), 1983 deletions(-) (limited to 'src') diff --git a/src/callback.hpp b/src/callback.hpp index d476d97..26cd2a1 100644 --- a/src/callback.hpp +++ b/src/callback.hpp @@ -17,22 +17,22 @@ namespace monitoring */ class Callback { - public: - Callback() = default; - Callback(const Callback&) = delete; - Callback(Callback&&) = default; - Callback& operator=(const Callback&) = delete; - Callback& operator=(Callback&&) = default; - virtual ~Callback() = default; - - /** @brief Run the callback. - * @param[in] ctx - caller context - * Context could be Startup or Signal - * Startup: Callback is called as part of process startup. - * Signal: Callback is called as part of watch condition has been met. - * - */ - virtual void operator()(Context ctx) = 0; + public: + Callback() = default; + Callback(const Callback&) = delete; + Callback(Callback&&) = default; + Callback& operator=(const Callback&) = delete; + Callback& operator=(Callback&&) = default; + virtual ~Callback() = default; + + /** @brief Run the callback. + * @param[in] ctx - caller context + * Context could be Startup or Signal + * Startup: Callback is called as part of process startup. + * Signal: Callback is called as part of watch condition has been met. + * + */ + virtual void operator()(Context ctx) = 0; }; /** @class Conditional @@ -42,16 +42,16 @@ class Callback */ class Conditional { - public: - Conditional() = default; - Conditional(const Conditional&) = delete; - Conditional(Conditional&&) = default; - Conditional& operator=(const Conditional&) = delete; - Conditional& operator=(Conditional&&) = default; - virtual ~Conditional() = default; - - /** @brief Test the condition. */ - virtual bool operator()() = 0; + public: + Conditional() = default; + Conditional(const Conditional&) = delete; + Conditional(Conditional&&) = default; + Conditional& operator=(const Conditional&) = delete; + Conditional& operator=(Conditional&&) = default; + virtual ~Conditional() = default; + + /** @brief Test the condition. */ + virtual bool operator()() = 0; }; /** @class IndexedConditional @@ -59,24 +59,25 @@ class Conditional */ class IndexedConditional : public Conditional { - public: - IndexedConditional() = delete; - IndexedConditional(const IndexedConditional&) = delete; - IndexedConditional(IndexedConditional&&) = default; - IndexedConditional& operator=(const IndexedConditional&) = delete; - IndexedConditional& operator=(IndexedConditional&&) = default; - virtual ~IndexedConditional() = default; - - explicit IndexedConditional(const PropertyIndex& conditionIndex) - : Conditional(), index(conditionIndex) {} - - /** @brief Test the condition. */ - virtual bool operator()() override = 0; - - protected: - - /** @brief Property names and their associated storage. */ - const PropertyIndex& index; + public: + IndexedConditional() = delete; + IndexedConditional(const IndexedConditional&) = delete; + IndexedConditional(IndexedConditional&&) = default; + IndexedConditional& operator=(const IndexedConditional&) = delete; + IndexedConditional& operator=(IndexedConditional&&) = default; + virtual ~IndexedConditional() = default; + + explicit IndexedConditional(const PropertyIndex& conditionIndex) : + Conditional(), index(conditionIndex) + { + } + + /** @brief Test the condition. */ + virtual bool operator()() override = 0; + + protected: + /** @brief Property names and their associated storage. */ + const PropertyIndex& index; }; /** @class IndexedCallback @@ -84,23 +85,24 @@ class IndexedConditional : public Conditional */ class IndexedCallback : public Callback { - public: - IndexedCallback() = delete; - IndexedCallback(const IndexedCallback&) = delete; - IndexedCallback(IndexedCallback&&) = default; - IndexedCallback& operator=(const IndexedCallback&) = delete; - IndexedCallback& operator=(IndexedCallback&&) = default; - virtual ~IndexedCallback() = default; - explicit IndexedCallback(const PropertyIndex& callbackIndex) - : Callback(), index(callbackIndex) {} - - /** @brief Run the callback. */ - virtual void operator()(Context ctx) override = 0; - - protected: - - /** @brief Property names and their associated storage. */ - const PropertyIndex& index; + public: + IndexedCallback() = delete; + IndexedCallback(const IndexedCallback&) = delete; + IndexedCallback(IndexedCallback&&) = default; + IndexedCallback& operator=(const IndexedCallback&) = delete; + IndexedCallback& operator=(IndexedCallback&&) = default; + virtual ~IndexedCallback() = default; + explicit IndexedCallback(const PropertyIndex& callbackIndex) : + Callback(), index(callbackIndex) + { + } + + /** @brief Run the callback. */ + virtual void operator()(Context ctx) override = 0; + + protected: + /** @brief Property names and their associated storage. */ + const PropertyIndex& index; }; /** @class GroupOfCallbacks @@ -113,67 +115,68 @@ class IndexedCallback : public Callback * * @tparam CallbackAccess - Access to the array of callbacks. */ -template -class GroupOfCallbacks : public Callback +template class GroupOfCallbacks : public Callback { - public: - GroupOfCallbacks() = delete; - GroupOfCallbacks(const GroupOfCallbacks&) = delete; - GroupOfCallbacks(GroupOfCallbacks&&) = default; - GroupOfCallbacks& operator=(const GroupOfCallbacks&) = delete; - GroupOfCallbacks& operator=(GroupOfCallbacks&&) = default; - ~GroupOfCallbacks() = default; - explicit GroupOfCallbacks( - const std::vector& graphEntry) - : graph(graphEntry) {} - - /** @brief Run the callbacks. */ - void operator()(Context ctx) override + public: + GroupOfCallbacks() = delete; + GroupOfCallbacks(const GroupOfCallbacks&) = delete; + GroupOfCallbacks(GroupOfCallbacks&&) = default; + GroupOfCallbacks& operator=(const GroupOfCallbacks&) = delete; + GroupOfCallbacks& operator=(GroupOfCallbacks&&) = default; + ~GroupOfCallbacks() = default; + explicit GroupOfCallbacks(const std::vector& graphEntry) : + graph(graphEntry) + { + } + + /** @brief Run the callbacks. */ + void operator()(Context ctx) override + { + for (auto e : graph) { - for (auto e : graph) - { - (*CallbackAccess::get()[e])(ctx); - } + (*CallbackAccess::get()[e])(ctx); } + } - private: - /** @brief The offsets of the callbacks in the group. */ - const std::vector& graph; + private: + /** @brief The offsets of the callbacks in the group. */ + const std::vector& graph; }; /** @class ConditionalCallback * @brief Callback adaptor that asssociates a condition with a callback. */ -template -class ConditionalCallback: public Callback +template class ConditionalCallback : public Callback { - public: - ConditionalCallback() = delete; - ConditionalCallback(const ConditionalCallback&) = delete; - ConditionalCallback(ConditionalCallback&&) = default; - ConditionalCallback& operator=(const ConditionalCallback&) = delete; - ConditionalCallback& operator=(ConditionalCallback&&) = default; - virtual ~ConditionalCallback() = default; - ConditionalCallback( - const std::vector& graphEntry, - Conditional& cond) - : graph(graphEntry), condition(cond) {} - - /** @brief Run the callback if the condition is satisfied. */ - virtual void operator()(Context ctx) override + public: + ConditionalCallback() = delete; + ConditionalCallback(const ConditionalCallback&) = delete; + ConditionalCallback(ConditionalCallback&&) = default; + ConditionalCallback& operator=(const ConditionalCallback&) = delete; + ConditionalCallback& operator=(ConditionalCallback&&) = default; + virtual ~ConditionalCallback() = default; + ConditionalCallback(const std::vector& graphEntry, + Conditional& cond) : + graph(graphEntry), + condition(cond) + { + } + + /** @brief Run the callback if the condition is satisfied. */ + virtual void operator()(Context ctx) override + { + if (condition()) { - if (condition()) - { - (*CallbackAccess::get()[graph[0]])(ctx); - } + (*CallbackAccess::get()[graph[0]])(ctx); } + } - protected: - /** @brief The index of the callback to conditionally invoke. */ - const std::vector& graph; + protected: + /** @brief The index of the callback to conditionally invoke. */ + const std::vector& graph; - /** @brief The condition to test. */ - Conditional& condition; + /** @brief The condition to test. */ + Conditional& condition; }; /** @class DeferrableCallback @@ -192,59 +195,57 @@ class ConditionalCallback: public Callback template class DeferrableCallback : public ConditionalCallback { - public: - DeferrableCallback() = delete; - DeferrableCallback(const DeferrableCallback&) = delete; - DeferrableCallback(DeferrableCallback&&) = default; - DeferrableCallback& operator=(const DeferrableCallback&) = delete; - DeferrableCallback& operator=(DeferrableCallback&&) = default; - ~DeferrableCallback() = default; - - DeferrableCallback( - const std::vector& graphEntry, - Conditional& cond, - const std::chrono::microseconds& delay) - : ConditionalCallback(graphEntry, cond), - delayInterval(delay), - timer(nullptr) {} - - void operator()(Context ctx) override + public: + DeferrableCallback() = delete; + DeferrableCallback(const DeferrableCallback&) = delete; + DeferrableCallback(DeferrableCallback&&) = default; + DeferrableCallback& operator=(const DeferrableCallback&) = delete; + DeferrableCallback& operator=(DeferrableCallback&&) = default; + ~DeferrableCallback() = default; + + DeferrableCallback(const std::vector& graphEntry, Conditional& cond, + const std::chrono::microseconds& delay) : + ConditionalCallback(graphEntry, cond), + delayInterval(delay), timer(nullptr) + { + } + + void operator()(Context ctx) override + { + if (!timer) { - if (!timer) - { - timer = std::make_unique( -// **INDENT-OFF** - [ctx, this](auto & source) - { - this->ConditionalCallback::operator()(ctx); - }); -// **INDENT-ON** - timer->disable(); - } + timer = std::make_unique( + // **INDENT-OFF** + [ctx, this](auto& source) { + this->ConditionalCallback::operator()(ctx); + }); + // **INDENT-ON** + timer->disable(); + } - if (this->condition()) - { - if (!timer->enabled()) - { - // This is the first time the condition evaluated. - // Start the countdown. - timer->update(timer->now() + delayInterval); - timer->enable(); - } - } - else + if (this->condition()) + { + if (!timer->enabled()) { - // The condition did not evaluate. Stop the countdown. - timer->disable(); + // This is the first time the condition evaluated. + // Start the countdown. + timer->update(timer->now() + delayInterval); + timer->enable(); } } + else + { + // The condition did not evaluate. Stop the countdown. + timer->disable(); + } + } - private: - /** @brief The length to wait for the condition to stop evaluating. */ - std::chrono::microseconds delayInterval; + private: + /** @brief The length to wait for the condition to stop evaluating. */ + std::chrono::microseconds delayInterval; - /** @brief Delegated timer functions. */ - std::unique_ptr timer; + /** @brief Delegated timer functions. */ + std::unique_ptr timer; }; } // namespace monitoring diff --git a/src/count.hpp b/src/count.hpp index 9f0ce3e..af3998a 100644 --- a/src/count.hpp +++ b/src/count.hpp @@ -31,82 +31,77 @@ namespace monitoring * If the oneshot parameter is true, then this condition won't pass * again until it fails at least once. */ -template -class CountCondition : public IndexedConditional +template class CountCondition : public IndexedConditional { - public: - CountCondition() = delete; - CountCondition(const CountCondition&) = default; - CountCondition(CountCondition&&) = default; - CountCondition& operator=(const CountCondition&) = default; - CountCondition& operator=(CountCondition&&) = default; - ~CountCondition() = default; + public: + CountCondition() = delete; + CountCondition(const CountCondition&) = default; + CountCondition(CountCondition&&) = default; + CountCondition& operator=(const CountCondition&) = default; + CountCondition& operator=(CountCondition&&) = default; + ~CountCondition() = default; - CountCondition( - const PropertyIndex& conditionIndex, - const std::function& _countOp, - const std::function& _propertyOp, - bool oneshot = false) : - IndexedConditional(conditionIndex), - countOp(_countOp), - propertyOp(_propertyOp), - oneshot(oneshot) {} + CountCondition(const PropertyIndex& conditionIndex, + const std::function& _countOp, + const std::function& _propertyOp, + bool oneshot = false) : + IndexedConditional(conditionIndex), + countOp(_countOp), propertyOp(_propertyOp), oneshot(oneshot) + { + } - bool operator()() override - { - // Count the number of properties in the index that - // pass the condition specified in the config file. - auto count = std::count_if( - index.cbegin(), - index.cend(), - [this](const auto & item) + bool operator()() override + { + // Count the number of properties in the index that + // pass the condition specified in the config file. + auto count = std::count_if( + index.cbegin(), index.cend(), + [this](const auto& item) // *INDENT-OFF* - { - //Get the property value from storage[0], - //and save the op result in storage[1]. - const auto& storage = std::get( - item.second); - // Don't count properties that don't exist. - if (std::get( - storage.get()).empty()) - { - return false; - } - const auto& value = any_ns::any_cast( - std::get(storage.get())); - auto r = propertyOp(value); - - std::get(storage.get()) = r; + { + // Get the property value from storage[0], + // and save the op result in storage[1]. + const auto& storage = std::get(item.second); + // Don't count properties that don't exist. + if (std::get(storage.get()).empty()) + { + return false; + } + const auto& value = + any_ns::any_cast(std::get(storage.get())); + auto r = propertyOp(value); - return r; - }); - // *INDENT-ON* + std::get(storage.get()) = r; - // Now apply the count condition to the count. - auto result = countOp(count); + return r; + }); + // *INDENT-ON* - // If this was a oneshot and the the condition has already - // passed, then don't let it pass again until the condition - // has gone back to false. - if (oneshot && result && lastResult) - { - return false; - } + // Now apply the count condition to the count. + auto result = countOp(count); - lastResult = result; - return result; + // If this was a oneshot and the the condition has already + // passed, then don't let it pass again until the condition + // has gone back to false. + if (oneshot && result && lastResult) + { + return false; } - private: - /** @brief The comparison to perform on the count. */ - std::function countOp; - /** @brief The comparison to perform on each property. */ - std::function propertyOp; - /** @brief If the condition can be allowed to pass again - on subsequent checks that are also true. */ - const bool oneshot; - /** @brief The result of the previous check. */ - bool lastResult = false; + lastResult = result; + return result; + } + + private: + /** @brief The comparison to perform on the count. */ + std::function countOp; + /** @brief The comparison to perform on each property. */ + std::function propertyOp; + /** @brief If the condition can be allowed to pass again + on subsequent checks that are also true. */ + const bool oneshot; + /** @brief The result of the previous check. */ + bool lastResult = false; }; } // namespace monitoring } // namespace dbus diff --git a/src/data_types.hpp b/src/data_types.hpp index 607289a..6be6431 100644 --- a/src/data_types.hpp +++ b/src/data_types.hpp @@ -17,17 +17,17 @@ constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; -//PropertyIndex::key_type fields +// PropertyIndex::key_type fields constexpr auto pathIndex = 0; constexpr auto interfaceIndex = 1; constexpr auto propertyIndex = 2; -//PropertyIndex::mapped_type fields +// PropertyIndex::mapped_type fields constexpr auto pathMetaIndex = 0; constexpr auto propertyMetaIndex = 1; constexpr auto storageIndex = 2; -//ConfigPropertyStorage fields +// ConfigPropertyStorage fields constexpr auto valueIndex = 0; constexpr auto resultIndex = 1; @@ -42,12 +42,11 @@ template using RefKeyMap = std::map, Value, std::less>; /** @brief A map with a tuple of references as keys. */ -template +template using TupleRefMap = std::map, Value, TupleOfRefsLess>; /** @brief A vector of references. */ -template -using RefVector = std::vector>; +template using RefVector = std::vector>; /** @brief * @@ -59,31 +58,23 @@ using MapperPath = std::string; /** @brief ObjectManager.InterfacesAdded signal signature alias. */ template -using InterfacesAdded = std::map < - std::string, - std::map < - std::string, - sdbusplus::message::variant>>; +using InterfacesAdded = + std::map>>; /** @brief ObjectMapper.GetObject response signature alias. */ using GetObject = std::map>; /** @brief Properties.GetAll response signature alias. */ template -using PropertiesChanged = std::map < - std::string, - sdbusplus::message::variant>; +using PropertiesChanged = std::map>; /** @brief Lookup index for properties . */ // *INDENT-OFF* -using PropertyIndex = TupleRefMap < - TupleOfRefs< - const std::string, - const std::string, - std::tuple>, - const std::string, - const std::string, - const std::string >; +using PropertyIndex = + TupleRefMap>, + const std::string, const std::string, const std::string>; // *INDENT-ON* /** @brief Convert some C++ types to others. @@ -97,8 +88,7 @@ template struct Downcast { using Type = std::remove_cv_t>; }; -template using DowncastType = - typename Downcast::Type; +template using DowncastType = typename Downcast::Type; } // namespace monitoring } // namespace dbus diff --git a/src/elog.cpp b/src/elog.cpp index 116691e..9cd18c8 100644 --- a/src/elog.cpp +++ b/src/elog.cpp @@ -27,7 +27,6 @@ void ElogBase::operator()(Context ctx) log(); } - } // namespace monitoring } // namespace dbus } // namespace phosphor diff --git a/src/elog.hpp b/src/elog.hpp index 234ef6f..996fd58 100644 --- a/src/elog.hpp +++ b/src/elog.hpp @@ -39,21 +39,22 @@ template <> struct ToString */ class ElogBase : public Callback { - public: - ElogBase(const ElogBase&) = delete; - ElogBase(ElogBase&&) = default; - ElogBase& operator=(const ElogBase&) = delete; - ElogBase& operator=(ElogBase&&) = default; - virtual ~ElogBase() = default; - ElogBase() : - Callback() {} - - /** @brief Callback interface implementation. */ - void operator()(Context ctx) override; - - private: - /** @brief Delegate type specific calls to subclasses. */ - virtual void log() const = 0; + public: + ElogBase(const ElogBase&) = delete; + ElogBase(ElogBase&&) = default; + ElogBase& operator=(const ElogBase&) = delete; + ElogBase& operator=(ElogBase&&) = default; + virtual ~ElogBase() = default; + ElogBase() : Callback() + { + } + + /** @brief Callback interface implementation. */ + void operator()(Context ctx) override; + + private: + /** @brief Delegate type specific calls to subclasses. */ + virtual void log() const = 0; }; namespace detail @@ -65,10 +66,9 @@ namespace detail * @tparam T - Error log type * @tparam Args - Metadata fields types. */ -template -struct CallElog +template struct CallElog { - static void op(Args&& ...args) + static void op(Args&&... args) { phosphor::logging::report(std::forward(args)...); } @@ -84,31 +84,29 @@ struct CallElog * @tparam Args - Metadata fields types. * @param[in] arguments - Metadata fields to be added to the error log */ -template -class Elog : public ElogBase +template class Elog : public ElogBase { - public: - Elog(const Elog&) = delete; - Elog(Elog&&) = default; - Elog& operator=(const Elog&) = delete; - Elog& operator=(Elog&&) = default; - ~Elog() = default; - Elog(Args&& ... arguments) : - ElogBase(), args(std::forward(arguments)...) {} - - private: - /** @brief elog interface implementation. */ - void log() const override - { - std::experimental::apply( - detail::CallElog::op, - std::tuple_cat(args)); - } - std::tuple args; + public: + Elog(const Elog&) = delete; + Elog(Elog&&) = default; + Elog& operator=(const Elog&) = delete; + Elog& operator=(Elog&&) = default; + ~Elog() = default; + Elog(Args&&... arguments) : + ElogBase(), args(std::forward(arguments)...) + { + } + private: + /** @brief elog interface implementation. */ + void log() const override + { + std::experimental::apply(detail::CallElog::op, + std::tuple_cat(args)); + } + std::tuple args; }; - /** * @class ElogWithMetadataCapture * @@ -135,75 +133,69 @@ class Elog : public ElogBase * @tparam metadataType - The metadata to use * @tparam propertyType - The data type of the captured properties */ -template +template class ElogWithMetadataCapture : public IndexedCallback { - public: - ElogWithMetadataCapture() = delete; - ElogWithMetadataCapture(const ElogWithMetadataCapture&) = delete; - ElogWithMetadataCapture(ElogWithMetadataCapture&&) = default; - ElogWithMetadataCapture& operator=( - const ElogWithMetadataCapture&) = delete; - ElogWithMetadataCapture& operator=( - ElogWithMetadataCapture&&) = default; - virtual ~ElogWithMetadataCapture() = default; - explicit ElogWithMetadataCapture( - const PropertyIndex& index) : - IndexedCallback(index) {} - - /** - * @brief Callback interface implementation that - * creates an error log - */ - void operator()(Context ctx) override - { - auto data = captureMetadata(); + public: + ElogWithMetadataCapture() = delete; + ElogWithMetadataCapture(const ElogWithMetadataCapture&) = delete; + ElogWithMetadataCapture(ElogWithMetadataCapture&&) = default; + ElogWithMetadataCapture& operator=(const ElogWithMetadataCapture&) = delete; + ElogWithMetadataCapture& operator=(ElogWithMetadataCapture&&) = default; + virtual ~ElogWithMetadataCapture() = default; + explicit ElogWithMetadataCapture(const PropertyIndex& index) : + IndexedCallback(index) + { + } - phosphor::logging::report( - metadataType(data.c_str())); - } + /** + * @brief Callback interface implementation that + * creates an error log + */ + void operator()(Context ctx) override + { + auto data = captureMetadata(); - private: - - /** - * @brief Builds a metadata string with property information - * - * Finds all of the properties in the index that have - * their condition pass/fail fields (get(storage)) - * set to true, and then packs those paths, names, and values - * into a metadata string that looks like: - * - * |path1:name1=value1|path2:name2=value2|... - * - * @return The metadata string - */ - std::string captureMetadata() + phosphor::logging::report(metadataType(data.c_str())); + } + + private: + /** + * @brief Builds a metadata string with property information + * + * Finds all of the properties in the index that have + * their condition pass/fail fields (get(storage)) + * set to true, and then packs those paths, names, and values + * into a metadata string that looks like: + * + * |path1:name1=value1|path2:name2=value2|... + * + * @return The metadata string + */ + std::string captureMetadata() + { + std::string metadata{'|'}; + + for (const auto& n : index) { - std::string metadata{'|'}; + const auto& storage = std::get(n.second).get(); + const auto& result = std::get(storage); - for (const auto& n : index) + if (!result.empty() && any_ns::any_cast(result)) { - const auto& storage = std::get(n.second).get(); - const auto& result = std::get(storage); - - if (!result.empty() && any_ns::any_cast(result)) - { - const auto& path = std::get(n.first).get(); - const auto& propertyName = std::get( - n.first).get(); - auto value = ToString::op( - any_ns::any_cast( - std::get(storage))); - - metadata += path + ":" + propertyName + - '=' + value + '|'; - } + const auto& path = std::get(n.first).get(); + const auto& propertyName = + std::get(n.first).get(); + auto value = + ToString::op(any_ns::any_cast( + std::get(storage))); + + metadata += path + ":" + propertyName + '=' + value + '|'; } + } - return metadata; - }; + return metadata; + }; }; /** @brief Argument type deduction for constructing Elog instances. @@ -212,11 +204,9 @@ class ElogWithMetadataCapture : public IndexedCallback * @tparam Args - Metadata fields types. * @param[in] arguments - Metadata fields to be added to the error log */ -template -auto makeElog(Args&& ... arguments) +template auto makeElog(Args&&... arguments) { - return std::make_unique>( - std::forward(arguments)...); + return std::make_unique>(std::forward(arguments)...); } } // namespace monitoring diff --git a/src/event.hpp b/src/event.hpp index b9f5167..a2a2236 100644 --- a/src/event.hpp +++ b/src/event.hpp @@ -22,60 +22,53 @@ namespace monitoring */ class EventBase : public IndexedCallback { - public: - EventBase() = delete; - EventBase(const EventBase&) = delete; - EventBase(EventBase&&) = default; - EventBase& operator=(const EventBase&) = delete; - EventBase& operator=(EventBase&&) = default; - virtual ~EventBase() = default; - EventBase(const PropertyIndex& index) : - IndexedCallback(index) {} + public: + EventBase() = delete; + EventBase(const EventBase&) = delete; + EventBase(EventBase&&) = default; + EventBase& operator=(const EventBase&) = delete; + EventBase& operator=(EventBase&&) = default; + virtual ~EventBase() = default; + EventBase(const PropertyIndex& index) : IndexedCallback(index) + { + } + + /** @brief Callback interface implementation. */ + void operator()(Context ctx) override + { + if (ctx == Context::START) + { + // No action should be taken + // as this call back is being called from + // daemon Startup. + return; + } - /** @brief Callback interface implementation. */ - void operator()(Context ctx) override + for (const auto& n : index) { - if (ctx == Context::START) - { - // No action should be taken - // as this call back is being called from - // daemon Startup. - return; - } + const auto& path = std::get(n.first); + const auto& propertyMeta = std::get(n.first); + const auto& storage = std::get(n.second); + const auto& value = std::get(storage.get()); - for (const auto& n : index) + if (!value.empty()) { - const auto& path = std::get(n.first); - const auto& propertyMeta = std::get(n.first); - const auto& storage = std::get(n.second); - const auto& value = std::get(storage.get()); - - if (!value.empty()) - { - createEvent( - path, - propertyMeta, - value); - } + createEvent(path, propertyMeta, value); } - } - - private: - - /** @brief Create the event Dbus Object. - * @param[in] path - Dbus Object Path for which the - * property has changed. - * @param[in] property - Name of the property whose value - * has been changed. - * @param[in] value - Changed property value. - */ - virtual void createEvent( - const std::string& path, - const std::string& property, - const any_ns::any& value) const = 0; - - + } + + private: + /** @brief Create the event Dbus Object. + * @param[in] path - Dbus Object Path for which the + * property has changed. + * @param[in] property - Name of the property whose value + * has been changed. + * @param[in] value - Changed property value. + */ + virtual void createEvent(const std::string& path, + const std::string& property, + const any_ns::any& value) const = 0; }; /** @class Event @@ -83,53 +76,50 @@ class EventBase : public IndexedCallback * * @tparam T - The C++ type of the property values being traced. */ -template -class Event : public EventBase +template class Event : public EventBase { - public: - Event() = delete; - Event(const Event&) = delete; - Event(Event&&) = default; - Event& operator=(const Event&) = delete; - Event& operator=(Event&&) = default; - ~Event() = default; - - /** @brief Constructor. - * @param[in] eventName - Name of the event. - * @param[in] eventMessage- Event Message. - * @param[in] index - look up index for the properties. - */ - Event(std::string eventName, - std::string eventMessage, - const PropertyIndex& index) : - EventBase(index), - name(eventName), - message(eventMessage) {} - - private: - /** @brief Create the event Dbus Object. - * @param[in] path - Dbus Object Path for which the - * property has changed. - * @param[in] property - Name of the property whose value - * has been changed. - * @param[in] value - Changed property value. - */ - void createEvent( - const std::string& path, - const std::string& property, - const any_ns::any& value) const override - { - std::stringstream ss {}; - ss << any_ns::any_cast(value); - phosphor::events::getManager().create( - name, message, path, property, ss.str()); - } - - /** @brief Event Name */ - std::string name; - - /** @brief Event Message */ - std::string message; + public: + Event() = delete; + Event(const Event&) = delete; + Event(Event&&) = default; + Event& operator=(const Event&) = delete; + Event& operator=(Event&&) = default; + ~Event() = default; + + /** @brief Constructor. + * @param[in] eventName - Name of the event. + * @param[in] eventMessage- Event Message. + * @param[in] index - look up index for the properties. + */ + Event(std::string eventName, std::string eventMessage, + const PropertyIndex& index) : + EventBase(index), + name(eventName), message(eventMessage) + { + } + + private: + /** @brief Create the event Dbus Object. + * @param[in] path - Dbus Object Path for which the + * property has changed. + * @param[in] property - Name of the property whose value + * has been changed. + * @param[in] value - Changed property value. + */ + void createEvent(const std::string& path, const std::string& property, + const any_ns::any& value) const override + { + std::stringstream ss{}; + ss << any_ns::any_cast(value); + phosphor::events::getManager().create(name, message, path, property, + ss.str()); + } + + /** @brief Event Name */ + std::string name; + + /** @brief Event Message */ + std::string message; }; } // namespace monitoring diff --git a/src/event_entry.hpp b/src/event_entry.hpp index 7be66d9..e39f1e2 100644 --- a/src/event_entry.hpp +++ b/src/event_entry.hpp @@ -13,8 +13,8 @@ namespace events using namespace phosphor::dbus::monitoring; -using EntryIface = sdbusplus::server::object::object < - sdbusplus::xyz::openbmc_project::Logging::server::Event >; +using EntryIface = sdbusplus::server::object::object< + sdbusplus::xyz::openbmc_project::Logging::server::Event>; /** @class Entry * @brief OpenBMC Event entry implementation. @@ -23,39 +23,35 @@ using EntryIface = sdbusplus::server::object::object < */ class Entry : public EntryIface { - public: - Entry() = delete; - Entry(const Entry&) = delete; - Entry& operator=(const Entry&) = delete; - Entry(Entry&&) = delete; - Entry& operator=(Entry&&) = delete; - virtual ~Entry() = default; - - /** @brief Constructor to put object onto bus at a dbus path. - * @param[in] path - Path to attach at. - * @param[in] eventId - The event entry id. - * @param[in] timestamp - timestamp when the event created. - * @param[in] msg - The message of the event. - * @param[in] metaData - The event metadata. - */ - Entry( - const std::string& path, - uint64_t eventTimestamp, - std::string&& msg, - std::vector&& metaData) : - EntryIface(SDBusPlus::getBus(), path.c_str(), true), - objectPath(path) - { - timestamp(eventTimestamp); - message(msg); - additionalData(metaData); - // Emit deferred signal. - this->emit_object_added(); - } - - /** @brief Path of Object. */ - std::string objectPath; - + public: + Entry() = delete; + Entry(const Entry&) = delete; + Entry& operator=(const Entry&) = delete; + Entry(Entry&&) = delete; + Entry& operator=(Entry&&) = delete; + virtual ~Entry() = default; + + /** @brief Constructor to put object onto bus at a dbus path. + * @param[in] path - Path to attach at. + * @param[in] eventId - The event entry id. + * @param[in] timestamp - timestamp when the event created. + * @param[in] msg - The message of the event. + * @param[in] metaData - The event metadata. + */ + Entry(const std::string& path, uint64_t eventTimestamp, std::string&& msg, + std::vector&& metaData) : + EntryIface(SDBusPlus::getBus(), path.c_str(), true), + objectPath(path) + { + timestamp(eventTimestamp); + message(msg); + additionalData(metaData); + // Emit deferred signal. + this->emit_object_added(); + } + + /** @brief Path of Object. */ + std::string objectPath; }; } // namespace events diff --git a/src/event_manager.cpp b/src/event_manager.cpp index 2c09f35..6e7d302 100644 --- a/src/event_manager.cpp +++ b/src/event_manager.cpp @@ -25,12 +25,11 @@ namespace phosphor namespace events { -void Manager::create( - const std::string& eventName, - const std::string& eventMessage, - const std::string& objectPath, - const std::string& propertyName, - const std::string& propertyValue) +void Manager::create(const std::string& eventName, + const std::string& eventMessage, + const std::string& objectPath, + const std::string& propertyName, + const std::string& propertyValue) { using namespace std::string_literals; namespace fs = std::experimental::filesystem; @@ -53,14 +52,15 @@ void Manager::create( { fs::path path(eventQueue.back()->objectPath); id = std::stoi(std::string(path.filename().c_str())); - id ++; + id++; } auto ms = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); + std::chrono::system_clock::now().time_since_epoch()) + .count(); - auto objPath = std::string(OBJ_EVENT) + '/' + eventName + '/' + - std::to_string(id); + auto objPath = + std::string(OBJ_EVENT) + '/' + eventName + '/' + std::to_string(id); // check for capping of the events,if cap reached then erase the oldest // event. @@ -69,11 +69,10 @@ void Manager::create( eventQueue.pop(); } - eventQueue.emplace(std::make_unique( - objPath, - ms, // Milliseconds since 1970 - std::move(msg), - std::move(additionalData))); + eventQueue.emplace(std::make_unique(objPath, + ms, // Milliseconds since 1970 + std::move(msg), + std::move(additionalData))); } Manager& getManager() diff --git a/src/event_manager.hpp b/src/event_manager.hpp index 7184852..a177739 100644 --- a/src/event_manager.hpp +++ b/src/event_manager.hpp @@ -17,38 +17,35 @@ namespace events */ class Manager { - public: - Manager() = default; - Manager(const Manager&) = delete; - Manager& operator=(const Manager&) = delete; - Manager(Manager&&) = default; - Manager& operator=(Manager&&) = default; - virtual ~Manager() = default; - - /** @brief Create the D-Bus Event object. - * @detail Add the objectPath,propertyName, propertyValue - * as additional data of the event object. - * @param[in] eventName - Name of the event. - * @param[in] eventMessage - Message for the event. - * @param[in] objectPath - Path of the D-Bus object. - * @param[in] propertyName - Name of the property. - * @param[in] propertyValue - Value of the property. - */ - void create( - const std::string& eventName, - const std::string& eventMessage, - const std::string& objectPath, - const std::string& propertyName, - const std::string& propertyValue); - - private: - using EventName = std::string; - /** @brief Queue of events */ - using EventQueue = std::queue>; - - using EventMap = std::map; - /** @brief Map of event name and the list of events **/ - EventMap eventMap; + public: + Manager() = default; + Manager(const Manager&) = delete; + Manager& operator=(const Manager&) = delete; + Manager(Manager&&) = default; + Manager& operator=(Manager&&) = default; + virtual ~Manager() = default; + + /** @brief Create the D-Bus Event object. + * @detail Add the objectPath,propertyName, propertyValue + * as additional data of the event object. + * @param[in] eventName - Name of the event. + * @param[in] eventMessage - Message for the event. + * @param[in] objectPath - Path of the D-Bus object. + * @param[in] propertyName - Name of the property. + * @param[in] propertyValue - Value of the property. + */ + void create(const std::string& eventName, const std::string& eventMessage, + const std::string& objectPath, const std::string& propertyName, + const std::string& propertyValue); + + private: + using EventName = std::string; + /** @brief Queue of events */ + using EventQueue = std::queue>; + + using EventMap = std::map; + /** @brief Map of event name and the list of events **/ + EventMap eventMap; }; Manager& getManager(); diff --git a/src/format.hpp b/src/format.hpp index f0b0c8e..f622f2e 100644 --- a/src/format.hpp +++ b/src/format.hpp @@ -14,7 +14,6 @@ namespace detail /** @brief Map format strings to undecorated C++ types. */ template struct GetFormatType { - }; template <> struct GetFormatType { diff --git a/src/journal.cpp b/src/journal.cpp index f54c5b3..41d51e4 100644 --- a/src/journal.cpp +++ b/src/journal.cpp @@ -34,11 +34,7 @@ void JournalBase::operator()(Context ctx) if (!value.empty()) { - log(message, - pathMeta, - path, - propertyMeta, - value); + log(message, pathMeta, path, propertyMeta, value); } } } diff --git a/src/journal.hpp b/src/journal.hpp index d9209af..249a7a2 100644 --- a/src/journal.hpp +++ b/src/journal.hpp @@ -20,30 +20,29 @@ namespace monitoring */ class JournalBase : public IndexedCallback { - public: - JournalBase() = delete; - JournalBase(const JournalBase&) = delete; - JournalBase(JournalBase&&) = default; - JournalBase& operator=(const JournalBase&) = delete; - JournalBase& operator=(JournalBase&&) = default; - virtual ~JournalBase() = default; - JournalBase(const char* msg, const PropertyIndex& index) : - IndexedCallback(index), message(msg) {} + public: + JournalBase() = delete; + JournalBase(const JournalBase&) = delete; + JournalBase(JournalBase&&) = default; + JournalBase& operator=(const JournalBase&) = delete; + JournalBase& operator=(JournalBase&&) = default; + virtual ~JournalBase() = default; + JournalBase(const char* msg, const PropertyIndex& index) : + IndexedCallback(index), message(msg) + { + } - /** @brief Callback interface implementation. */ - void operator()(Context ctx) override; + /** @brief Callback interface implementation. */ + void operator()(Context ctx) override; - private: - /** @brief Delegate type specific calls to subclasses. */ - virtual void log( - const char* message, - const std::string& pathMeta, - const std::string& path, - const std::string& propertyMeta, - const any_ns::any& value) const = 0; + private: + /** @brief Delegate type specific calls to subclasses. */ + virtual void log(const char* message, const std::string& pathMeta, + const std::string& path, const std::string& propertyMeta, + const any_ns::any& value) const = 0; - /** @brief The client provided message to be traced. */ - const char* message; + /** @brief The client provided message to be traced. */ + const char* message; }; /** @struct Display @@ -77,34 +76,33 @@ template <> struct Display template class Journal : public JournalBase { - public: - Journal() = delete; - Journal(const Journal&) = delete; - Journal(Journal&&) = default; - Journal& operator=(const Journal&) = delete; - Journal& operator=(Journal&&) = default; - ~Journal() = default; - Journal(const char* msg, const PropertyIndex& index) : - JournalBase(msg, index) {} + public: + Journal() = delete; + Journal(const Journal&) = delete; + Journal(Journal&&) = default; + Journal& operator=(const Journal&) = delete; + Journal& operator=(Journal&&) = default; + ~Journal() = default; + Journal(const char* msg, const PropertyIndex& index) : + JournalBase(msg, index) + { + } - private: - /** @brief log interface implementation. */ - void log( - const char* message, - const std::string& pathMeta, - const std::string& path, - const std::string& propertyMeta, - const any_ns::any& value) const override - { - phosphor::logging::log( - message, - phosphor::logging::entry( - (pathMeta + GetFormat::format).c_str(), - path.c_str()), - phosphor::logging::entry( - (propertyMeta + GetFormat::format).c_str(), - detail::Display::op(any_ns::any_cast(value)))); - } + private: + /** @brief log interface implementation. */ + void log(const char* message, const std::string& pathMeta, + const std::string& path, const std::string& propertyMeta, + const any_ns::any& value) const override + { + phosphor::logging::log( + message, + phosphor::logging::entry( + (pathMeta + GetFormat::format).c_str(), + path.c_str()), + phosphor::logging::entry( + (propertyMeta + GetFormat::format).c_str(), + detail::Display::op(any_ns::any_cast(value)))); + } }; } // namespace monitoring diff --git a/src/method.hpp b/src/method.hpp index 9475fb8..7c29205 100644 --- a/src/method.hpp +++ b/src/method.hpp @@ -19,22 +19,14 @@ namespace detail * @tparam DBusInterface - The DBus interface to use. * @tparam MethodArgs - DBus method argument types. */ -template -struct CallDBusMethod +template struct CallDBusMethod { - static void op( - const std::string& bus, - const std::string& path, - const std::string& iface, - const std::string& method, - MethodArgs&& ...args) + static void op(const std::string& bus, const std::string& path, + const std::string& iface, const std::string& method, + MethodArgs&&... args) { - DBusInterface::callMethodNoReply( - bus, - path, - iface, - method, - std::forward(args)...); + DBusInterface::callMethodNoReply(bus, path, iface, method, + std::forward(args)...); } }; } // namespace detail @@ -46,32 +38,28 @@ struct CallDBusMethod */ class MethodBase : public Callback { - public: - MethodBase() = delete; - MethodBase(const MethodBase&) = delete; - MethodBase(MethodBase&&) = default; - MethodBase& operator=(const MethodBase&) = delete; - MethodBase& operator=(MethodBase&&) = default; - virtual ~MethodBase() = default; - MethodBase( - const std::string& b, - const std::string& p, - const std::string& i, - const std::string& m) - : Callback(), - bus(b), - path(p), - interface(i), - method(m) {} + public: + MethodBase() = delete; + MethodBase(const MethodBase&) = delete; + MethodBase(MethodBase&&) = default; + MethodBase& operator=(const MethodBase&) = delete; + MethodBase& operator=(MethodBase&&) = default; + virtual ~MethodBase() = default; + MethodBase(const std::string& b, const std::string& p, const std::string& i, + const std::string& m) : + Callback(), + bus(b), path(p), interface(i), method(m) + { + } - /** @brief Callback interface implementation. */ - void operator()(Context ctx) override = 0; + /** @brief Callback interface implementation. */ + void operator()(Context ctx) override = 0; - protected: - const std::string& bus; - const std::string& path; - const std::string& interface; - const std::string& method; + protected: + const std::string& bus; + const std::string& path; + const std::string& interface; + const std::string& method; }; /** @class Method @@ -80,57 +68,46 @@ class MethodBase : public Callback * @tparam DBusInterface - The DBus interface to use to call the method. * @tparam MethodArgs - DBus method argument types. */ -template +template class Method : public MethodBase { - public: - Method() = delete; - Method(const Method&) = default; - Method(Method&&) = default; - Method& operator=(const Method&) = default; - Method& operator=(Method&&) = default; - ~Method() = default; - Method( - const std::string& bus, - const std::string& path, - const std::string& iface, - const std::string& method, - MethodArgs&& ... arguments) - : MethodBase(bus, path, iface, method), - args(std::forward(arguments)...) {} + public: + Method() = delete; + Method(const Method&) = default; + Method(Method&&) = default; + Method& operator=(const Method&) = default; + Method& operator=(Method&&) = default; + ~Method() = default; + Method(const std::string& bus, const std::string& path, + const std::string& iface, const std::string& method, + MethodArgs&&... arguments) : + MethodBase(bus, path, iface, method), + args(std::forward(arguments)...) + { + } - /** @brief Callback interface implementation. */ - void operator()(Context ctx) override - { - std::experimental::apply( - detail::CallDBusMethod::op, - std::tuple_cat( - std::make_tuple(bus), - std::make_tuple(path), - std::make_tuple(interface), - std::make_tuple(method), - args)); - } + /** @brief Callback interface implementation. */ + void operator()(Context ctx) override + { + std::experimental::apply( + detail::CallDBusMethod::op, + std::tuple_cat(std::make_tuple(bus), std::make_tuple(path), + std::make_tuple(interface), std::make_tuple(method), + args)); + } - private: - std::tuple args; + private: + std::tuple args; }; /** @brief Argument type deduction for constructing Method instances. */ -template -auto makeMethod( - const std::string& bus, - const std::string& path, - const std::string& iface, - const std::string& method, - MethodArgs&& ... arguments) +template +auto makeMethod(const std::string& bus, const std::string& path, + const std::string& iface, const std::string& method, + MethodArgs&&... arguments) { return std::make_unique>( - bus, - path, - iface, - method, - std::forward(arguments)...); + bus, path, iface, method, std::forward(arguments)...); } } // namespace monitoring diff --git a/src/propertywatch.hpp b/src/propertywatch.hpp index cd286a5..2cbf6f5 100644 --- a/src/propertywatch.hpp +++ b/src/propertywatch.hpp @@ -25,80 +25,78 @@ class Callback; * A property watch maintains the state of one or more DBus properties * as specified by the supplied index. */ -template -class PropertyWatch : public Watch +template class PropertyWatch : public Watch { - public: - PropertyWatch() = delete; - PropertyWatch(const PropertyWatch&) = delete; - PropertyWatch(PropertyWatch&&) = default; - PropertyWatch& operator=(const PropertyWatch&) = delete; - PropertyWatch& operator=(PropertyWatch&&) = default; - virtual ~PropertyWatch() = default; - PropertyWatch( - const PropertyIndex& watchIndex, - Callback* callback = nullptr) - : Watch(), index(watchIndex), cb(callback), alreadyRan(false) {} - - /** @brief Start the watch. - * - * Watch start interface implementation for PropertyWatch. - */ - void start() override; - - /** @brief Run the watch callback method. - * - * Watch callback interface implementation for PropertyWatch. - */ - void callback(Context ctx) override; - - /** @brief Update properties. - * - * Subclasses to query the properties specified by the index - * and update the cache. - * - * @param[in] busName - The busname hosting the interface to query. - * @param[in] path - The path of the interface to query. - * @param[in] interface - The interface to query. - */ - virtual void updateProperties( - const std::string& busName, - const std::string& path, - const std::string& interface) = 0; - - /** @brief Dbus signal callback for PropertiesChanged. - * - * Subclasses to update the cache. - * - * @param[in] message - The org.freedesktop.DBus.PropertiesChanged - * message. - * @param[in] path - The path associated with the message. - * @param[in] interface - The interface associated with the message. - */ - virtual void propertiesChanged( - sdbusplus::message::message&, - const std::string& path, - const std::string& interface) = 0; - - /** @brief Dbus signal callback for InterfacesAdded. - * - * Subclasses to update the cache. - * - * @param[in] msg - The org.freedesktop.DBus.PropertiesChanged - * message. - */ - virtual void interfacesAdded(sdbusplus::message::message& msg) = 0; - - protected: - - /** @brief Property names and their associated storage. */ - const PropertyIndex& index; - - /** @brief Optional callback method. */ - Callback* const cb; - - /** @brief The start method should only be invoked once. */ - bool alreadyRan; + public: + PropertyWatch() = delete; + PropertyWatch(const PropertyWatch&) = delete; + PropertyWatch(PropertyWatch&&) = default; + PropertyWatch& operator=(const PropertyWatch&) = delete; + PropertyWatch& operator=(PropertyWatch&&) = default; + virtual ~PropertyWatch() = default; + PropertyWatch(const PropertyIndex& watchIndex, + Callback* callback = nullptr) : + Watch(), + index(watchIndex), cb(callback), alreadyRan(false) + { + } + + /** @brief Start the watch. + * + * Watch start interface implementation for PropertyWatch. + */ + void start() override; + + /** @brief Run the watch callback method. + * + * Watch callback interface implementation for PropertyWatch. + */ + void callback(Context ctx) override; + + /** @brief Update properties. + * + * Subclasses to query the properties specified by the index + * and update the cache. + * + * @param[in] busName - The busname hosting the interface to query. + * @param[in] path - The path of the interface to query. + * @param[in] interface - The interface to query. + */ + virtual void updateProperties(const std::string& busName, + const std::string& path, + const std::string& interface) = 0; + + /** @brief Dbus signal callback for PropertiesChanged. + * + * Subclasses to update the cache. + * + * @param[in] message - The org.freedesktop.DBus.PropertiesChanged + * message. + * @param[in] path - The path associated with the message. + * @param[in] interface - The interface associated with the message. + */ + virtual void propertiesChanged(sdbusplus::message::message&, + const std::string& path, + const std::string& interface) = 0; + + /** @brief Dbus signal callback for InterfacesAdded. + * + * Subclasses to update the cache. + * + * @param[in] msg - The org.freedesktop.DBus.PropertiesChanged + * message. + */ + virtual void interfacesAdded(sdbusplus::message::message& msg) = 0; + + protected: + /** @brief Property names and their associated storage. */ + const PropertyIndex& index; + + /** @brief Optional callback method. */ + Callback* const cb; + + /** @brief The start method should only be invoked once. */ + bool alreadyRan; }; /** @class PropertyWatchOfType @@ -110,71 +108,67 @@ class PropertyWatch : public Watch template class PropertyWatchOfType : public PropertyWatch { - public: - PropertyWatchOfType() = default; - PropertyWatchOfType(const PropertyWatchOfType&) = delete; - PropertyWatchOfType(PropertyWatchOfType&&) = default; - PropertyWatchOfType& operator=(const PropertyWatchOfType&) = delete; - PropertyWatchOfType& operator=(PropertyWatchOfType&&) = default; - ~PropertyWatchOfType() = default; - PropertyWatchOfType( - const PropertyIndex& watchIndex, Callback& callback) : - PropertyWatch(watchIndex, &callback) {} - PropertyWatchOfType( - const PropertyIndex& watchIndex) : - PropertyWatch(watchIndex, nullptr) {} - - - /** @brief PropertyMatch implementation for PropertyWatchOfType. - * - * @param[in] busName - The busname hosting the interface to query. - * @param[in] path - The path of the interface to query. - * @param[in] interface - The interface to query. - */ - void updateProperties( - const std::string& busName, - const std::string& path, - const std::string& interface) override; - - /** @brief PropertyMatch implementation for PropertyWatchOfType. - * - * @param[in] msg - The org.freedesktop.DBus.PropertiesChanged - * message. - * @param[in] path - The path associated with the message. - * @param[in] interface - The interface associated with the message. - */ - void propertiesChanged( - sdbusplus::message::message& msg, - const std::string& path, - const std::string& interface) override; - - /** @brief DBus agnostic implementation of interfacesAdded. - * - * @param[in] path - The path of the properties that changed. - * @param[in] interface - The interface of the properties that - * changed. - * @param[in] properites - The properties that changed. - */ - void propertiesChanged( - const std::string& path, - const std::string& interface, - const PropertiesChanged& properties); - - /** @brief PropertyMatch implementation for PropertyWatchOfType. - * - * @param[in] msg - The org.freedesktop.DBus.PropertiesChanged - * message. - */ - void interfacesAdded(sdbusplus::message::message& msg) override; - - /** @brief DBus agnostic implementation of interfacesAdded. - * - * @param[in] path - The path of the added interfaces. - * @param[in] interfaces - The added interfaces. - */ - void interfacesAdded( - const std::string& path, - const InterfacesAdded& interfaces); + public: + PropertyWatchOfType() = default; + PropertyWatchOfType(const PropertyWatchOfType&) = delete; + PropertyWatchOfType(PropertyWatchOfType&&) = default; + PropertyWatchOfType& operator=(const PropertyWatchOfType&) = delete; + PropertyWatchOfType& operator=(PropertyWatchOfType&&) = default; + ~PropertyWatchOfType() = default; + PropertyWatchOfType(const PropertyIndex& watchIndex, Callback& callback) : + PropertyWatch(watchIndex, &callback) + { + } + PropertyWatchOfType(const PropertyIndex& watchIndex) : + PropertyWatch(watchIndex, nullptr) + { + } + + /** @brief PropertyMatch implementation for PropertyWatchOfType. + * + * @param[in] busName - The busname hosting the interface to query. + * @param[in] path - The path of the interface to query. + * @param[in] interface - The interface to query. + */ + void updateProperties(const std::string& busName, const std::string& path, + const std::string& interface) override; + + /** @brief PropertyMatch implementation for PropertyWatchOfType. + * + * @param[in] msg - The org.freedesktop.DBus.PropertiesChanged + * message. + * @param[in] path - The path associated with the message. + * @param[in] interface - The interface associated with the message. + */ + void propertiesChanged(sdbusplus::message::message& msg, + const std::string& path, + const std::string& interface) override; + + /** @brief DBus agnostic implementation of interfacesAdded. + * + * @param[in] path - The path of the properties that changed. + * @param[in] interface - The interface of the properties that + * changed. + * @param[in] properites - The properties that changed. + */ + void propertiesChanged(const std::string& path, + const std::string& interface, + const PropertiesChanged& properties); + + /** @brief PropertyMatch implementation for PropertyWatchOfType. + * + * @param[in] msg - The org.freedesktop.DBus.PropertiesChanged + * message. + */ + void interfacesAdded(sdbusplus::message::message& msg) override; + + /** @brief DBus agnostic implementation of interfacesAdded. + * + * @param[in] path - The path of the added interfaces. + * @param[in] interfaces - The added interfaces. + */ + void interfacesAdded(const std::string& path, + const InterfacesAdded& interfaces); }; } // namespace monitoring diff --git a/src/propertywatchimpl.hpp b/src/propertywatchimpl.hpp index 1f0e4d1..003ee37 100644 --- a/src/propertywatchimpl.hpp +++ b/src/propertywatchimpl.hpp @@ -16,8 +16,7 @@ namespace monitoring using MappedPropertyIndex = RefKeyMap>>; + RefKeyMap>>; MappedPropertyIndex convert(const PropertyIndex& index); @@ -41,11 +40,9 @@ void PropertyWatch::start() // Watch for new interfaces on this path. DBusInterfaceType::addMatch( sdbusplus::bus::match::rules::interfacesAdded(path), - [this](auto & msg) - // *INDENT-OFF* - { - this->interfacesAdded(msg); - }); + [this](auto& msg) + // *INDENT-OFF* + { this->interfacesAdded(msg); }); // *INDENT-ON* // Do a query to populate the cache. Start with a mapper query. @@ -53,12 +50,8 @@ void PropertyWatch::start() const std::vector queryInterfaces; // all interfaces auto mapperResp = DBusInterfaceType::template callMethodAndRead( - MAPPER_BUSNAME, - MAPPER_PATH, - MAPPER_INTERFACE, - "GetObject", - path, - queryInterfaces); + MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, "GetObject", + path, queryInterfaces); for (const auto& i : interfaces) { @@ -66,9 +59,9 @@ void PropertyWatch::start() // Watch for property changes on this interface. DBusInterfaceType::addMatch( - sdbusplus::bus::match::rules::propertiesChanged( - path, interface), - [this](auto & msg) + sdbusplus::bus::match::rules::propertiesChanged(path, + interface), + [this](auto& msg) // *INDENT-OFF* { std::string interface; @@ -76,7 +69,7 @@ void PropertyWatch::start() auto path = msg.get_path(); this->propertiesChanged(msg, path, interface); }); - // *INDENT-ON* + // *INDENT-ON* // The mapper response is a busname:[interfaces] map. Look for // each interface in the index and if found, query the service and @@ -85,10 +78,9 @@ void PropertyWatch::start() { const auto& busName = mr.first; const auto& mapperInterfaces = mr.second; - if (mapperInterfaces.end() == std::find( - mapperInterfaces.begin(), - mapperInterfaces.end(), - interface)) + if (mapperInterfaces.end() == + std::find(mapperInterfaces.begin(), mapperInterfaces.end(), + interface)) { // This interface isn't being watched. continue; @@ -115,24 +107,19 @@ void PropertyWatch::callback(Context ctx) template void PropertyWatchOfType::updateProperties( - const std::string& busName, - const std::string& path, + const std::string& busName, const std::string& path, const std::string& interface) { auto properties = DBusInterfaceType::template callMethodAndRead>( - busName.c_str(), - path.c_str(), - "org.freedesktop.DBus.Properties", - "GetAll", - interface); + busName.c_str(), path.c_str(), "org.freedesktop.DBus.Properties", + "GetAll", interface); propertiesChanged(path, interface, properties); } template void PropertyWatchOfType::propertiesChanged( - const std::string& path, - const std::string& interface, + const std::string& path, const std::string& interface, const PropertiesChanged& properties) { // Update the cache for any watched properties. @@ -147,7 +134,7 @@ void PropertyWatchOfType::propertiesChanged( } std::get(std::get(item->second).get()) = - p.second.template get(); + p.second.template get(); // Invoke callback if present. this->callback(Context::SIGNAL); @@ -156,8 +143,7 @@ void PropertyWatchOfType::propertiesChanged( template void PropertyWatchOfType::propertiesChanged( - sdbusplus::message::message& msg, - const std::string& path, + sdbusplus::message::message& msg, const std::string& path, const std::string& interface) { PropertiesChanged properties; @@ -167,8 +153,7 @@ void PropertyWatchOfType::propertiesChanged( template void PropertyWatchOfType::interfacesAdded( - const std::string& path, - const InterfacesAdded& interfaces) + const std::string& path, const InterfacesAdded& interfaces) { for (const auto& i : interfaces) { diff --git a/src/resolve_errors.cpp b/src/resolve_errors.cpp index 54f0b78..47277eb 100644 --- a/src/resolve_errors.cpp +++ b/src/resolve_errors.cpp @@ -36,7 +36,7 @@ using EndpointsProperty = sdbusplus::message::variant; void ResolveCallout::operator()(Context ctx) { - //Resolve all errors for this callout: + // Resolve all errors for this callout: // 1) Read the 'endpoints' property for the callout/fault object // // 2) Follow each endpoint to its log entry @@ -50,21 +50,17 @@ void ResolveCallout::operator()(Context ctx) if (busName.empty()) { - //Just means there are no error logs with this callout + // Just means there are no error logs with this callout return; } auto endpoints = SDBusPlus::callMethodAndRead( - busName, - path, - PROPERTY_IFACE, - "Get", - ASSOCIATION_IFACE, - ENDPOINTS_PROPERTY); + busName, path, PROPERTY_IFACE, "Get", ASSOCIATION_IFACE, + ENDPOINTS_PROPERTY); const auto& logEntries = endpoints.get(); - //Resolve each log entry + // Resolve each log entry for (const auto& logEntry : logEntries) { resolve(logEntry); @@ -72,10 +68,9 @@ void ResolveCallout::operator()(Context ctx) } catch (const std::exception& e) { - log( - "Failed getting callout fault associations", - entry("CALLOUT=%s", callout.c_str()), - entry("MESSAGE=%s", e.what())); + log("Failed getting callout fault associations", + entry("CALLOUT=%s", callout.c_str()), + entry("MESSAGE=%s", e.what())); } } @@ -95,28 +90,22 @@ void ResolveCallout::resolve(const std::string& logEntry) sdbusplus::message::variant resolved = true; - auto response = SDBusPlus::callMethod( - busName, - logEntry, - PROPERTY_IFACE, - "Set", - LOGGING_IFACE, - RESOLVED_PROPERTY, - resolved); + auto response = + SDBusPlus::callMethod(busName, logEntry, PROPERTY_IFACE, "Set", + LOGGING_IFACE, RESOLVED_PROPERTY, resolved); if (response.is_method_error()) { log( - "Failed to set Resolved property on an error log entry", - entry("ENTRY=%s", logEntry.c_str())); + "Failed to set Resolved property on an error log entry", + entry("ENTRY=%s", logEntry.c_str())); } } catch (const std::exception& e) { - log( - "Unable to resolve error log entry", - entry("ENTRY=%s", logEntry.c_str()), - entry("MESSAGE=%s", e.what())); + log("Unable to resolve error log entry", + entry("ENTRY=%s", logEntry.c_str()), + entry("MESSAGE=%s", e.what())); } } diff --git a/src/resolve_errors.hpp b/src/resolve_errors.hpp index cae4bbc..c58dc7d 100644 --- a/src/resolve_errors.hpp +++ b/src/resolve_errors.hpp @@ -17,48 +17,46 @@ namespace monitoring */ class ResolveCallout : public Callback { - public: - - ResolveCallout() = delete; - ~ResolveCallout() = default; - ResolveCallout(const ResolveCallout&) = delete; - ResolveCallout& operator=(const ResolveCallout&) = delete; - ResolveCallout(ResolveCallout&&) = default; - ResolveCallout& operator=(ResolveCallout&&) = default; - - /** - * @brief constructor - * - * @param[in] callout - The callout whose errors need to be resolved. - * Normally an inventory path. - */ - explicit ResolveCallout(const std::string& callout) : - callout(callout) {} - - /** - * @brief Callback interface to resolve errors - * - * Resolves all error log entries that are associated - * with the callout. - */ - void operator()(Context ctx) override; - - private: - - /** - * @brief Resolves a single error log entry - * - * param[in] entry - the object path of the error log entry - */ - void resolve(const std::string& entry); - - /** - * @brief The object path of the callout, typically an inventory path - */ - std::string callout; + public: + ResolveCallout() = delete; + ~ResolveCallout() = default; + ResolveCallout(const ResolveCallout&) = delete; + ResolveCallout& operator=(const ResolveCallout&) = delete; + ResolveCallout(ResolveCallout&&) = default; + ResolveCallout& operator=(ResolveCallout&&) = default; + + /** + * @brief constructor + * + * @param[in] callout - The callout whose errors need to be resolved. + * Normally an inventory path. + */ + explicit ResolveCallout(const std::string& callout) : callout(callout) + { + } + + /** + * @brief Callback interface to resolve errors + * + * Resolves all error log entries that are associated + * with the callout. + */ + void operator()(Context ctx) override; + + private: + /** + * @brief Resolves a single error log entry + * + * param[in] entry - the object path of the error log entry + */ + void resolve(const std::string& entry); + + /** + * @brief The object path of the callout, typically an inventory path + */ + std::string callout; }; - } // namespace monitoring } // namespace dbus } // namespace phosphor diff --git a/src/sdbusplus.hpp b/src/sdbusplus.hpp index 1a2c9c2..1b54582 100644 --- a/src/sdbusplus.hpp +++ b/src/sdbusplus.hpp @@ -19,116 +19,90 @@ namespace monitoring */ class SDBusPlus { - private: - static auto& getWatches() - { - static std::vector watches; - return watches; - } + private: + static auto& getWatches() + { + static std::vector watches; + return watches; + } - public: - static auto& getBus() - { - static auto bus = sdbusplus::bus::new_default(); - return bus; - } + public: + static auto& getBus() + { + static auto bus = sdbusplus::bus::new_default(); + return bus; + } - /** @brief Invoke a method; ignore reply. */ - template - static void callMethodNoReply( - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - Args&& ... args) - { - auto reqMsg = getBus().new_method_call( - busName.c_str(), - path.c_str(), - interface.c_str(), - method.c_str()); - reqMsg.append(std::forward(args)...); - getBus().call_noreply(reqMsg); + /** @brief Invoke a method; ignore reply. */ + template + static void callMethodNoReply(const std::string& busName, + const std::string& path, + const std::string& interface, + const std::string& method, Args&&... args) + { + auto reqMsg = getBus().new_method_call( + busName.c_str(), path.c_str(), interface.c_str(), method.c_str()); + reqMsg.append(std::forward(args)...); + getBus().call_noreply(reqMsg); - // TODO: openbmc/openbmc#1719 - // invoke these methods async, with a callback - // handler that checks for errors and logs. - } + // TODO: openbmc/openbmc#1719 + // invoke these methods async, with a callback + // handler that checks for errors and logs. + } - /** @brief Invoke a method. */ - template - static auto callMethod( - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - Args&& ... args) - { - auto reqMsg = getBus().new_method_call( - busName.c_str(), - path.c_str(), - interface.c_str(), - method.c_str()); - reqMsg.append(std::forward(args)...); - return getBus().call(reqMsg); - } + /** @brief Invoke a method. */ + template + static auto callMethod(const std::string& busName, const std::string& path, + const std::string& interface, + const std::string& method, Args&&... args) + { + auto reqMsg = getBus().new_method_call( + busName.c_str(), path.c_str(), interface.c_str(), method.c_str()); + reqMsg.append(std::forward(args)...); + return getBus().call(reqMsg); + } - /** @brief Invoke a method and read the response. */ - template - static auto callMethodAndRead( - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - Args&& ... args) - { - Ret resp; - sdbusplus::message::message respMsg = - callMethod( - busName, - path, - interface, - method, - std::forward(args)...); - respMsg.read(resp); - return resp; - } + /** @brief Invoke a method and read the response. */ + template + static auto callMethodAndRead(const std::string& busName, + const std::string& path, + const std::string& interface, + const std::string& method, Args&&... args) + { + Ret resp; + sdbusplus::message::message respMsg = callMethod( + busName, path, interface, method, std::forward(args)...); + respMsg.read(resp); + return resp; + } - /** @brief Register a DBus signal callback. */ - static auto addMatch( - const std::string& match, - const sdbusplus::bus::match::match::callback_t& callback) - { - getWatches().emplace_back( - getBus(), - match, - callback); - } + /** @brief Register a DBus signal callback. */ + static auto + addMatch(const std::string& match, + const sdbusplus::bus::match::match::callback_t& callback) + { + getWatches().emplace_back(getBus(), match, callback); + } - /** @brief Look up the bus name for a path and interface */ - static auto getBusName( - const std::string& path, - const std::string& interface) - { - std::vector interfaces{interface}; + /** @brief Look up the bus name for a path and interface */ + static auto getBusName(const std::string& path, + const std::string& interface) + { + std::vector interfaces{interface}; - auto object = callMethodAndRead( - MAPPER_BUSNAME, - MAPPER_PATH, - MAPPER_INTERFACE, - "GetObject", - path, - interfaces); + auto object = callMethodAndRead( + MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, "GetObject", path, + interfaces); - std::string name; - if (!object.empty()) - { - name = object.begin()->first; - } - return name; + std::string name; + if (!object.empty()) + { + name = object.begin()->first; } + return name; + } - friend Loop; + friend Loop; }; } // namespace monitoring diff --git a/src/sdevent.hpp b/src/sdevent.hpp index dc912c1..4fed159 100644 --- a/src/sdevent.hpp +++ b/src/sdevent.hpp @@ -17,22 +17,22 @@ namespace monitoring */ class SDEvent { - protected: - /** @brief Share a single event loop amongst users. */ - static auto& getEvent() - { - static auto event = sdevent::event::newDefault(); - return event; - } + protected: + /** @brief Share a single event loop amongst users. */ + static auto& getEvent() + { + static auto event = sdevent::event::newDefault(); + return event; + } - public: - /** @brief Wrapper for sd_event_now. */ - static auto now() - { - return getEvent().now(); - } + public: + /** @brief Wrapper for sd_event_now. */ + static auto now() + { + return getEvent().now(); + } - friend Loop; + friend Loop; }; /** @class SDEventTimer @@ -40,45 +40,46 @@ class SDEvent */ class SDEventTimer : public SDEvent { - public: - SDEventTimer() = delete; - SDEventTimer(const SDEventTimer&) = default; - SDEventTimer(SDEventTimer&&) = default; - SDEventTimer& operator=(const SDEventTimer&) = default; - SDEventTimer& operator=(SDEventTimer&&) = default; - ~SDEventTimer() = default; + public: + SDEventTimer() = delete; + SDEventTimer(const SDEventTimer&) = default; + SDEventTimer(SDEventTimer&&) = default; + SDEventTimer& operator=(const SDEventTimer&) = default; + SDEventTimer& operator=(SDEventTimer&&) = default; + ~SDEventTimer() = default; - explicit SDEventTimer( - const sdevent::event::timer::Timer::Callback& callback) - : timer(getEvent(), callback) {} + explicit SDEventTimer( + const sdevent::event::timer::Timer::Callback& callback) : + timer(getEvent(), callback) + { + } - /** @brief Update a timer expiration. */ - void update( - const std::chrono::steady_clock::time_point& expires) - { - timer.setTime(expires); - } + /** @brief Update a timer expiration. */ + void update(const std::chrono::steady_clock::time_point& expires) + { + timer.setTime(expires); + } - /** @brief Query timer state. */ - auto enabled() - { - return timer.enabled() != SD_EVENT_OFF; - } + /** @brief Query timer state. */ + auto enabled() + { + return timer.enabled() != SD_EVENT_OFF; + } - /** @brief Enable a timer. */ - void enable() - { - timer.enable(SD_EVENT_ONESHOT); - } + /** @brief Enable a timer. */ + void enable() + { + timer.enable(SD_EVENT_ONESHOT); + } - /** @brief Disable a timer. */ - void disable() - { - timer.enable(SD_EVENT_OFF); - } + /** @brief Disable a timer. */ + void disable() + { + timer.enable(SD_EVENT_OFF); + } - private: - sdevent::event::timer::Timer timer; + private: + sdevent::event::timer::Timer timer; }; } // namespace monitoring diff --git a/src/sdevent/event.hpp b/src/sdevent/event.hpp index 5462202..f47c05d 100644 --- a/src/sdevent/event.hpp +++ b/src/sdevent/event.hpp @@ -49,84 +49,81 @@ using Event = std::unique_ptr; */ class Event { - public: - /* 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. - */ - Event() = delete; - Event(const Event&) = delete; - Event& operator=(const Event&) = delete; - Event(Event&&) = default; - Event& operator=(Event&&) = default; - ~Event() = default; - - /** @brief Conversion constructor from 'EventPtr'. - * - * Increments ref-count of the event-pointer and releases it when - * done. - */ - explicit Event(EventPtr e); - - /** @brief Constructor for 'Event'. - * - * Takes ownership of the event-pointer and releases it when done. - */ - Event(EventPtr e, std::false_type); - - /** @brief Release ownership of the stored event-pointer. */ - EventPtr release() - { - return evt.release(); - } - - /** @brief Wait indefinitely for new event sources. */ - void loop() - { - sd_event_loop(evt.get()); - } - - /** @brief Attach to a DBus loop. */ - void attach(sdbusplus::bus::bus& bus) - { - bus.attach_event(evt.get(), SD_EVENT_PRIORITY_NORMAL); - } - - /** @brief C++ wrapper for sd_event_now. */ - auto now() - { - using namespace std::chrono; - - uint64_t usec; - sd_event_now(evt.get(), CLOCK_MONOTONIC, &usec); - microseconds d(usec); - return steady_clock::time_point(d); - } - - friend class timer::Timer; - - private: - - EventPtr get() - { - return evt.get(); - } - - details::Event evt; + public: + /* 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. + */ + Event() = delete; + Event(const Event&) = delete; + Event& operator=(const Event&) = delete; + Event(Event&&) = default; + Event& operator=(Event&&) = default; + ~Event() = default; + + /** @brief Conversion constructor from 'EventPtr'. + * + * Increments ref-count of the event-pointer and releases it when + * done. + */ + explicit Event(EventPtr e); + + /** @brief Constructor for 'Event'. + * + * Takes ownership of the event-pointer and releases it when done. + */ + Event(EventPtr e, std::false_type); + + /** @brief Release ownership of the stored event-pointer. */ + EventPtr release() + { + return evt.release(); + } + + /** @brief Wait indefinitely for new event sources. */ + void loop() + { + sd_event_loop(evt.get()); + } + + /** @brief Attach to a DBus loop. */ + void attach(sdbusplus::bus::bus& bus) + { + bus.attach_event(evt.get(), SD_EVENT_PRIORITY_NORMAL); + } + + /** @brief C++ wrapper for sd_event_now. */ + auto now() + { + using namespace std::chrono; + + uint64_t usec; + sd_event_now(evt.get(), CLOCK_MONOTONIC, &usec); + microseconds d(usec); + return steady_clock::time_point(d); + } + + friend class timer::Timer; + + private: + EventPtr get() + { + return evt.get(); + } + + details::Event evt; }; inline Event::Event(EventPtr l) : evt(sd_event_ref(l)) { - } inline Event::Event(EventPtr l, std::false_type) : evt(l) { - } inline Event newDefault() diff --git a/src/sdevent/source.hpp b/src/sdevent/source.hpp index 812f0a3..4f837be 100644 --- a/src/sdevent/source.hpp +++ b/src/sdevent/source.hpp @@ -37,77 +37,80 @@ using source = std::unique_ptr; */ class Source { - public: - /* 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. - */ - Source() = delete; - Source(const Source&) = delete; - Source& operator=(const Source&) = delete; - Source(Source&&) = default; - Source& operator=(Source&&) = default; - ~Source() = default; - - /** @brief Conversion constructor from 'SourcePtr'. - * - * Increments ref-count of the source-pointer and releases it - * when done. - */ - explicit Source(SourcePtr s) : src(sd_event_source_ref(s)) {} - - /** @brief Constructor for 'source'. - * - * Takes ownership of the source-pointer and releases it when done. - */ - Source(SourcePtr s, std::false_type) : src(s) {} - - /** @brief Check if source contains a real pointer. (non-nullptr). */ - explicit operator bool() const - { - return bool(src); - } - - /** @brief Test whether or not the source can generate events. */ - auto enabled() - { - int enabled; - sd_event_source_get_enabled(src.get(), &enabled); - return enabled; - } - - /** @brief Allow the source to generate events. */ - void enable(int enable) - { - sd_event_source_set_enabled(src.get(), enable); - } - - /** @brief Set the expiration on a timer source. */ - void setTime( - const std::chrono::steady_clock::time_point& expires) - { - using namespace std::chrono; - auto epoch = expires.time_since_epoch(); - auto time = duration_cast(epoch); - sd_event_source_set_time(src.get(), time.count()); - } - - /** @brief Get the expiration on a timer source. */ - auto getTime() - { - using namespace std::chrono; - uint64_t usec; - sd_event_source_get_time(src.get(), &usec); - microseconds d(usec); - return steady_clock::time_point(d); - } - - private: - details::source src; + public: + /* 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. + */ + Source() = delete; + Source(const Source&) = delete; + Source& operator=(const Source&) = delete; + Source(Source&&) = default; + Source& operator=(Source&&) = default; + ~Source() = default; + + /** @brief Conversion constructor from 'SourcePtr'. + * + * Increments ref-count of the source-pointer and releases it + * when done. + */ + explicit Source(SourcePtr s) : src(sd_event_source_ref(s)) + { + } + + /** @brief Constructor for 'source'. + * + * Takes ownership of the source-pointer and releases it when done. + */ + Source(SourcePtr s, std::false_type) : src(s) + { + } + + /** @brief Check if source contains a real pointer. (non-nullptr). */ + explicit operator bool() const + { + return bool(src); + } + + /** @brief Test whether or not the source can generate events. */ + auto enabled() + { + int enabled; + sd_event_source_get_enabled(src.get(), &enabled); + return enabled; + } + + /** @brief Allow the source to generate events. */ + void enable(int enable) + { + sd_event_source_set_enabled(src.get(), enable); + } + + /** @brief Set the expiration on a timer source. */ + void setTime(const std::chrono::steady_clock::time_point& expires) + { + using namespace std::chrono; + auto epoch = expires.time_since_epoch(); + auto time = duration_cast(epoch); + sd_event_source_set_time(src.get(), time.count()); + } + + /** @brief Get the expiration on a timer source. */ + auto getTime() + { + using namespace std::chrono; + uint64_t usec; + sd_event_source_get_time(src.get(), &usec); + microseconds d(usec); + return steady_clock::time_point(d); + } + + private: + details::source src; }; } // namespace source } // namespace sdevent diff --git a/src/sdevent/timer.hpp b/src/sdevent/timer.hpp index 863e725..5e45b94 100644 --- a/src/sdevent/timer.hpp +++ b/src/sdevent/timer.hpp @@ -22,117 +22,99 @@ namespace timer */ class Timer { - public: - /* 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. - */ - Timer() = delete; - Timer(const Timer&) = delete; - Timer& operator=(const Timer&) = delete; - Timer(Timer&&) = default; - Timer& operator=(Timer&&) = default; - ~Timer() = default; + public: + /* 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. + */ + Timer() = delete; + Timer(const Timer&) = delete; + Timer& operator=(const Timer&) = delete; + Timer(Timer&&) = default; + Timer& operator=(Timer&&) = default; + ~Timer() = default; - using Callback = std::function; + using Callback = std::function; - /** @brief Register a timer callback. - * - * @param[in] event - The event to register on. - * @param[in] expires - The initial timer expiration time. - * @param[in] callback - The callback method. - */ - Timer( - sdevent::event::Event& event, - const std::chrono::steady_clock::time_point& expires, - Callback callback) - : src(nullptr), - cb(std::make_unique(std::move(callback))) - { - using namespace std::chrono; - auto epoch = expires.time_since_epoch(); - auto time = duration_cast(epoch); - sd_event_source* source = nullptr; - sd_event_add_time( - event.get(), - &source, - CLOCK_MONOTONIC, - time.count(), - 0, - callCallback, - cb.get()); -// **INDENT-OFF** - src = decltype(src){source, std::false_type()}; -// **INDENT-ON** - } + /** @brief Register a timer callback. + * + * @param[in] event - The event to register on. + * @param[in] expires - The initial timer expiration time. + * @param[in] callback - The callback method. + */ + Timer(sdevent::event::Event& event, + const std::chrono::steady_clock::time_point& expires, + Callback callback) : + src(nullptr), + cb(std::make_unique(std::move(callback))) + { + using namespace std::chrono; + auto epoch = expires.time_since_epoch(); + auto time = duration_cast(epoch); + sd_event_source* source = nullptr; + sd_event_add_time(event.get(), &source, CLOCK_MONOTONIC, time.count(), + 0, callCallback, cb.get()); + // **INDENT-OFF** + src = decltype(src){source, std::false_type()}; + // **INDENT-ON** + } - /** @brief Register a disabled timer callback. - * - * @param[in] event - The event to register on. - * @param[in] callback - The callback method. - */ - Timer( - sdevent::event::Event& event, - Callback callback) - : src(nullptr), - cb(std::make_unique(std::move(callback))) - { - sd_event_source* source = nullptr; - sd_event_add_time( - event.get(), - &source, - CLOCK_MONOTONIC, - ULLONG_MAX, - 0, - callCallback, - cb.get()); -// **INDENT-OFF** - src = decltype(src){source, std::false_type()}; -// **INDENT-ON** - } + /** @brief Register a disabled timer callback. + * + * @param[in] event - The event to register on. + * @param[in] callback - The callback method. + */ + Timer(sdevent::event::Event& event, Callback callback) : + src(nullptr), cb(std::make_unique(std::move(callback))) + { + sd_event_source* source = nullptr; + sd_event_add_time(event.get(), &source, CLOCK_MONOTONIC, ULLONG_MAX, 0, + callCallback, cb.get()); + // **INDENT-OFF** + src = decltype(src){source, std::false_type()}; + // **INDENT-ON** + } - /** @brief Set the timer expiration time. */ - void setTime( - const std::chrono::steady_clock::time_point& expires) - { - src.setTime(expires); - } + /** @brief Set the timer expiration time. */ + void setTime(const std::chrono::steady_clock::time_point& expires) + { + src.setTime(expires); + } - /** @brief Get the timer expiration time. */ - auto getTime() - { - return src.getTime(); - } + /** @brief Get the timer expiration time. */ + auto getTime() + { + return src.getTime(); + } - /** @brief Set the timer source enable state. */ - void enable(int enable) - { - src.enable(enable); - } + /** @brief Set the timer source enable state. */ + void enable(int enable) + { + src.enable(enable); + } - /** @brief Query timer state. */ - auto enabled() - { - return src.enabled(); - } + /** @brief Query timer state. */ + auto enabled() + { + return src.enabled(); + } - private: - source::Source src; - std::unique_ptr cb = nullptr; + private: + source::Source src; + std::unique_ptr cb = nullptr; - static int callCallback(sd_event_source* s, uint64_t usec, - void* context) - { - source::Source source(s); - auto c = static_cast(context); - (*c)(source); + static int callCallback(sd_event_source* s, uint64_t usec, void* context) + { + source::Source source(s); + auto c = static_cast(context); + (*c)(source); - return 0; - } + return 0; + } }; } // namespace timer } // namespace event diff --git a/src/test/callbackgentest.cpp b/src/test/callbackgentest.cpp index 77fe60a..cda665d 100644 --- a/src/test/callbackgentest.cpp +++ b/src/test/callbackgentest.cpp @@ -9,15 +9,12 @@ using Index = std::map, size_t>; #include "callbackgentest.hpp" -const std::array, 4> expectedCallbacks = -{ - { - std::tuple{"int32_t", 0}, - std::tuple{"int32_t", 0}, - std::tuple{"std::string", 1}, - std::tuple{"std::string", 2}, - } -}; +const std::array, 4> expectedCallbacks = {{ + std::tuple{"int32_t", 0}, + std::tuple{"int32_t", 0}, + std::tuple{"std::string", 1}, + std::tuple{"std::string", 2}, +}}; TEST(CallbackGenTest, CallbacksSameSize) { @@ -29,7 +26,6 @@ TEST(CallbackGenTest, CallbacksSameContent) size_t i; for (i = 0; i < expectedCallbacks.size(); ++i) { - ASSERT_EQ(callbacks[i], - expectedCallbacks[i]); + ASSERT_EQ(callbacks[i], expectedCallbacks[i]); } } diff --git a/src/test/callbackgroupgentest.cpp b/src/test/callbackgroupgentest.cpp index 3112295..fe760ec 100644 --- a/src/test/callbackgroupgentest.cpp +++ b/src/test/callbackgroupgentest.cpp @@ -8,12 +8,11 @@ using namespace phosphor::dbus::monitoring; #include "callbackgroupgentest.hpp" const std::array, 4> expectedGroups = {{ - {0, 1, 2, 3}, - {0, 1, 4}, - {2, 6, 7}, - {7}, - } -}; + {0, 1, 2, 3}, + {0, 1, 4}, + {2, 6, 7}, + {7}, +}}; TEST(CallbackGroupGenTest, GroupsSameSize) { @@ -25,7 +24,6 @@ TEST(CallbackGroupGenTest, GroupsSameContent) size_t i; for (i = 0; i < expectedGroups.size(); ++i) { - ASSERT_EQ(groups[i], - expectedGroups[i]); + ASSERT_EQ(groups[i], expectedGroups[i]); } } diff --git a/src/test/conditiongentest.cpp b/src/test/conditiongentest.cpp index 76ea608..d0df215 100644 --- a/src/test/conditiongentest.cpp +++ b/src/test/conditiongentest.cpp @@ -7,16 +7,12 @@ using namespace phosphor::dbus::monitoring; #include "conditiongentest.hpp" -const std::array, 2> expectedGroups = -{ - { - {0}, - {1}, - } -}; +const std::array, 2> expectedGroups = {{ + {0}, + {1}, +}}; -const std::array expectedCallbacks = -{ +const std::array expectedCallbacks = { 0, 0, 1, @@ -38,8 +34,7 @@ TEST(ConditionGenTest, GroupsSameContent) size_t i; for (i = 0; i < expectedGroups.size(); ++i) { - ASSERT_EQ(groups[i], - expectedGroups[i]); + ASSERT_EQ(groups[i], expectedGroups[i]); } } @@ -48,7 +43,6 @@ TEST(ConditionGenTest, CallbacksSameContent) size_t i; for (i = 0; i < expectedCallbacks.size(); ++i) { - ASSERT_EQ(callbacks[i], - expectedCallbacks[i]); + ASSERT_EQ(callbacks[i], expectedCallbacks[i]); } } diff --git a/src/test/pathgentest.cpp b/src/test/pathgentest.cpp index d13c82e..1f75153 100644 --- a/src/test/pathgentest.cpp +++ b/src/test/pathgentest.cpp @@ -9,15 +9,13 @@ using PathMeta = TupleOfRefs; #include "pathgentest.hpp" -const std::array expectedMeta = -{ +const std::array expectedMeta = { "PATH1"s, "PATH3"s, "PATH2"s, }; -const std::array expectedPaths = -{ +const std::array expectedPaths = { "/xyz/openbmc_project/testing/inst1"s, "/xyz/openbmc_project/testing/inst2"s, "/xyz/openbmc_project/testing/inst3"s, @@ -26,55 +24,49 @@ const std::array expectedPaths = "/xyz/openbmc_project/testing/inst6"s, }; -const std::array expectedPathMeta = -{ +const std::array expectedPathMeta = {{ + PathMeta{paths[0], meta[0]}, + PathMeta{paths[1], meta[0]}, + PathMeta{paths[2], meta[0]}, + PathMeta{paths[3], meta[0]}, + PathMeta{paths[0], meta[1]}, + PathMeta{paths[1], meta[1]}, + PathMeta{paths[2], meta[1]}, + PathMeta{paths[3], meta[1]}, + PathMeta{paths[4], meta[0]}, + PathMeta{paths[5], meta[0]}, + PathMeta{paths[3], meta[2]}, + PathMeta{paths[2], meta[2]}, + PathMeta{paths[1], meta[2]}, + PathMeta{paths[0], meta[2]}, +}}; + +const std::array, 4> expectedGroups = {{ { - PathMeta{ paths[0], meta[0] }, - PathMeta{ paths[1], meta[0] }, - PathMeta{ paths[2], meta[0] }, - PathMeta{ paths[3], meta[0] }, - PathMeta{ paths[0], meta[1] }, - PathMeta{ paths[1], meta[1] }, - PathMeta{ paths[2], meta[1] }, - PathMeta{ paths[3], meta[1] }, - PathMeta{ paths[4], meta[0] }, - PathMeta{ paths[5], meta[0] }, - PathMeta{ paths[3], meta[2] }, - PathMeta{ paths[2], meta[2] }, - PathMeta{ paths[1], meta[2] }, - PathMeta{ paths[0], meta[2] }, - } -}; - -const std::array, 4> expectedGroups = -{ + paths[0], + paths[1], + paths[2], + paths[3], + }, { - { - paths[0], - paths[1], - paths[2], - paths[3], - }, - { - paths[0], - paths[1], - paths[2], - paths[3], - }, - { - paths[0], - paths[1], - paths[4], - paths[5], - }, - { - paths[3], - paths[2], - paths[1], - paths[0], - }, - } -}; + paths[0], + paths[1], + paths[2], + paths[3], + }, + { + paths[0], + paths[1], + paths[4], + paths[5], + }, + { + paths[3], + paths[2], + paths[1], + paths[0], + }, +}}; TEST(PathGenTest, MetaSameSize) { @@ -138,7 +130,6 @@ TEST(PathGenTest, GroupsSameContent) for (j = 0; j < groups[i].size(); ++j) { ASSERT_EQ(groups[i][j].get(), expectedGroups[i][j].get()); - } } } diff --git a/src/test/propertygentest.cpp b/src/test/propertygentest.cpp index e5c95c2..d17f6a1 100644 --- a/src/test/propertygentest.cpp +++ b/src/test/propertygentest.cpp @@ -7,62 +7,52 @@ using namespace std::string_literals; using namespace phosphor::dbus::monitoring; using Property = - TupleOfRefs < - const std::string, - const std::string, - const std::string >; + TupleOfRefs; using GroupOfProperties = std::vector; #include "propertygentest.hpp" -const std::array expectedMeta = -{ +const std::array expectedMeta = { "PROPERTY1"s, "PROPERTY2"s, "PROPERTY3"s, }; -const std::array expectedInterfaces = -{ +const std::array expectedInterfaces = { "xyz.openbmc_project.Test.Iface3"s, "xyz.openbmc_project.Test.Iface2"s, "xyz.openbmc_project.Test.Iface6"s, "xyz.openbmc_project.Test.Iface1"s, }; -const std::array expectedProperties = -{ +const std::array expectedProperties = { "Foo"s, "Value"s, "Bar"s, "Baz"s, }; -const std::array expectedGroups = -{ +const std::array expectedGroups = {{ { - { - Property{ interfaces[0], properties[0], meta[0] }, - Property{ interfaces[1], properties[1], meta[1] }, - }, - { - Property{ interfaces[0], properties[2], meta[0] }, - Property{ interfaces[1], properties[0], meta[1] }, - }, - { - Property{ interfaces[2], properties[0], meta[0] }, - Property{ interfaces[3], properties[1], meta[1] }, - }, - { - Property{ interfaces[0], properties[2], meta[0] }, - Property{ interfaces[1], properties[1], meta[1] }, - Property{ interfaces[2], properties[3], meta[2] }, - }, - } -}; + Property{interfaces[0], properties[0], meta[0]}, + Property{interfaces[1], properties[1], meta[1]}, + }, + { + Property{interfaces[0], properties[2], meta[0]}, + Property{interfaces[1], properties[0], meta[1]}, + }, + { + Property{interfaces[2], properties[0], meta[0]}, + Property{interfaces[3], properties[1], meta[1]}, + }, + { + Property{interfaces[0], properties[2], meta[0]}, + Property{interfaces[1], properties[1], meta[1]}, + Property{interfaces[2], properties[3], meta[2]}, + }, +}}; -const std::array expectedTypes = -{ +const std::array expectedTypes = { "uint32_t"s, "int32_t"s, "std::string"s, @@ -99,8 +89,7 @@ TEST(PropertyGenTest, MetaSameContent) size_t i; for (i = 0; i < expectedMeta.size(); ++i) { - ASSERT_EQ(meta[i], - expectedMeta[i]); + ASSERT_EQ(meta[i], expectedMeta[i]); } } @@ -109,8 +98,7 @@ TEST(PropertyGenTest, IfacesSameContent) size_t i; for (i = 0; i < expectedInterfaces.size(); ++i) { - ASSERT_EQ(interfaces[i], - expectedInterfaces[i]); + ASSERT_EQ(interfaces[i], expectedInterfaces[i]); } } @@ -135,7 +123,8 @@ TEST(PropertyGenTest, GroupsSameContent) const auto& actualIface = std::get<0>(groups[i][j]).get(); ASSERT_EQ(expectedIface, actualIface); - const auto& expectedProperty = std::get<1>(expectedGroups[i][j]).get(); + const auto& expectedProperty = + std::get<1>(expectedGroups[i][j]).get(); const auto& actualProperty = std::get<1>(groups[i][j]).get(); ASSERT_EQ(expectedProperty, actualProperty); diff --git a/src/test/propertywatchgentest.cpp b/src/test/propertywatchgentest.cpp index 5973f92..2e446a4 100644 --- a/src/test/propertywatchgentest.cpp +++ b/src/test/propertywatchgentest.cpp @@ -12,48 +12,42 @@ using Index = std::map, size_t>; auto expectedStorageCount = 16; -const std::array expectedIndicies = -{ +const std::array expectedIndicies = {{ { - { - {Index::key_type{0, 0, 0}, 0}, - {Index::key_type{0, 1, 0}, 1}, - {Index::key_type{1, 0, 0}, 2}, - {Index::key_type{1, 1, 0}, 3}, - {Index::key_type{2, 0, 0}, 4}, - {Index::key_type{2, 1, 0}, 5}, - {Index::key_type{3, 0, 0}, 6}, - {Index::key_type{3, 1, 0}, 7}, - }, - { - {Index::key_type{2, 2, 1}, 8}, - {Index::key_type{2, 2, 2}, 9}, - {Index::key_type{3, 2, 1}, 10}, - {Index::key_type{3, 2, 2}, 11}, - {Index::key_type{4, 2, 1}, 12}, - {Index::key_type{4, 2, 2}, 13}, - {Index::key_type{5, 2, 1}, 14}, - {Index::key_type{5, 2, 2}, 15}, - }, - { - {Index::key_type{3, 0, 0}, 6}, - }, - { - {Index::key_type{3, 2, 2}, 11}, - {Index::key_type{5, 2, 2}, 15}, - }, - } -}; - -const std::array, 4> expectedWatches = -{ + {Index::key_type{0, 0, 0}, 0}, + {Index::key_type{0, 1, 0}, 1}, + {Index::key_type{1, 0, 0}, 2}, + {Index::key_type{1, 1, 0}, 3}, + {Index::key_type{2, 0, 0}, 4}, + {Index::key_type{2, 1, 0}, 5}, + {Index::key_type{3, 0, 0}, 6}, + {Index::key_type{3, 1, 0}, 7}, + }, { - std::tuple{"std::string"s, 0}, - std::tuple{"uint32_t"s, 1}, - std::tuple{"int32_t"s, 2}, - std::tuple{"std::string"s, 3}, - } -}; + {Index::key_type{2, 2, 1}, 8}, + {Index::key_type{2, 2, 2}, 9}, + {Index::key_type{3, 2, 1}, 10}, + {Index::key_type{3, 2, 2}, 11}, + {Index::key_type{4, 2, 1}, 12}, + {Index::key_type{4, 2, 2}, 13}, + {Index::key_type{5, 2, 1}, 14}, + {Index::key_type{5, 2, 2}, 15}, + }, + { + {Index::key_type{3, 0, 0}, 6}, + }, + { + {Index::key_type{3, 2, 2}, 11}, + {Index::key_type{5, 2, 2}, 15}, + }, +}}; + +const std::array, 4> expectedWatches = {{ + std::tuple{"std::string"s, 0}, + std::tuple{"uint32_t"s, 1}, + std::tuple{"int32_t"s, 2}, + std::tuple{"std::string"s, 3}, +}}; TEST(PropertyWatchGenTest, storageCount) { @@ -75,8 +69,7 @@ TEST(PropertyWatchGenTest, WatchesSameContent) size_t i; for (i = 0; i < expectedWatches.size(); ++i) { - ASSERT_EQ(watches[i], - expectedWatches[i]); + ASSERT_EQ(watches[i], expectedWatches[i]); } } @@ -85,7 +78,6 @@ TEST(PropertyWatchGenTest, IndiciesSameContent) size_t i; for (i = 0; i < expectedIndicies.size(); ++i) { - ASSERT_EQ(indices[i], - expectedIndicies[i]); + ASSERT_EQ(indices[i], expectedIndicies[i]); } } diff --git a/src/test/propertywatchtest.cpp b/src/test/propertywatchtest.cpp index c97e8d3..6576bfd 100644 --- a/src/test/propertywatchtest.cpp +++ b/src/test/propertywatchtest.cpp @@ -5,75 +5,56 @@ using namespace std::string_literals; using namespace phosphor::dbus::monitoring; -const std::array paths = -{ +const std::array paths = { "/xyz/openbmc_project/testing/inst1"s, "/xyz/openbmc_project/testing/inst2"s, "/xyz/openbmc_project/testing/inst3"s, "/xyz/openbmc_project/testing/inst4"s, }; -const std::array interfaces = -{ +const std::array interfaces = { "xyz.openbmc_project.Iface1"s, "xyz.openbmc_project.Iface2"s, }; -const std::array properties = -{ +const std::array properties = { "Value1"s, "Value2"s, }; const std::string meta; -std::array, 8> storage = { }; +std::array, 8> storage = {}; -const PropertyIndex watchIndex = -{ +const PropertyIndex watchIndex = { { - { - PropertyIndex::key_type{paths[0], interfaces[0], properties[0]}, - PropertyIndex::mapped_type{meta, meta, storage[0]} - }, - { - PropertyIndex::key_type{paths[0], interfaces[1], properties[1]}, - PropertyIndex::mapped_type{meta, meta, storage[1]} - }, - { - PropertyIndex::key_type{paths[1], interfaces[0], properties[0]}, - PropertyIndex::mapped_type{meta, meta, storage[2]} - }, - { - PropertyIndex::key_type{paths[1], interfaces[1], properties[1]}, - PropertyIndex::mapped_type{meta, meta, storage[3]} - }, - { - PropertyIndex::key_type{paths[2], interfaces[0], properties[0]}, - PropertyIndex::mapped_type{meta, meta, storage[4]} - }, - { - PropertyIndex::key_type{paths[2], interfaces[1], properties[1]}, - PropertyIndex::mapped_type{meta, meta, storage[5]} - }, - { - PropertyIndex::key_type{paths[3], interfaces[0], properties[0]}, - PropertyIndex::mapped_type{meta, meta, storage[6]} - }, - { - PropertyIndex::key_type{paths[3], interfaces[1], properties[1]}, - PropertyIndex::mapped_type{meta, meta, storage[7]} - }, + {PropertyIndex::key_type{paths[0], interfaces[0], properties[0]}, + PropertyIndex::mapped_type{meta, meta, storage[0]}}, + {PropertyIndex::key_type{paths[0], interfaces[1], properties[1]}, + PropertyIndex::mapped_type{meta, meta, storage[1]}}, + {PropertyIndex::key_type{paths[1], interfaces[0], properties[0]}, + PropertyIndex::mapped_type{meta, meta, storage[2]}}, + {PropertyIndex::key_type{paths[1], interfaces[1], properties[1]}, + PropertyIndex::mapped_type{meta, meta, storage[3]}}, + {PropertyIndex::key_type{paths[2], interfaces[0], properties[0]}, + PropertyIndex::mapped_type{meta, meta, storage[4]}}, + {PropertyIndex::key_type{paths[2], interfaces[1], properties[1]}, + PropertyIndex::mapped_type{meta, meta, storage[5]}}, + {PropertyIndex::key_type{paths[3], interfaces[0], properties[0]}, + PropertyIndex::mapped_type{meta, meta, storage[6]}}, + {PropertyIndex::key_type{paths[3], interfaces[1], properties[1]}, + PropertyIndex::mapped_type{meta, meta, storage[7]}}, }, }; -template struct ExpectedValues {}; +template struct ExpectedValues +{ +}; template <> struct ExpectedValues { static auto& get(size_t i) { - static const std::array values = - { + static const std::array values = { {0, 1, 2, 3, 4, 5, 6, 7}, }; return values[i]; @@ -84,8 +65,7 @@ template <> struct ExpectedValues { static auto& get(size_t i) { - static const std::array values = - { + static const std::array values = { {88, 77, 66, 55, 44, 33, 22, 11}, }; return values[i]; @@ -96,8 +76,7 @@ template <> struct ExpectedValues { static auto& get(size_t i) { - static const std::array values = - { + static const std::array values = { {0xffffffff, 1, 3, 0, 5, 7, 9, 0xffffffff}, }; return values[i]; @@ -108,8 +87,7 @@ template <> struct ExpectedValues { static auto& get(size_t i) { - static const std::array values = - { + static const std::array values = { {0xffffffffffffffff, 3, 7, 12234, 0, 3, 9, 0xffffffff}, }; return values[i]; @@ -120,16 +98,14 @@ template <> struct ExpectedValues { static auto& get(size_t i) { - static const std::array values = - { + static const std::array values = { {""s, "foo"s, "bar"s, "baz"s, "hello"s, "string", "\x2\x3", "\\"}, }; return values[i]; } }; -template -void testStart() +template void testStart() { using ::testing::Return; using ::testing::_; @@ -146,34 +122,22 @@ void testStart() const auto& path = o.first.get(); const auto& interfaces = o.second; std::vector mapperResponse; - std::transform( - interfaces.begin(), - interfaces.end(), - std::back_inserter(mapperResponse), - // *INDENT-OFF* - [](const auto & item) - { - return item.first; - }); + std::transform(interfaces.begin(), interfaces.end(), + std::back_inserter(mapperResponse), + // *INDENT-OFF* + [](const auto& item) { return item.first; }); // *INDENT-ON* + EXPECT_CALL(dbus, mapperGetObject(MAPPER_BUSNAME, MAPPER_PATH, + MAPPER_INTERFACE, "GetObject", path, + expectedMapperInterfaces)) + .WillOnce(Return(GetObject({{"", mapperResponse}}))); EXPECT_CALL( - dbus, - mapperGetObject( - MAPPER_BUSNAME, - MAPPER_PATH, - MAPPER_INTERFACE, - "GetObject", - path, - expectedMapperInterfaces)) - .WillOnce(Return(GetObject({{"", mapperResponse}}))); - EXPECT_CALL( - dbus, - fwdAddMatch( - sdbusplus::bus::match::rules::member("InterfacesAdded") + - sdbusplus::bus::match::rules::path(path) + - sdbusplus::bus::match::rules::interface( - "org.freedesktop.DBus.ObjectManager"), - _)); + dbus, fwdAddMatch( + sdbusplus::bus::match::rules::member("InterfacesAdded") + + sdbusplus::bus::match::rules::path(path) + + sdbusplus::bus::match::rules::interface( + "org.freedesktop.DBus.ObjectManager"), + _)); for (const auto& i : interfaces) { const auto& interface = i.first.get(); @@ -182,10 +146,10 @@ void testStart() dbus, fwdAddMatch( sdbusplus::bus::match::rules::member("PropertiesChanged") + - sdbusplus::bus::match::rules::path(path) + - sdbusplus::bus::match::rules::argN(0, interface) + - sdbusplus::bus::match::rules::interface( - "org.freedesktop.DBus.Properties"), + sdbusplus::bus::match::rules::path(path) + + sdbusplus::bus::match::rules::argN(0, interface) + + sdbusplus::bus::match::rules::interface( + "org.freedesktop.DBus.Properties"), _)); PropertiesChanged serviceResponse; @@ -195,7 +159,7 @@ void testStart() ++ndx; } Expect::getProperties(dbus, path, interface) - .WillOnce(Return(serviceResponse)); + .WillOnce(Return(serviceResponse)); } } diff --git a/src/test/propertywatchtest.hpp b/src/test/propertywatchtest.hpp index f965096..d226f93 100644 --- a/src/test/propertywatchtest.hpp +++ b/src/test/propertywatchtest.hpp @@ -26,19 +26,12 @@ namespace monitoring * * Specialize to implement new forwards. */ -template < - typename DBusInterfaceType, - typename Ret, - typename ...Args > +template struct CallMethodAndRead { - static Ret op( - DBusInterfaceType& dbus, - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - Args&& ... args) + static Ret op(DBusInterfaceType& dbus, const std::string& busName, + const std::string& path, const std::string& interface, + const std::string& method, Args&&... args) { static_assert(true, "Missing CallMethodAndRead definition."); return Ret(); @@ -48,253 +41,160 @@ struct CallMethodAndRead /** @brief CallMethodAndRead specialization for * xyz.openbmc_project.ObjectMapper.GetObject. */ template -struct CallMethodAndRead < - DBusInterfaceType, - GetObject, - const MapperPath&, - const std::vector& > +struct CallMethodAndRead&> { - static GetObject op( - DBusInterfaceType& dbus, - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - const MapperPath& objectPath, - const std::vector& interfaces) + static GetObject op(DBusInterfaceType& dbus, const std::string& busName, + const std::string& path, const std::string& interface, + const std::string& method, const MapperPath& objectPath, + const std::vector& interfaces) { - return dbus.mapperGetObject( - busName, - path, - interface, - method, - objectPath, - interfaces); + return dbus.mapperGetObject(busName, path, interface, method, + objectPath, interfaces); } }; /** @brief CallMethodAndRead specialization for * org.freedesktop.DBus.Properties.GetAll(uint64_t). */ template -struct CallMethodAndRead < - DBusInterfaceType, - PropertiesChanged, - const std::string& > +struct CallMethodAndRead, + const std::string&> { - static PropertiesChanged op( - DBusInterfaceType& dbus, - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - const std::string& propertiesInterface) + static PropertiesChanged + op(DBusInterfaceType& dbus, const std::string& busName, + const std::string& path, const std::string& interface, + const std::string& method, const std::string& propertiesInterface) { - return dbus.getPropertiesU64( - busName, - path, - interface, - method, - propertiesInterface); + return dbus.getPropertiesU64(busName, path, interface, method, + propertiesInterface); } }; /** @brief CallMethodAndRead specialization for * org.freedesktop.DBus.Properties.GetAll(uint32_t). */ template -struct CallMethodAndRead < - DBusInterfaceType, - PropertiesChanged, - const std::string& > +struct CallMethodAndRead, + const std::string&> { - static PropertiesChanged op( - DBusInterfaceType& dbus, - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - const std::string& propertiesInterface) + static PropertiesChanged + op(DBusInterfaceType& dbus, const std::string& busName, + const std::string& path, const std::string& interface, + const std::string& method, const std::string& propertiesInterface) { - return dbus.getPropertiesU32( - busName, - path, - interface, - method, - propertiesInterface); + return dbus.getPropertiesU32(busName, path, interface, method, + propertiesInterface); } }; /** @brief CallMethodAndRead specialization for * org.freedesktop.DBus.Properties.GetAll(uint16_t). */ template -struct CallMethodAndRead < - DBusInterfaceType, - PropertiesChanged, - const std::string& > +struct CallMethodAndRead, + const std::string&> { - static PropertiesChanged op( - DBusInterfaceType& dbus, - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - const std::string& propertiesInterface) + static PropertiesChanged + op(DBusInterfaceType& dbus, const std::string& busName, + const std::string& path, const std::string& interface, + const std::string& method, const std::string& propertiesInterface) { - return dbus.getPropertiesU16( - busName, - path, - interface, - method, - propertiesInterface); + return dbus.getPropertiesU16(busName, path, interface, method, + propertiesInterface); } }; /** @brief CallMethodAndRead specialization for * org.freedesktop.DBus.Properties.GetAll(uint8_t). */ template -struct CallMethodAndRead < - DBusInterfaceType, - PropertiesChanged, - const std::string& > +struct CallMethodAndRead, + const std::string&> { - static PropertiesChanged op( - DBusInterfaceType& dbus, - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - const std::string& propertiesInterface) + static PropertiesChanged + op(DBusInterfaceType& dbus, const std::string& busName, + const std::string& path, const std::string& interface, + const std::string& method, const std::string& propertiesInterface) { - return dbus.getPropertiesU8( - busName, - path, - interface, - method, - propertiesInterface); + return dbus.getPropertiesU8(busName, path, interface, method, + propertiesInterface); } }; /** @brief CallMethodAndRead specialization for * org.freedesktop.DBus.Properties.GetAll(int64_t). */ template -struct CallMethodAndRead < - DBusInterfaceType, - PropertiesChanged, - const std::string& > +struct CallMethodAndRead, + const std::string&> { - static PropertiesChanged op( - DBusInterfaceType& dbus, - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - const std::string& propertiesInterface) + static PropertiesChanged + op(DBusInterfaceType& dbus, const std::string& busName, + const std::string& path, const std::string& interface, + const std::string& method, const std::string& propertiesInterface) { - return dbus.getPropertiesU64( - busName, - path, - interface, - method, - propertiesInterface); + return dbus.getPropertiesU64(busName, path, interface, method, + propertiesInterface); } }; /** @brief CallMethodAndRead specialization for * org.freedesktop.DBus.Properties.GetAll(int32_t). */ template -struct CallMethodAndRead < - DBusInterfaceType, - PropertiesChanged, - const std::string& > +struct CallMethodAndRead, + const std::string&> { - static PropertiesChanged op( - DBusInterfaceType& dbus, - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - const std::string& propertiesInterface) + static PropertiesChanged + op(DBusInterfaceType& dbus, const std::string& busName, + const std::string& path, const std::string& interface, + const std::string& method, const std::string& propertiesInterface) { - return dbus.getPropertiesU32( - busName, - path, - interface, - method, - propertiesInterface); + return dbus.getPropertiesU32(busName, path, interface, method, + propertiesInterface); } }; /** @brief CallMethodAndRead specialization for * org.freedesktop.DBus.Properties.GetAll(int16_t). */ template -struct CallMethodAndRead < - DBusInterfaceType, - PropertiesChanged, - const std::string& > +struct CallMethodAndRead, + const std::string&> { - static PropertiesChanged op( - DBusInterfaceType& dbus, - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - const std::string& propertiesInterface) + static PropertiesChanged + op(DBusInterfaceType& dbus, const std::string& busName, + const std::string& path, const std::string& interface, + const std::string& method, const std::string& propertiesInterface) { - return dbus.getPropertiesU16( - busName, - path, - interface, - method, - propertiesInterface); + return dbus.getPropertiesU16(busName, path, interface, method, + propertiesInterface); } }; /** @brief CallMethodAndRead specialization for * org.freedesktop.DBus.Properties.GetAll(int8_t). */ template -struct CallMethodAndRead < - DBusInterfaceType, - PropertiesChanged, - const std::string& > +struct CallMethodAndRead, + const std::string&> { - static PropertiesChanged op( - DBusInterfaceType& dbus, - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - const std::string& propertiesInterface) + static PropertiesChanged + op(DBusInterfaceType& dbus, const std::string& busName, + const std::string& path, const std::string& interface, + const std::string& method, const std::string& propertiesInterface) { - return dbus.getPropertiesU8( - busName, - path, - interface, - method, - propertiesInterface); + return dbus.getPropertiesU8(busName, path, interface, method, + propertiesInterface); } }; /** @brief CallMethodAndRead specialization for * org.freedesktop.DBus.Properties.GetAll(std::string). */ template -struct CallMethodAndRead < - DBusInterfaceType, - PropertiesChanged, - const std::string& > +struct CallMethodAndRead, + const std::string&> { - static PropertiesChanged op( - DBusInterfaceType& dbus, - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - const std::string& propertiesInterface) + static PropertiesChanged + op(DBusInterfaceType& dbus, const std::string& busName, + const std::string& path, const std::string& interface, + const std::string& method, const std::string& propertiesInterface) { - return dbus.getPropertiesString( - busName, - path, - interface, - method, - propertiesInterface); + return dbus.getPropertiesString(busName, path, interface, method, + propertiesInterface); } }; @@ -304,102 +204,59 @@ struct CallMethodAndRead < */ struct MockDBusInterface { - MOCK_METHOD6( - mapperGetObject, - GetObject( - const std::string&, - const std::string&, - const std::string&, - const std::string&, - const MapperPath&, - const std::vector&)); - - MOCK_METHOD5( - getPropertiesU64, - PropertiesChanged( - const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::string&)); - - MOCK_METHOD5( - getPropertiesU32, - PropertiesChanged( - const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::string&)); - - MOCK_METHOD5( - getPropertiesU16, - PropertiesChanged( - const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::string&)); - - MOCK_METHOD5( - getPropertiesU8, - PropertiesChanged( - const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::string&)); - - MOCK_METHOD5( - getPropertiesS64, - PropertiesChanged( - const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::string&)); - - MOCK_METHOD5( - getPropertiesS32, - PropertiesChanged( - const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::string&)); - - MOCK_METHOD5( - getPropertiesS16, - PropertiesChanged( - const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::string&)); - - MOCK_METHOD5( - getPropertiesS8, - PropertiesChanged( - const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::string&)); - - MOCK_METHOD5( - getPropertiesString, - PropertiesChanged( - const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::string&)); - - MOCK_METHOD2( - fwdAddMatch, - void( - const std::string&, - const sdbusplus::bus::match::match::callback_t&)); + MOCK_METHOD6(mapperGetObject, + GetObject(const std::string&, const std::string&, + const std::string&, const std::string&, + const MapperPath&, const std::vector&)); + + MOCK_METHOD5(getPropertiesU64, + PropertiesChanged( + const std::string&, const std::string&, const std::string&, + const std::string&, const std::string&)); + + MOCK_METHOD5(getPropertiesU32, + PropertiesChanged( + const std::string&, const std::string&, const std::string&, + const std::string&, const std::string&)); + + MOCK_METHOD5(getPropertiesU16, + PropertiesChanged( + const std::string&, const std::string&, const std::string&, + const std::string&, const std::string&)); + + MOCK_METHOD5(getPropertiesU8, + PropertiesChanged( + const std::string&, const std::string&, const std::string&, + const std::string&, const std::string&)); + + MOCK_METHOD5(getPropertiesS64, + PropertiesChanged( + const std::string&, const std::string&, const std::string&, + const std::string&, const std::string&)); + + MOCK_METHOD5(getPropertiesS32, + PropertiesChanged( + const std::string&, const std::string&, const std::string&, + const std::string&, const std::string&)); + + MOCK_METHOD5(getPropertiesS16, + PropertiesChanged( + const std::string&, const std::string&, const std::string&, + const std::string&, const std::string&)); + + MOCK_METHOD5(getPropertiesS8, + PropertiesChanged( + const std::string&, const std::string&, const std::string&, + const std::string&, const std::string&)); + + MOCK_METHOD5(getPropertiesString, + PropertiesChanged( + const std::string&, const std::string&, const std::string&, + const std::string&, const std::string&)); + + MOCK_METHOD2(fwdAddMatch, + void(const std::string&, + const sdbusplus::bus::match::match::callback_t&)); static MockDBusInterface* ptr; static MockDBusInterface& instance() @@ -412,27 +269,21 @@ struct MockDBusInterface } /** @brief GMock member template/free function forward. */ - template - static auto callMethodAndRead( - const std::string& busName, - const std::string& path, - const std::string& interface, - const std::string& method, - Args&& ... args) + template + static auto callMethodAndRead(const std::string& busName, + const std::string& path, + const std::string& interface, + const std::string& method, Args&&... args) { - return CallMethodAndRead ::op( - instance(), - busName, - path, - interface, - method, - std::forward(args)...); + return CallMethodAndRead::op( + instance(), busName, path, interface, method, + std::forward(args)...); } /** @brief GMock free function forward. */ - static auto addMatch( - const std::string& match, - const sdbusplus::bus::match::match::callback_t& callback) + static auto + addMatch(const std::string& match, + const sdbusplus::bus::match::match::callback_t& callback) { instance().fwdAddMatch(match, callback); } @@ -441,185 +292,125 @@ struct MockDBusInterface /** @class Expect * @brief Enable use of EXPECT_CALL from a C++ template. */ -template struct Expect {}; +template struct Expect +{ +}; -template <> -struct Expect +template <> struct Expect { template - static auto& getProperties( - MockObjType&& mockObj, - const std::string& path, - const std::string& interface) + static auto& getProperties(MockObjType&& mockObj, const std::string& path, + const std::string& interface) { - return EXPECT_CALL( - std::forward(mockObj), - getPropertiesU64( - ::testing::_, - path, - "org.freedesktop.DBus.Properties", - "GetAll", - interface)); + return EXPECT_CALL(std::forward(mockObj), + getPropertiesU64(::testing::_, path, + "org.freedesktop.DBus.Properties", + "GetAll", interface)); } }; -template <> -struct Expect +template <> struct Expect { template - static auto& getProperties( - MockObjType&& mockObj, - const std::string& path, - const std::string& interface) + static auto& getProperties(MockObjType&& mockObj, const std::string& path, + const std::string& interface) { - return EXPECT_CALL( - std::forward(mockObj), - getPropertiesU32( - ::testing::_, - path, - "org.freedesktop.DBus.Properties", - "GetAll", - interface)); + return EXPECT_CALL(std::forward(mockObj), + getPropertiesU32(::testing::_, path, + "org.freedesktop.DBus.Properties", + "GetAll", interface)); } }; -template <> -struct Expect +template <> struct Expect { template - static auto& getProperties( - MockObjType&& mockObj, - const std::string& path, - const std::string& interface) + static auto& getProperties(MockObjType&& mockObj, const std::string& path, + const std::string& interface) { - return EXPECT_CALL( - std::forward(mockObj), - getPropertiesU16( - ::testing::_, - path, - "org.freedesktop.DBus.Properties", - "GetAll", - interface)); + return EXPECT_CALL(std::forward(mockObj), + getPropertiesU16(::testing::_, path, + "org.freedesktop.DBus.Properties", + "GetAll", interface)); } }; -template <> -struct Expect +template <> struct Expect { template - static auto& getProperties( - MockObjType&& mockObj, - const std::string& path, - const std::string& interface) + static auto& getProperties(MockObjType&& mockObj, const std::string& path, + const std::string& interface) { - return EXPECT_CALL( - std::forward(mockObj), - getPropertiesU8( - ::testing::_, - path, - "org.freedesktop.DBus.Properties", - "GetAll", - interface)); + return EXPECT_CALL(std::forward(mockObj), + getPropertiesU8(::testing::_, path, + "org.freedesktop.DBus.Properties", + "GetAll", interface)); } }; -template <> -struct Expect +template <> struct Expect { template - static auto& getProperties( - MockObjType&& mockObj, - const std::string& path, - const std::string& interface) + static auto& getProperties(MockObjType&& mockObj, const std::string& path, + const std::string& interface) { - return EXPECT_CALL( - std::forward(mockObj), - getPropertiesS64( - ::testing::_, - path, - "org.freedesktop.DBus.Properties", - "GetAll", - interface)); + return EXPECT_CALL(std::forward(mockObj), + getPropertiesS64(::testing::_, path, + "org.freedesktop.DBus.Properties", + "GetAll", interface)); } }; -template <> -struct Expect +template <> struct Expect { template - static auto& getProperties( - MockObjType&& mockObj, - const std::string& path, - const std::string& interface) + static auto& getProperties(MockObjType&& mockObj, const std::string& path, + const std::string& interface) { - return EXPECT_CALL( - std::forward(mockObj), - getPropertiesS32( - ::testing::_, - path, - "org.freedesktop.DBus.Properties", - "GetAll", - interface)); + return EXPECT_CALL(std::forward(mockObj), + getPropertiesS32(::testing::_, path, + "org.freedesktop.DBus.Properties", + "GetAll", interface)); } }; -template <> -struct Expect +template <> struct Expect { template - static auto& getProperties( - MockObjType&& mockObj, - const std::string& path, - const std::string& interface) + static auto& getProperties(MockObjType&& mockObj, const std::string& path, + const std::string& interface) { - return EXPECT_CALL( - std::forward(mockObj), - getPropertiesS16( - ::testing::_, - path, - "org.freedesktop.DBus.Properties", - "GetAll", - interface)); + return EXPECT_CALL(std::forward(mockObj), + getPropertiesS16(::testing::_, path, + "org.freedesktop.DBus.Properties", + "GetAll", interface)); } }; -template <> -struct Expect +template <> struct Expect { template - static auto& getProperties( - MockObjType&& mockObj, - const std::string& path, - const std::string& interface) + static auto& getProperties(MockObjType&& mockObj, const std::string& path, + const std::string& interface) { - return EXPECT_CALL( - std::forward(mockObj), - getPropertiesS8( - ::testing::_, - path, - "org.freedesktop.DBus.Properties", - "GetAll", - interface)); + return EXPECT_CALL(std::forward(mockObj), + getPropertiesS8(::testing::_, path, + "org.freedesktop.DBus.Properties", + "GetAll", interface)); } }; -template <> -struct Expect +template <> struct Expect { template - static auto& getProperties( - MockObjType&& mockObj, - const std::string& path, - const std::string& interface) + static auto& getProperties(MockObjType&& mockObj, const std::string& path, + const std::string& interface) { return EXPECT_CALL( - std::forward(mockObj), - getPropertiesString( - ::testing::_, - path, - "org.freedesktop.DBus.Properties", - "GetAll", - interface)); + std::forward(mockObj), + getPropertiesString(::testing::_, path, + "org.freedesktop.DBus.Properties", "GetAll", + interface)); } }; diff --git a/src/tupleref.hpp b/src/tupleref.hpp index c6a6dcd..3e896be 100644 --- a/src/tupleref.hpp +++ b/src/tupleref.hpp @@ -17,8 +17,7 @@ using TupleOfRefs = std::tuple...>; namespace detail { /** @brief Less than implementation for tuples of references. */ -template -struct TupleOfRefsLess +template struct TupleOfRefsLess { static constexpr bool compare(const T& l, const U& r) { @@ -30,7 +29,7 @@ struct TupleOfRefsLess { return false; } - return TupleOfRefsLess < size, i + 1, T, U >::compare(l, r); + return TupleOfRefsLess::compare(l, r); } }; @@ -49,17 +48,13 @@ struct TupleOfRefsLess struct TupleOfRefsLess { template - constexpr bool operator()( - const TupleOfRefs& l, - const TupleOfRefs& r) const + constexpr bool operator()(const TupleOfRefs& l, + const TupleOfRefs& r) const { static_assert(sizeof...(T) == sizeof...(U), "Cannot compare tuples of different lengths."); - return detail::TupleOfRefsLess < - sizeof...(T), - 0, - TupleOfRefs, - TupleOfRefs>::compare(l, r); + return detail::TupleOfRefsLess, + TupleOfRefs>::compare(l, r); } }; diff --git a/src/watch.hpp b/src/watch.hpp index d420458..9c97b9e 100644 --- a/src/watch.hpp +++ b/src/watch.hpp @@ -24,20 +24,19 @@ namespace monitoring */ class Watch { - public: - Watch() = default; - Watch(const Watch&) = default; - Watch(Watch&&) = default; - Watch& operator=(const Watch&) = default; - Watch& operator=(Watch&&) = default; - virtual ~Watch() = default; + public: + Watch() = default; + Watch(const Watch&) = default; + Watch(Watch&&) = default; + Watch& operator=(const Watch&) = default; + Watch& operator=(Watch&&) = default; + virtual ~Watch() = default; - /** @brief Start the watch. */ - virtual void start() = 0; - - /** @brief Invoke the callback associated with the watch. */ - virtual void callback(Context ctx) = 0; + /** @brief Start the watch. */ + virtual void start() = 0; + /** @brief Invoke the callback associated with the watch. */ + virtual void callback(Context ctx) = 0; }; } // namespace monitoring -- cgit v1.2.1