2018-11-20 00:57:28 +01:00
|
|
|
#ifndef LLARP_LOGIC_HPP
|
|
|
|
#define LLARP_LOGIC_HPP
|
2018-12-12 03:52:51 +01:00
|
|
|
|
2019-11-23 05:47:08 +01:00
|
|
|
#include <ev/ev.hpp>
|
2019-01-10 20:41:51 +01:00
|
|
|
#include <util/mem.h>
|
2018-04-30 20:18:18 +02:00
|
|
|
|
2018-12-10 15:14:55 +01:00
|
|
|
namespace llarp
|
2018-07-09 06:26:27 +02:00
|
|
|
{
|
2018-12-10 15:14:55 +01:00
|
|
|
class Logic
|
|
|
|
{
|
2018-12-17 21:46:08 +01:00
|
|
|
public:
|
2019-11-14 16:06:53 +01:00
|
|
|
/// stop all operation and wait for that to die
|
2018-12-10 15:14:55 +01:00
|
|
|
void
|
|
|
|
stop();
|
2018-04-30 20:18:18 +02:00
|
|
|
|
2020-05-23 22:04:43 +02:00
|
|
|
void
|
|
|
|
Call(std::function<void(void)> func);
|
2019-04-17 21:05:54 +02:00
|
|
|
|
2019-11-23 05:47:08 +01:00
|
|
|
uint32_t
|
2020-04-07 20:38:56 +02:00
|
|
|
call_later(llarp_time_t later, std::function<void(void)> func);
|
2019-07-28 19:13:52 +02:00
|
|
|
|
2018-12-10 15:14:55 +01:00
|
|
|
void
|
|
|
|
cancel_call(uint32_t id);
|
2018-07-03 13:25:36 +02:00
|
|
|
|
2018-12-10 15:14:55 +01:00
|
|
|
void
|
|
|
|
remove_call(uint32_t id);
|
2019-05-22 19:18:19 +02:00
|
|
|
|
2019-12-10 16:21:52 +01:00
|
|
|
void
|
2020-04-07 20:38:56 +02:00
|
|
|
SetQueuer(std::function<void(std::function<void(void)>)> q);
|
2019-12-10 16:21:52 +01:00
|
|
|
|
2019-11-23 05:47:08 +01:00
|
|
|
void
|
2021-01-12 00:13:22 +01:00
|
|
|
set_event_loop(EventLoop* loop);
|
2019-11-23 05:47:08 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
clear_event_loop();
|
|
|
|
|
2019-11-14 16:06:53 +01:00
|
|
|
private:
|
2021-01-12 00:13:22 +01:00
|
|
|
EventLoop* m_Loop = nullptr;
|
2020-04-07 20:38:56 +02:00
|
|
|
std::function<void(std::function<void(void)>)> m_Queue;
|
2018-12-10 15:14:55 +01:00
|
|
|
};
|
|
|
|
} // namespace llarp
|
2018-04-30 20:18:18 +02:00
|
|
|
|
2020-05-23 22:04:43 +02:00
|
|
|
/// this used to be a macro
|
|
|
|
template <typename Logic_ptr, typename Func_t>
|
|
|
|
static bool
|
|
|
|
LogicCall(const Logic_ptr& logic, Func_t func)
|
|
|
|
{
|
|
|
|
logic->Call(std::move(func));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-30 20:18:18 +02:00
|
|
|
#endif
|