orotool/src/evloop.cpp

79 lines
2.4 KiB
C++
Raw Normal View History

2020-08-10 11:22:25 +01:00
/* Copyright 2020, Michele Santullo
* This file is part of orotool.
*
* Orotool is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Orotool is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Orotool. If not, see <http://www.gnu.org/licenses/>.
*/
#include "evloop.hpp"
#include "timer_oro_api.hpp"
#include "eventia/eventia.hpp"
#include "eventia/signal.hpp"
#include "roar11/ThreadPool.hpp"
2020-08-09 21:07:54 +01:00
#include "oro/api.hpp"
#include <iostream>
namespace duck {
namespace {
//class KeepaliveTimer : public ev::timer {
//public:
// KeepaliveTimer (ev::loop_ref& loop, RunningPool::subpool_type*) {
// this->set(loop);
// this->set<KeepaliveTimer, &KeepaliveTimer::on_timer_ev>(this);
// ev::timer::start(5.0, 5.0);
// }
// void on_timer_ev() {
// }
//};
class SignalInt : public eve::Signal {
public:
SignalInt (const eve::Context& ctx, eve::Eventia* even) :
eve::Signal(SIGINT, ctx),
m_eventia(even)
{ }
virtual void on_signal() override {
m_eventia->stop();
}
private:
eve::Eventia* m_eventia;
};
} //unnamed namespace
2020-08-11 01:33:11 +01:00
void test(oro::Api* api, oro::OriginsDB* db, std::size_t thread_count) {
typedef TimerOroApi<&oro::Api::market_list> TimerShops;
typedef TimerOroApi<&oro::Api::items_list> TimerItems;
typedef TimerOroApi<&oro::Api::items_icons> TimerIcons;
2020-08-11 02:10:43 +01:00
typedef TimerOroApi<&oro::Api::fame_list> TimerCreators;
2020-08-09 20:47:04 +01:00
std::cout << "Running with " << thread_count << " worker threads\n";
roar11::ThreadPool pool(thread_count);
2020-08-09 19:28:39 +01:00
eve::Eventia worker;
pool.submit(worker.event_functor());
auto sig_int = worker.make_event<SignalInt>(&worker);
auto timer_items = worker.make_event<TimerItems>(0.5, &pool, api, db);
auto timer_icons = worker.make_event<TimerIcons>(1.0, &pool, api, db);
auto timer_shops = worker.make_event<TimerShops>(1.5, &pool, api, db);
auto timer_creat = worker.make_event<TimerCreators>(2.0, &pool, api, db);
worker.wait();
std::cout << "all tasks completed\n";
}
} //namespace duck