2018-11-19 23:57:28 +00:00
|
|
|
#ifndef LLARP_LOGIC_HPP
|
|
|
|
#define LLARP_LOGIC_HPP
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/mem.h>
|
|
|
|
#include <util/threadpool.h>
|
|
|
|
#include <util/timer.hpp>
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
namespace llarp
|
2018-07-09 04:26:27 +00:00
|
|
|
{
|
2018-12-10 14:14:55 +00:00
|
|
|
class Logic
|
|
|
|
{
|
2018-12-17 20:46:08 +00:00
|
|
|
public:
|
2018-12-10 14:14:55 +00:00
|
|
|
struct llarp_threadpool* thread;
|
|
|
|
struct llarp_timer_context* timer;
|
2019-07-09 13:47:24 +00:00
|
|
|
const std::thread::id ourID;
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
Logic()
|
|
|
|
: thread(llarp_init_same_process_threadpool())
|
|
|
|
, timer(llarp_init_timer())
|
2019-07-09 13:47:24 +00:00
|
|
|
, ourID(std::this_thread::get_id())
|
2018-12-10 14:14:55 +00:00
|
|
|
{
|
|
|
|
}
|
2018-06-06 12:46:26 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
/// single threaded tick
|
|
|
|
void
|
|
|
|
tick(llarp_time_t now);
|
2018-06-06 12:46:26 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
/// isolated tick
|
|
|
|
void
|
|
|
|
tick_async(llarp_time_t now);
|
2018-08-09 19:02:17 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
stop_timer();
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
stop();
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
mainloop();
|
2018-08-09 19:02:17 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
queue_job(struct llarp_thread_job job);
|
2018-04-30 18:18:18 +00:00
|
|
|
|
2019-05-15 15:54:26 +00:00
|
|
|
bool
|
2019-04-17 19:05:54 +00:00
|
|
|
queue_func(std::function< void(void) > func);
|
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
uint32_t
|
2019-01-03 21:54:26 +00:00
|
|
|
call_later(const llarp_timeout_job& job);
|
2018-05-27 12:49:10 +00:00
|
|
|
|
2019-07-28 17:13:52 +00:00
|
|
|
void
|
|
|
|
call_later(llarp_time_t later, std::function< void(void) > func);
|
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
cancel_call(uint32_t id);
|
2018-07-03 11:25:36 +00:00
|
|
|
|
2018-12-10 14:14:55 +00:00
|
|
|
void
|
|
|
|
remove_call(uint32_t id);
|
2019-05-22 17:18:19 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
can_flush() const;
|
2018-12-10 14:14:55 +00:00
|
|
|
};
|
|
|
|
} // namespace llarp
|
2018-04-30 18:18:18 +00:00
|
|
|
|
|
|
|
#endif
|