Add TimerShops
This commit is contained in:
parent
9f4a5baebb
commit
c1e21bb8d6
6 changed files with 94 additions and 2 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include "evloop.hpp"
|
#include "evloop.hpp"
|
||||||
#include "timer_items.hpp"
|
#include "timer_items.hpp"
|
||||||
#include "timer_icons.hpp"
|
#include "timer_icons.hpp"
|
||||||
|
#include "timer_shops.hpp"
|
||||||
#include "eventia/eventia.hpp"
|
#include "eventia/eventia.hpp"
|
||||||
#include "roar11/ThreadPool.hpp"
|
#include "roar11/ThreadPool.hpp"
|
||||||
#include "oro/api.hpp"
|
#include "oro/api.hpp"
|
||||||
|
@ -51,8 +52,9 @@ void test(oro::Api* api, oro::OriginsDB* db) {
|
||||||
eve::Eventia worker;
|
eve::Eventia worker;
|
||||||
pool.submit(worker.event_functor());
|
pool.submit(worker.event_functor());
|
||||||
|
|
||||||
auto timer_items = worker.make_timer<TimerItems>(3.0, &pool, api, db);
|
auto timer_items = worker.make_timer<TimerItems>(5.0, &pool, api, db);
|
||||||
auto timer_icons = worker.make_timer<TimerIcons>(20.0, &pool, api, db);
|
auto timer_icons = worker.make_timer<TimerIcons>(10.0, &pool, api, db);
|
||||||
|
auto timer_shops = worker.make_timer<TimerShops>(15.0, &pool, api, db);
|
||||||
|
|
||||||
join(pool);
|
join(pool);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ executable(meson.project_name(),
|
||||||
'timer_items.cpp',
|
'timer_items.cpp',
|
||||||
'timer_icons.cpp',
|
'timer_icons.cpp',
|
||||||
'timer_base.cpp',
|
'timer_base.cpp',
|
||||||
|
'timer_shops.cpp',
|
||||||
'oro/originsdb.cpp',
|
'oro/originsdb.cpp',
|
||||||
'gnulib/lib/base64.c',
|
'gnulib/lib/base64.c',
|
||||||
'base64.cpp',
|
'base64.cpp',
|
||||||
|
|
|
@ -117,4 +117,7 @@ void OriginsDB::update (const Icons& icons) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OriginsDB::update (const Shops& shops) {
|
||||||
|
}
|
||||||
|
|
||||||
} //namespace oro
|
} //namespace oro
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
|
|
||||||
void update (const Items& items);
|
void update (const Items& items);
|
||||||
void update (const Icons& icons);
|
void update (const Icons& icons);
|
||||||
|
void update (const Shops& shops);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
|
|
47
src/timer_shops.cpp
Normal file
47
src/timer_shops.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/* 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 "timer_shops.hpp"
|
||||||
|
#include "oro/originsdb.hpp"
|
||||||
|
#include "oro/api.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace duck {
|
||||||
|
TimerShops::TimerShops (
|
||||||
|
const eve::Context& ctx,
|
||||||
|
double timeout,
|
||||||
|
roar11::ThreadPool* pool,
|
||||||
|
oro::Api* oro_api,
|
||||||
|
oro::OriginsDB* db
|
||||||
|
) :
|
||||||
|
TimerBase(ctx, timeout, pool, oro_api, db)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimerShops::fetch_data() {
|
||||||
|
auto shops = oro_api().market_list();
|
||||||
|
|
||||||
|
{
|
||||||
|
const int next_timer = shops.first.retry_after / shops.first.rate_limit;
|
||||||
|
std::cout << "Next timer in " << next_timer << " secs\n";
|
||||||
|
set_timer(static_cast<double>(next_timer));
|
||||||
|
}
|
||||||
|
|
||||||
|
db().update(shops.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
} //namespace duck
|
38
src/timer_shops.hpp
Normal file
38
src/timer_shops.hpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "timer_base.hpp"
|
||||||
|
|
||||||
|
namespace duck {
|
||||||
|
|
||||||
|
class TimerShops : TimerBase {
|
||||||
|
public:
|
||||||
|
TimerShops (
|
||||||
|
const eve::Context& ctx,
|
||||||
|
double timeout,
|
||||||
|
roar11::ThreadPool* pool,
|
||||||
|
oro::Api* oro_api,
|
||||||
|
oro::OriginsDB* db
|
||||||
|
);
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void fetch_data() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace duck
|
Loading…
Reference in a new issue