diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-03-29 10:34:05 -0400 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-03-29 10:34:46 -0400 |
commit | d1eac88d18ae7dd11033dba87b6aebb220da9064 (patch) | |
tree | 9744e38138ff853c53868d847f86e9ad58e9ac66 /src/sdevent | |
parent | 1abcb06bedadfbd40b4ec6f7e5f6a95021df3c96 (diff) | |
download | phosphor-dbus-monitor-d1eac88d18ae7dd11033dba87b6aebb220da9064.tar.gz phosphor-dbus-monitor-d1eac88d18ae7dd11033dba87b6aebb220da9064.zip |
Enable clang-format
Fix up errors and enable clang-format during CI builds.
Change-Id: I4176b81f8b85a287af9354165e09ff66aeb9fb29
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'src/sdevent')
-rw-r--r-- | src/sdevent/event.hpp | 137 | ||||
-rw-r--r-- | src/sdevent/source.hpp | 145 | ||||
-rw-r--r-- | src/sdevent/timer.hpp | 184 |
3 files changed, 224 insertions, 242 deletions
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<sd_event, EventDeleter>; */ 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<sd_event_source, SourceDeleter>; */ 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<microseconds>(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<microseconds>(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<void(source::Source&)>; + using Callback = std::function<void(source::Source&)>; - /** @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<Callback>(std::move(callback))) - { - using namespace std::chrono; - auto epoch = expires.time_since_epoch(); - auto time = duration_cast<microseconds>(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<Callback>(std::move(callback))) + { + using namespace std::chrono; + auto epoch = expires.time_since_epoch(); + auto time = duration_cast<microseconds>(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<Callback>(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<Callback>(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<Callback> cb = nullptr; + private: + source::Source src; + std::unique_ptr<Callback> cb = nullptr; - static int callCallback(sd_event_source* s, uint64_t usec, - void* context) - { - source::Source source(s); - auto c = static_cast<Callback*>(context); - (*c)(source); + static int callCallback(sd_event_source* s, uint64_t usec, void* context) + { + source::Source source(s); + auto c = static_cast<Callback*>(context); + (*c)(source); - return 0; - } + return 0; + } }; } // namespace timer } // namespace event |