7 #ifndef _QI_EVENTLOOP_HPP_
8 # define _QI_EVENTLOOP_HPP_
11 # pragma warning( disable: 4503 ) // decorated name length
14 # include <boost/shared_ptr.hpp>
15 # include <boost/function.hpp>
23 # pragma warning( push )
24 # pragma warning( disable: 4251 )
25 # pragma warning( disable: 4996 ) // TODO: Reactivate this warning once msvc stop triggerring a warning on overloading a deprecated function
35 template<
typename T>
class Future;
37 class EventLoopPrivate;
51 EventLoop(
const std::string& name =
"eventloop");
59 bool isInThisContext()
override;
64 void start(
int nthreads = 0);
74 void setEmergencyCallback(boost::function<
void()> cb);
80 void setMaxThreads(
unsigned int max);
98 Future<
void> async(const boost::function<
void()>& callback,
uint64_t usDelay)
105 return asyncDelayImpl(callback, delay);
111 return asyncAt(callback, timepoint);
123 void post(const boost::function<
void ()>& callback,
uint64_t usDelay)
128 void post(const boost::function<
void ()>& callback, qi::
Duration delay)
130 postDelayImpl(callback, delay);
149 EventLoopPrivate *_p;
152 void postImpl(boost::function<
void()> callback)
override
156 void postDelayImpl(boost::function<
void()> callback,
qi::Duration delay);
166 template <
typename F>
168 typename std::enable_if<detail::IsAsyncBind<F>::value,
typename std::decay<decltype(cb())>::type>::type;
169 template <
typename F>
171 typename std::enable_if<!detail::IsAsyncBind<F>::value,
173 template <
typename F>
175 typename std::enable_if<detail::IsAsyncBind<F>::value,
typename std::decay<decltype(cb())>::type>::type;
176 template <
typename F>
178 typename std::enable_if<!detail::IsAsyncBind<F>::value,
209 template <
typename F>
215 template <
typename F>
221 template <
typename F>
229 template<
typename R,
typename Func,
typename ArgTrack>
233 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
234 template <typename R, typename AF, typename ARG0 comma ATYPEDECL> \
235 inline QI_API_DEPRECATED Future<R> async(const AF& fun, const ARG0& arg0 comma ADECL, qi::Duration delay = qi::Duration(0)) \
237 return detail::asyncMaybeActor(qi::bind(fun, arg0 comma AUSE), delay); \
239 template <typename R, typename AF, typename ARG0 comma ATYPEDECL> \
240 inline QI_API_DEPRECATED Future<R> async(const AF& fun, const ARG0& arg0 comma ADECL, qi::SteadyClockTimePoint timepoint) \
242 return detail::asyncMaybeActor(qi::bind(fun, arg0 comma AUSE), timepoint); \
269 # pragma warning( pop )
273 #endif // _QI_EVENTLOOP_HPP_
auto asyncDelay(F &&callback, qi::Duration delay) -> decltype(detail::asyncMaybeActor(std::forward< F >(callback), delay))
DurationType< int64_t, boost::micro > MicroSeconds
SteadyClock::time_point SteadyClockTimePoint
Steady clock time point.
Class to handle eventloop. <includename>qi/eventloop.hpp</includename> .
virtual qi::Future< void > async(const boost::function< void()> &callback, qi::SteadyClockTimePoint tp)=0
Future< R > async(const boost::function< R()> &callback, uint64_t usDelay)
Call given function once after given delay in microseconds.
dll import/export and compiler message
auto asyncDelay(F &&callback, qi::Duration delay) -> qi::Future< typename std::decay< decltype(callback())>::type >
call a callback asynchronously to be executed in delay
void startEventLoop(int nthread)
Start the eventloop with nthread threads. No-op if already started.
typename detail::FunctionImpl< A >::type Function
auto asyncMaybeActor(F &&cb, qi::Duration delay) -> typename std::enable_if< detail::IsAsyncBind< F >::value, typename std::decay< decltype(cb())>::type >::type
boost::asio::io_service & getIoService()
Get the io_service used by the global event loop.
Future< R > async(boost::function< R()> callback, uint64_t usDelay)
void post(F &&callback)
post a callback to be executed as soon as possible
#define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma)
#define QI_API_DEPRECATED_MSG(msg__)
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
EventLoop * getEventLoop()
Return the global eventloop, created on demand on first call.
auto asyncAt(F &&callback, qi::SteadyClockTimePoint timepoint) -> decltype(qi::getEventLoop() ->asyncAt(std::forward< F >(callback), timepoint))
auto asyncAt(F &&callback, qi::SteadyClockTimePoint tp) -> qi::Future< typename std::decay< decltype(callback())>::type >
call a callback asynchronously to be executed on tp
#define QI_API_DEPRECATED
Compiler flags to mark a function as deprecated. It will generate a compiler warning.