#pragma once #include #include #include class LorieMessageQueue { public: LorieMessageQueue(); void write(std::function func); template void call(Ret Class::* __pm, Args&& ... args) { write(std::bind(std::mem_fn(__pm), args...)); }; void run(); int get_fd(); private: int fd; pthread_mutex_t write_mutex; pthread_mutex_t read_mutex; std::queue> queue; }; template struct LorieFuncWrapper { using TFn = T (Class::*)(Args...); LorieFuncWrapper(TFn fn, Class* cl, LorieMessageQueue& q): cl(cl), ptr(fn), q(q) {}; Class* cl; TFn ptr; LorieMessageQueue& q; T operator()(Args... params) { q.call(ptr, cl, params...); //return (cl->*ptr)(params...); } }; template struct LorieFuncWrapperTypeHelper; template struct LorieFuncWrapperTypeHelper { using type = LorieFuncWrapper; }; template using LorieFuncWrapperType = typename LorieFuncWrapperTypeHelper::type; template LorieFuncWrapper LorieFuncWrap(Ret(Class::*F)(Args...), Class* c) { return LorieFuncWrapper(F, c); };