From 2d62b44ebc15164a5003e3dc7072dbe6b5f6069a Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sun, 16 Aug 2020 13:41:32 +0100 Subject: [PATCH] Group parameters in a TimerSettings struct --- src/evloop.cpp | 9 +++++---- src/timer_base.cpp | 9 ++++----- src/timer_base.hpp | 15 ++++++++++++--- src/timer_oro_api.hpp | 8 +++----- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/evloop.cpp b/src/evloop.cpp index c88bb42..a097bab 100644 --- a/src/evloop.cpp +++ b/src/evloop.cpp @@ -61,6 +61,7 @@ void test(oro::Api* api, oro::OriginsDB* db, std::size_t extra_delay, std::size_ typedef TimerOroApi TimerItems; typedef TimerOroApi TimerIcons; typedef TimerOroApi TimerCreators; + typedef TimerSettings TSet; std::cout << "Running with " << thread_count << " worker threads\n"; roar11::ThreadPool pool(thread_count); @@ -71,10 +72,10 @@ void test(oro::Api* api, oro::OriginsDB* db, std::size_t extra_delay, std::size_ auto sig_int = worker.make_event(&worker); - auto timer_items = worker.make_event(0.0, ed, &pool, api, db); - auto timer_icons = worker.make_event(5.0, ed, &pool, api, db); - auto timer_shops = worker.make_event(10.0, ed, &pool, api, db); - auto timer_creat = worker.make_event(15.0, ed, &pool, api, db); + auto timer_items = worker.make_event(TSet{0.0, ed}, &pool, api, db); + auto timer_icons = worker.make_event(TSet{5.0, ed}, &pool, api, db); + auto timer_shops = worker.make_event(TSet{10.0, ed}, &pool, api, db); + auto timer_creat = worker.make_event(TSet{15.0, ed}, &pool, api, db); worker.wait(); #if !defined(NDEBUG) diff --git a/src/timer_base.cpp b/src/timer_base.cpp index cc78da6..d5235fd 100644 --- a/src/timer_base.cpp +++ b/src/timer_base.cpp @@ -55,14 +55,13 @@ namespace { TimerBase::TimerBase ( const eve::Context& ctx, oro::DBOperation type, - double min_wait, - double extra_wait, + const TimerSettings& settings, roar11::ThreadPool* pool, oro::Api* oro_api, oro::OriginsDB* db ) : - eve::Timer(initial_timer(*db, type, min_wait), ctx), - m_extra_wait(extra_wait), + eve::Timer(initial_timer(*db, type, settings.min_wait), ctx), + m_extra_delay(settings.extra_delay), m_pool(pool), m_oro_api(oro_api), m_db(db) @@ -76,7 +75,7 @@ void TimerBase::on_timer() { } void TimerBase::set_next_timer (const oro::Header& header) { - const unsigned long next_timer = time_interval(header) + m_extra_wait; + const unsigned long next_timer = time_interval(header) + m_extra_delay; std::cout << "Next timer in " << next_timer << " secs\n"; this->set_timer(static_cast(next_timer)); } diff --git a/src/timer_base.hpp b/src/timer_base.hpp index 2ea3f2b..e00e458 100644 --- a/src/timer_base.hpp +++ b/src/timer_base.hpp @@ -37,13 +37,22 @@ namespace oro { namespace duck { +struct TimerSettings { + TimerSettings (double min_wait, double extra_delay) : + min_wait(min_wait), + extra_delay(extra_delay) + { } + + double min_wait; + double extra_delay; +}; + class TimerBase : public eve::Timer { public: TimerBase ( const eve::Context& ctx, oro::DBOperation type, - double min_wait, - double extra_wait, + const TimerSettings& settings, roar11::ThreadPool* pool, oro::Api* oro_api, oro::OriginsDB* db @@ -65,7 +74,7 @@ protected: private: virtual void fetch_data() = 0; - double m_extra_wait; + double m_extra_delay; roar11::ThreadPool* m_pool; oro::Api* m_oro_api; oro::OriginsDB* m_db; diff --git a/src/timer_oro_api.hpp b/src/timer_oro_api.hpp index 359fa51..d83989f 100644 --- a/src/timer_oro_api.hpp +++ b/src/timer_oro_api.hpp @@ -33,8 +33,7 @@ class TimerOroApi : TimerBase { public: TimerOroApi ( const eve::Context& ctx, - double min_wait, - double extra_wait, + const TimerSettings& settings, roar11::ThreadPool* pool, oro::Api* oro_api, oro::OriginsDB* db @@ -71,13 +70,12 @@ namespace detail { template inline TimerOroApi::TimerOroApi ( const eve::Context& ctx, - double min_wait, - double extra_wait, + const TimerSettings& settings, roar11::ThreadPool* pool, oro::Api* oro_api, oro::OriginsDB* db ) : - TimerBase(ctx, Op, min_wait, extra_wait, pool, oro_api, db) + TimerBase(ctx, Op, settings, pool, oro_api, db) { }