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 )
34 template<
typename T>
class Future;
36 class EventLoopPrivate;
50 EventLoop(
const std::string& name =
"eventloop");
58 bool isInThisContext();
63 void start(
int nthreads = 0);
73 void setEmergencyCallback(boost::function<
void()> cb);
79 void setMaxThreads(
unsigned int max);
99 typename boost::enable_if_c<!boost::is_same<R, void>::value,
103 return ExecutionContext::async<R>(callback, delay);
105 template <
typename R>
106 typename boost::enable_if_c<!boost::is_same<R, void>::value,
108 async(
const boost::function<R()>& callback,
111 return ExecutionContext::async<R>(callback, tp);
120 void post(
const boost::function<
void ()>& callback,
uint64_t usDelay);
121 void post(
const boost::function<
void ()>& callback,
qi::Duration delay);
123 void post(
const boost::function<
void ()>& callback)
125 return post(callback, 0);
138 EventLoopPrivate *
_p;
147 template <
typename R,
typename ARG0>
148 typename boost::enable_if<
149 boost::is_base_of<Actor, typename detail::Unwrap<ARG0>::type>,
153 template <
typename R,
typename ARG0>
154 typename boost::disable_if<
155 boost::is_base_of<Actor, typename detail::Unwrap<ARG0>::type>,
159 template <
typename R,
typename ARG0>
160 typename boost::enable_if<
161 boost::is_base_of<Actor, typename detail::Unwrap<ARG0>::type>,
165 template <
typename R,
typename ARG0>
166 typename boost::disable_if<
167 boost::is_base_of<Actor, typename detail::Unwrap<ARG0>::type>,
192 template<
typename R,
typename Func,
typename ArgTrack>
195 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
196 template<typename R, typename AF, typename ARG0 comma ATYPEDECL> \
197 inline typename boost::disable_if< \
199 boost::is_same<ARG0, std::string>, boost::is_same<ARG0, char*>, \
200 boost::is_same<ARG0, const char*>, boost::is_array<ARG0> >, \
201 Future<R> >::type async(const AF& fun, const ARG0& arg0 comma ADECL, \
202 qi::Duration delay = qi::Duration(0)) \
204 return detail::asyncMaybeActor<R, ARG0>( \
205 arg0, qi::bind<R()>(fun, arg0 comma AUSE), delay); \
207 template<typename R, typename AF, typename ARG0 comma ATYPEDECL> \
208 inline Future<R> async(const AF& fun, const ARG0& arg0 comma ADECL, \
209 qi::SteadyClockTimePoint timepoint) \
211 return detail::asyncMaybeActor<R, ARG0>( \
212 arg0, qi::bind<R()>(fun, arg0 comma AUSE), timepoint); \
239 # pragma warning( pop )
243 #endif // _QI_EVENTLOOP_HPP_
Class to handle eventloop. <includename>qi/eventloop.hpp</includename> .
boost::chrono::duration< int64_t, boost::nano > Duration
Convenience typedefs.
dll import/export and compiler message
void startEventLoop(int nthread)
Start the eventloop with nthread threads. No-op if already started.
Future< R > async(boost::function< R()> callback, uint64_t usDelay=0)
boost::asio::io_service & getIoService()
Get the io_service used by the global event loop.
boost::enable_if< boost::is_base_of< Actor, typename detail::Unwrap< ARG0 >::type >, Future< R > >::type asyncMaybeActor(const ARG0 &arg0, const boost::function< R()> &cb, qi::Duration delay)
void post(const boost::function< void()> &callback)
post a callback to be executed as soon as possible
#define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma)
EventLoop * getEventLoop()
Return the global eventloop, created on demand on first call.
uint64_t uint64_t
Cross-platform unsigned integer of length 64 bits (8 bytes).
Future< R > async(const boost::function< R()> &callback, uint64_t usDelay=0)
Call given function once after given delay in microseconds.
boost::enable_if_c<!boost::is_same< R, void >::value, qi::Future< R > >::type async(const boost::function< R()> &callback, qi::SteadyClockTimePoint tp)
SteadyClock::time_point SteadyClockTimePoint
Steady clock time point.
boost::enable_if_c<!boost::is_same< R, void >::value, qi::Future< R > >::type async(const boost::function< R()> &callback, qi::Duration delay)