1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/util/thread/logic.hpp

53 lines
910 B
C++
Raw Normal View History

2018-11-20 00:57:28 +01:00
#ifndef LLARP_LOGIC_HPP
#define LLARP_LOGIC_HPP
#include <ev/ev.hpp>
#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
{
public:
/// 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
void
Call(std::function<void(void)> func);
uint32_t
call_later(llarp_time_t later, std::function<void(void)> func);
2018-12-10 15:14:55 +01:00
void
cancel_call(uint32_t id);
2018-12-10 15:14:55 +01:00
void
remove_call(uint32_t id);
void
SetQueuer(std::function<void(std::function<void(void)>)> q);
void
set_event_loop(EventLoop* loop);
void
clear_event_loop();
private:
EventLoop* m_Loop = nullptr;
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
/// 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