libqi-api  2.4.3.28
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
eventloop.hxx
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2013 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6 
7 #ifndef _QI_DETAILS_EVENTLOOP_HXX_
8 #define _QI_DETAILS_EVENTLOOP_HXX_
9 
10 #include <qi/detail/future_fwd.hpp>
11 #include <qi/actor.hpp>
12 
13 namespace qi
14 {
15 
16 template <typename R>
17 void nullConverter(void*, R&)
18 {}
19 
20 template <typename R>
21 inline Future<R> EventLoop::async(const boost::function<R()>& callback,
22  uint64_t usDelay)
23 {
24  return async(callback, qi::MicroSeconds(usDelay));
25 }
26 
27 namespace detail
28 {
29 
30 template <typename R, typename ARG0>
31 inline typename boost::enable_if<
32  boost::is_base_of<Actor, typename detail::Unwrap<ARG0>::type>,
33  Future<R> >::type
34  asyncMaybeActor(const ARG0& arg0, const boost::function<R()>& cb,
35  qi::Duration delay)
36 {
37  return detail::Unwrap<ARG0>::unwrap(arg0)->strand()->async(cb, delay);
38 }
39 template <typename R, typename ARG0>
40 inline typename boost::disable_if<
41  boost::is_base_of<Actor, typename detail::Unwrap<ARG0>::type>,
42  Future<R> >::type
43  asyncMaybeActor(const ARG0& arg0, const boost::function<R()>& cb,
44  qi::Duration delay)
45 {
46  return qi::getEventLoop()->async(cb, delay);
47 }
48 template <typename R, typename ARG0>
49 inline typename boost::enable_if<
50  boost::is_base_of<Actor, typename detail::Unwrap<ARG0>::type>,
51  Future<R> >::type
52  asyncMaybeActor(const ARG0& arg0, const boost::function<R()>& cb,
53  qi::SteadyClockTimePoint timepoint)
54 {
55  return detail::Unwrap<ARG0>::unwrap(arg0)->strand()->async(cb, timepoint);
56 }
57 template <typename R, typename ARG0>
58 inline typename boost::disable_if<
59  boost::is_base_of<Actor, typename detail::Unwrap<ARG0>::type>,
60  Future<R> >::type
61  asyncMaybeActor(const ARG0& arg0, const boost::function<R()>& cb,
62  qi::SteadyClockTimePoint timepoint)
63 {
64  return qi::getEventLoop()->async(cb, timepoint);
65 }
66 
67 }
68 
69 }
70 
71 #endif
boost::chrono::duration< int64_t, boost::nano > Duration
Convenience typedefs.
Definition: clock.hpp:18
void nullConverter(void *, R &)
Definition: eventloop.hxx:17
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)
Definition: eventloop.hxx:34
EventLoop * getEventLoop()
Return the global eventloop, created on demand on first call.
static T * unwrap(T &v)
Definition: mpl.hpp:22
boost::chrono::duration< int64_t, boost::micro > MicroSeconds
Definition: clock.hpp:20
uint64_t uint64_t
Cross-platform unsigned integer of length 64 bits (8 bytes).
Definition: types.hpp:81
Future< R > async(const boost::function< R()> &callback, uint64_t usDelay=0)
Call given function once after given delay in microseconds.
Definition: eventloop.hxx:21
SteadyClock::time_point SteadyClockTimePoint
Steady clock time point.
Definition: clock.hpp:203