libqi-api  release-2.5.3-2016-11-18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
actor.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2012 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6 
7 #ifndef _QI_ACTOR_HPP_
8 #define _QI_ACTOR_HPP_
9 
10 #include <qi/strand.hpp>
11 #include <boost/scoped_ptr.hpp>
12 #include <boost/function.hpp>
13 
14 namespace qi
15 {
16 
27 {
28  mutable qi::Strand _strand; // The name of this members needs to be declared before using it in the signature of
29  // the following member functions. This is a C++ restriction so do not move this down.
30 public:
31  Actor() = default;
32  Actor(const Actor&) = delete; // An actor cannot be copy-able nor move-able.
33 
35  : _strand(ec)
36  {}
37 
38  virtual ~Actor() = default;
39 
40  qi::Strand* strand() const
41  {
42  return &_strand;
43  }
44 
45  template<class... Args>
46  auto stranded(Args&&... args) const
47  -> decltype(_strand.schedulerFor(std::forward<Args>(args)...)) // TODO C++14: remove this line
48  {
49  return _strand.schedulerFor(std::forward<Args>(args)...);
50  }
51 
52  template<class... Args>
53  auto async(Args&&... args) const
54  -> decltype(_strand.async(std::forward<Args>(args)...)) // TODO C++14: remove this line
55  {
56  return _strand.async(std::forward<Args>(args)...);
57  }
58 
59  template<class... Args>
60  auto asyncDelay(Args&&... args) const
61  -> decltype(_strand.asyncDelay(std::forward<Args>(args)...)) // TODO C++14: remove this line
62  {
63  return _strand.asyncDelay(std::forward<Args>(args)...);
64  }
65 
66  template<class... Args>
67  auto asyncAt(Args&&... args) const
68  -> decltype(_strand.asyncAt(std::forward<Args>(args)...)) // TODO C++14: remove this line
69  {
70  return _strand.asyncAt(std::forward<Args>(args)...);
71  }
72 
73  void joinTasks()
74  {
75  _strand.join();
76  }
77 
78 };
79 
80 }
81 
82 #endif // _QI_ACTOR_HPP_
auto asyncDelay(F &&callback, qi::Duration delay) -> decltype(detail::asyncMaybeActor(std::forward< F >(callback), delay))
Definition: eventloop.hpp:210
#define QI_API
Definition: api.hpp:33
auto stranded(Args &&...args) const -> decltype(_strand.schedulerFor(std::forward< Args >(args)...))
Definition: actor.hpp:46
qi::Strand * strand() const
Definition: actor.hpp:40
auto asyncAt(Args &&...args) const -> decltype(_strand.asyncAt(std::forward< Args >(args)...))
Definition: actor.hpp:67
auto async(Args &&...args) const -> decltype(_strand.async(std::forward< Args >(args)...))
Definition: actor.hpp:53
Future< R > async(boost::function< R()> callback, uint64_t usDelay)
Definition: eventloop.hpp:186
void joinTasks()
Definition: actor.hpp:73
auto asyncAt(F &&callback, qi::SteadyClockTimePoint timepoint) -> decltype(qi::getEventLoop() ->asyncAt(std::forward< F >(callback), timepoint))
Definition: eventloop.hpp:216
Actor(qi::ExecutionContext &ec)
Definition: actor.hpp:34
auto asyncDelay(Args &&...args) const -> decltype(_strand.asyncDelay(std::forward< Args >(args)...))
Definition: actor.hpp:60