libqi-api  release-2.5.3-2016-11-18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
future_fwd.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_FUTURE_HPP_
8 # define _QI_FUTURE_HPP_
9 
10 # include <type_traits>
11 # include <qi/api.hpp>
12 # include <qi/assert.hpp>
13 # include <vector>
14 # include <qi/atomic.hpp>
15 # include <qi/config.hpp>
16 # include <qi/trackable.hpp>
17 # include <qi/clock.hpp>
18 # include <qi/detail/mpl.hpp>
19 
20 # include <boost/shared_ptr.hpp>
21 # include <boost/make_shared.hpp>
22 # include <boost/function.hpp>
23 # include <boost/bind.hpp>
24 # include <boost/thread/recursive_mutex.hpp>
25 
26 # ifdef _MSC_VER
27 # pragma warning( push )
28 # pragma warning( disable: 4251 )
29 # pragma warning( disable: 4275 ) //std::runtime_error: no dll interface
30 # endif
31 
32 namespace qi {
33 
34  class AnyReference;
35 
36  namespace detail
37  {
38  template<typename T>
39  struct FutureType
40  {
41  using type = T;
42  using typecast = T;
43  };
44 
45  struct FutureHasNoValue {};
46  // Hold a void* for Future<void>
47  template<>
48  struct FutureType<void>
49  {
50  using type = void*;
52  };
53 
54  template <typename T>
55  class AddUnwrap
56  {};
57  }
58 
59  class Actor;
60  class Strand;
61 
62  template <typename T> class Future;
63  template <typename T> class FutureSync;
64  template <typename T> class Promise;
65 
66  namespace detail {
67  template <typename T> class FutureBaseTyped;
68 
69  template<typename FT>
70  void futureCancelAdapter(boost::weak_ptr<detail::FutureBaseTyped<FT> > wf);
71  }
72 
75  enum FutureState {
81  };
82 
87  };
88 
90  FutureTimeout_Infinite = ((int) 0x7fffffff),
92  };
93 
97  };
98 
99  using FutureUniqueId = void*;
100 
103  class QI_API FutureException : public std::runtime_error {
104  public:
112  };
113 
114  explicit FutureException(const ExceptionState &es, const std::string &str = std::string())
115  : std::runtime_error(stateToString(es) + str)
116  , _state(es)
117  {}
118 
119  inline ExceptionState state() const { return _state; }
120 
121  std::string stateToString(const ExceptionState &es);
122 
123  virtual ~FutureException() throw()
124  {}
125 
126  private:
127  ExceptionState _state;
128  };
129 
134  public:
135 
136  explicit FutureUserException(const std::string &str = std::string())
137  : FutureException(ExceptionState_FutureUserError, str)
138  {}
139 
140  virtual ~FutureUserException() throw()
141  {}
142  };
143 
148  template <typename T>
149  class Future : public detail::AddUnwrap<T> {
150  static_assert(!std::is_const<T>::value, "can't create a future of const");
151  public:
154  using TemplateValue = T;
155 
156  public:
158  : _p(boost::make_shared<detail::FutureBaseTyped<T> >())
159  {
160  }
161 
162  Future(const Future<T>& b)
163  : _p(b._p)
164  {}
165 
166  bool operator==(const Future<T> &other) const
167  {
168  return _p.get() == other._p.get();
169  }
170 
172  {
173  _p = b._p;
174  return *this;
175  }
176 
177  bool operator < (const Future<T>& b) const
178  {
179  return _p.get() < b._p.get();
180  }
181 
183  {
184  return _p.get();
185  }
186 
188  bool isValid() const
189  {
190  return _p->state() != FutureState_None;
191  }
192 
196  {
197  Promise<T> promise(async);
198  promise.setValue(v);
199  *this = promise.future();
200  }
201 
214  inline const ValueType &value(int msecs = FutureTimeout_Infinite) const
215  { return _p->value(msecs); }
216 
219  inline operator const ValueTypeCast&() const
220  { return _p->value(FutureTimeout_Infinite); }
221 
226  inline FutureState wait(int msecs = FutureTimeout_Infinite) const
227  { return _p->wait(msecs); }
228 
233  inline FutureState wait(qi::Duration duration) const
234  { return _p->wait(duration); }
235 
236  inline FutureState waitFor(qi::Duration duration) const
237  { return this->wait(duration); }
238 
244  { return _p->wait(timepoint); }
245 
247  { return this->wait(timepoint); }
248 
253  inline bool isFinished() const
254  { return _p->isFinished(); }
255 
260  inline bool isRunning() const
261  { return _p->isRunning(); }
262 
269  inline bool isCanceled() const
270  { return _p->isCanceled(); }
271 
278  inline bool hasError(int msecs = FutureTimeout_Infinite) const
279  { return _p->hasError(msecs); }
280 
288  inline bool hasValue(int msecs = FutureTimeout_Infinite) const
289  { return _p->hasValue(msecs); }
290 
297  inline const std::string &error(int msecs = FutureTimeout_Infinite) const
298  { return _p->error(msecs); }
299 
304  {
305  return FutureSync<T>(*this);
306  };
307 
314  void cancel()
315  {
316  _p->cancel(*this);
317  }
318 
323  QI_API_DEPRECATED_MSG("Method implementation removed, always returns 'true'")
324  bool isCancelable() const
325  {
326  return true;
327  }
328 
343  template <typename R, typename AF>
344  QI_API_DEPRECATED_MSG(Use 'then' instead)
345  Future<R> thenR(FutureCallbackType type, AF&& func);
346 
352  template <typename R, typename AF>
353  QI_API_DEPRECATED_MSG(Use 'then' instead)
354  Future<R> thenR(AF&& func)
355  {
356  return thenRImpl<R>(FutureCallbackType_Auto, std::forward<AF>(func));
357  }
358 
362  template <typename R, typename AF, typename Arg0, typename... Args>
363  QI_API_DEPRECATED_MSG(Use 'then' instead)
364  Future<R> thenR(AF&& func, Arg0&& arg0, Args&&... args)
365  {
366  return thenRImpl<R>(
368  qi::bind(std::forward<AF>(func), std::forward<Arg0>(arg0), std::forward<Args>(args)...));
369  }
370 
374  template <typename R, typename AF, typename Arg0, typename... Args>
375  QI_API_DEPRECATED_MSG(Use 'then' instead)
376  Future<R> thenR(FutureCallbackType type, AF&& func, Arg0&& arg0, Args&&... args)
377  {
378  return thenRImpl<R>(
379  type,
380  qi::bind(std::forward<AF>(func), arg0, std::forward<Args>(args)...));
381  }
382 
393  template <typename AF>
394  auto then(FutureCallbackType type, AF&& func)
396  {
397  return thenRImpl<typename detail::DecayAsyncResult<AF, qi::Future<T>>::type>(type, std::forward<AF>(func));
398  }
399 
403  template <typename AF>
404  auto then(AF&& func)
406  {
407  return this->then(FutureCallbackType_Auto, std::forward<AF>(func));
408  }
409 
420  template <typename R, typename AF>
421  QI_API_DEPRECATED_MSG(Use 'andThen' instead)
422  Future<R> andThenR(FutureCallbackType type, AF&& func);
423 
429  template <typename R, typename AF>
430  QI_API_DEPRECATED_MSG(Use 'andThen' instead)
431  Future<R> andThenR(AF&& func)
432  {
433  return andThenRImpl<R>(FutureCallbackType_Auto, std::forward<AF>(func));
434  }
435 
444  template <typename AF>
445  auto andThen(FutureCallbackType type, AF&& func)
447  {
448  return this->andThenRImpl<typename detail::DecayAsyncResult<AF, ValueType>::type>(type, std::forward<AF>(func));
449  }
450 
454  template <typename AF>
455  auto andThen(AF&& func)
457  {
458  return this->andThen(FutureCallbackType_Auto, std::forward<AF>(func));
459  }
460 
469  boost::function<void()> makeCanceler();
470 
471  public:
472  using Connection = boost::function<void(Future<T>)>;
473 
483  template<typename AF>
484  inline void connect(const AF& fun,
486  {
487  _p->connect(*this, fun, type);
488  }
489 #ifdef DOXYGEN
490 
496  template<typename FUNCTYPE, typename ARG0>
497  void connect(FUNCTYPE fun, ARG0 tracked, ...,
499 #else
500 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
501  template <typename AF, typename ARG0 comma ATYPEDECL> \
502  inline void connect(const AF& fun, const ARG0& arg0 comma ADECL, \
503  FutureCallbackType type = FutureCallbackType_Auto) \
504  { \
505  this->then(type, qi::bind(fun, arg0 comma AUSE)); \
506  }
507  QI_GEN(genCall)
508 #undef genCall
509 #endif
510 
511  // @deprecated since 2.5 use the overload with Strand&
512  QI_API_DEPRECATED_MSG(Use overload with 'Strand&' instead)
513  void connectWithStrand(qi::Strand* strand,
514  const boost::function<void(const Future<T>&)>& cb);
515  void connectWithStrand(qi::Strand& strand,
516  const boost::function<void(const Future<T>&)>& cb);
517 
518  // Our companion library libqitype requires a connect with same signature for all instantiations
519  inline void _connect(const boost::function<void()>& s)
520  {
521  connect(boost::bind(s));
522  }
523 
524  boost::shared_ptr<detail::FutureBaseTyped<T> > impl() { return _p;}
525  Future(boost::shared_ptr<detail::FutureBaseTyped<T> > p) :
526  _p(p)
527  {
528  QI_ASSERT(_p);
529  }
530 
531  protected:
532  // C4251 needs to have dll-interface to be used by clients of class 'qi::Future<T>'
533  boost::shared_ptr< detail::FutureBaseTyped<T> > _p;
534  friend class Promise<T>;
535  friend class FutureSync<T>;
536 
537  template<typename R>
539  template<typename FT, typename PT>
540  friend void adaptFuture(const Future<FT>& f, Promise<PT>& p, AdaptFutureOption option);
541  template<typename FT, typename PT, typename CONV>
542  friend void adaptFuture(const Future<FT>& f, Promise<PT>& p,
543  CONV converter, AdaptFutureOption option);
544  template<typename R>
545  friend void adaptFuture(Future<AnyReference>& f, Promise<R>& p);
546 
547  template<typename FT>
548  friend void detail::futureCancelAdapter(
549  boost::weak_ptr<detail::FutureBaseTyped<FT> > wf);
550  friend class detail::AddUnwrap<T>;
551 
552  private:
553  friend class ServiceBoundObject;
554  // Private forward impl to then
555  template <typename R, typename AF>
556  Future<R> andThenRImpl(FutureCallbackType type, AF&& func);
557 
558  // Private forward impl to then
559  template <typename R, typename AF>
560  Future<R> thenRImpl(FutureCallbackType type, AF&& func);
561 
562  // Nuke this when C++03 ends
563  void setOnDestroyed(boost::function<void(ValueType)> cb)
564  {
565  _p->setOnDestroyed(cb);
566  }
567 
568  static void _weakCancelCb(const boost::weak_ptr<detail::FutureBaseTyped<T> >& wfuture);
569  };
570 
579  template<typename T>
580  class FutureSync
581  {
582  public:
583  using ValueType = typename Future<T>::ValueType;
586  // This future cannot be set, so sync starts at false
587  FutureSync() : _sync(false) {}
588 
590  : _sync(true)
591  {
592  _future = b;
593  }
594 
596  : _sync(true)
597  {
598  _future = b._future;
599  b._sync = false;
600  }
601 
602  explicit FutureSync<T>(const ValueType& v)
603  : _sync(false)
604  {
605  Promise<T> promise;
606  promise.setValue(v);
607  _future = promise.future();
608  }
609 
611  {
612  _future = b;
613  _sync = true;
614  b._sync = false;
615  return *this;
616  }
617 
619  {
620  _future = b;
621  _sync = true;
622  return *this;
623  }
624 
629  {
630  if (_sync)
631  _future.value();
632  }
633 
634  operator Future<T>()
635  {
636  return async();
637  }
638 
639  bool operator < (const FutureSync<T>& b) const
640  {
641  return _future._p.get() < b._future._p.get();
642  }
643 
645  {
646  return _future.uniqueId();
647  }
648 
649  const ValueType &value(int msecs = FutureTimeout_Infinite) const { _sync = false; return _future.value(msecs); }
650  operator const typename Future<T>::ValueTypeCast&() const { _sync = false; return _future.value(); }
651  FutureState wait(int msecs = FutureTimeout_Infinite) const { _sync = false; return _future.wait(msecs); }
652  FutureState wait(qi::Duration duration) const { _sync = false; return _future.wait(duration); }
653  FutureState waitFor(qi::Duration duration) const { _sync = false; return _future.waitFor(duration); }
654  FutureState wait(qi::SteadyClock::time_point timepoint) const { _sync = false; return _future.wait(timepoint); }
655  FutureState waitUntil(qi::SteadyClock::time_point timepoint) const { _sync = false; return _future.waitUntil(timepoint); }
656  bool isValid() const { _sync = false; return _future.isValid(); }
657  bool isRunning() const { _sync = false; return _future.isRunning(); }
658  bool isFinished() const { _sync = false; return _future.isFinished(); }
659  bool isCanceled() const { _sync = false; return _future.isCanceled(); }
660  bool hasError(int msecs = FutureTimeout_Infinite) const { _sync = false; return _future.hasError(msecs); }
661  bool hasValue(int msecs = FutureTimeout_Infinite) const { _sync = false; return _future.hasValue(msecs); }
662  const std::string &error(int msecs = FutureTimeout_Infinite) const { _sync = false; return _future.error(msecs); }
663  void cancel() { _sync = false; _future.cancel(); }
664  bool isCancelable() const { _sync = false; return true; }
665  void connect(const Connection& s) { _sync = false; _future.connect(s);}
666  void _connect(const boost::function<void()>& s) { _sync = false; _future._connect(s);}
667 
668 #ifdef DOXYGEN
669 
675  template<typename FUNCTYPE, typename ARG0>
676  void connect(FUNCTYPE fun, ARG0 tracked, ...);
677 #else
678 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
679  template<typename AF, typename ARG0 comma ATYPEDECL> \
680  inline void connect(const AF& fun, const ARG0& arg0 comma ADECL) \
681  { \
682  _sync = false; \
683  connect(::qi::bind<void(FutureSync<T>)>(fun, arg0 comma AUSE)); \
684  }
685  QI_GEN(genCall)
686 #undef genCall
687 #endif
688 
690  {
691  _sync = false;
692  return _future;
693  }
694 
695  protected:
696  mutable bool _sync;
698  friend class Future<T>;
699  };
700 
705  template <typename T>
706  class Promise {
707  public:
709 
716  _f._p->reportStart();
717  _f._p->_async = async;
718  ++_f._p->_promiseCount;
719  }
720 
726  template <typename FUNC,
727  typename std::enable_if<!std::is_same<
728  typename std::decay<FUNC>::type,
729  typename std::decay<qi::Promise<T> >::type
730  >::value
731  >::type* = nullptr>
732  explicit Promise(FUNC&& cancelCallback,
734  {
735  setup(std::forward<FUNC>(cancelCallback), async);
736  ++_f._p->_promiseCount;
737  }
738 
739  explicit Promise(boost::function<void (qi::Promise<T>)> cancelCallback,
741  {
742  setup([cancelCallback](qi::Promise<T>& p){ cancelCallback(p); }, async);
743  ++_f._p->_promiseCount;
744  }
745 
747  {
748  _f = rhs._f;
749  ++_f._p->_promiseCount;
750  }
751 
753  decRefcnt();
754  }
755 
760  void setValue(const ValueType &value) {
761  _f._p->setValue(_f, value);
762  }
763 
767  void setError(const std::string &msg) {
768  _f._p->setError(_f, msg);
769  }
770 
774  void setCanceled() {
775  _f._p->setCanceled(_f);
776  }
777 
781  bool isCancelRequested() const {
782  return _f._p->isCancelRequested();
783  }
784 
786  Future<T> future() const { return _f; }
787 
792  ValueType& value() { return _f._p->_value;}
795  void trigger() { _f._p->set(_f);}
796 
802  void setOnCancel(boost::function<void (qi::Promise<T>&)> cancelCallback)
803  {
804  qi::Future<T> fut = this->future();
805  this->_f._p->setOnCancel(*this, cancelCallback);
806  }
807 
809  {
810  if (_f._p == rhs._f._p)
811  return *this;
812 
813  decRefcnt();
814  _f = rhs._f;
815  ++_f._p->_promiseCount;
816  return *this;
817  }
818 
819  protected:
820  void setup(boost::function<void (qi::Promise<T>&)> cancelCallback, FutureCallbackType async = FutureCallbackType_Auto)
821  {
822  this->_f._p->reportStart();
823  this->_f._p->setOnCancel(*this, cancelCallback);
824  this->_f._p->_async = async;
825  }
826  explicit Promise(Future<T>& f) : _f(f) {
827  ++_f._p->_promiseCount;
828  }
829  template<typename> friend class ::qi::detail::FutureBaseTyped;
831 
832  template<typename R>
834  template<typename FT, typename PT>
835  friend void adaptFuture(const Future<FT>& f, Promise<PT>& p, AdaptFutureOption option);
836  template<typename FT, typename PT, typename CONV>
837  friend void adaptFuture(const Future<FT>& f, Promise<PT>& p,
838  CONV converter, AdaptFutureOption option);
839  template<typename R>
840  friend void adaptFuture(Future<AnyReference>& f, Promise<R>& p);
841 
842  private:
843  void decRefcnt()
844  {
845  QI_ASSERT(_f._p->_promiseCount.load() > 0);
846  // this is race-free because if we reach 0 it means that this is the last Promise pointing to a state and since it
847  // is the last, no one could be trying to make a copy from it while destroying it. Also no one could be changing
848  // the promise state (from running to finished or whatever) while destroying it.
849  if (--_f._p->_promiseCount == 0 && _f.isRunning())
850  _f._p->setBroken(_f);
851  }
852  };
853 
854  namespace detail
855  {
856  class FutureBasePrivate;
858  public:
859  FutureBase();
860  ~FutureBase();
861 
862  FutureState wait(int msecs) const;
863  FutureState wait(qi::Duration duration) const;
864  FutureState wait(qi::SteadyClock::time_point timepoint) const;
865  FutureState state() const;
866  bool isRunning() const;
867  bool isFinished() const;
868  bool isCanceled() const;
869  bool isCancelRequested() const;
870  bool hasError(int msecs) const;
871  bool hasValue(int msecs) const;
872  const std::string &error(int msecs) const;
873  void reportStart();
874 
875  protected:
876  void reportValue();
877  void reportError(const std::string &message);
878  void requestCancel();
879  void reportCanceled();
880  boost::recursive_mutex& mutex();
881  void notifyFinish();
882 
883  public:
884  FutureBasePrivate *_p;
885  };
886 
887 
888  //common state shared between a Promise and multiple Futures
889  template <typename T>
890  class FutureBaseTyped : public FutureBase {
891  public:
892  using CancelCallback = boost::function<void(Promise<T>&)>;
893  using ValueType = typename FutureType<T>::type;
894  FutureBaseTyped();
896 
897  void cancel(qi::Future<T>& future);
898 
899  void callCbNotify(qi::Future<T>& future);
900 
901  /*
902  * inplace api for promise
903  */
904  void set(qi::Future<T>& future);
905  void setValue(qi::Future<T>& future, const ValueType &value);
906  void setError(qi::Future<T>& future, const std::string &message);
907  void setBroken(qi::Future<T>& future);
908  void setCanceled(qi::Future<T>& future);
909 
910  void setOnCancel(qi::Promise<T>& promise, CancelCallback onCancel);
911  void setOnDestroyed(boost::function<void (ValueType)> f);
912 
913  void connect(qi::Future<T> future,
914  const boost::function<void (qi::Future<T>)> &s,
915  FutureCallbackType type);
916 
917  const ValueType& value(int msecs) const;
918 
919  private:
920  friend class Promise<T>;
921  using CallbackType = boost::function<void(qi::Future<T>)>;
922  struct Callback
923  {
924  CallbackType callback;
925  FutureCallbackType callType;
926 
927  Callback(CallbackType callback, FutureCallbackType callType)
928  : callback(callback)
929  , callType(callType)
930  {}
931  };
932  using Callbacks = std::vector<Callback>;
933  Callbacks _onResult;
934  ValueType _value;
935  CancelCallback _onCancel;
936  boost::function<void (ValueType)> _onDestroyed;
937  FutureCallbackType _async;
938  qi::Atomic<unsigned int> _promiseCount;
939 
940  void clearCallbacks();
941  };
942  }
943 
948  template <typename T>
949  qi::Future<T> makeFutureError(const std::string& error);
950 
952  template <typename T>
954  {
955  }
956 
958  template<typename FT, typename PT>
960  {
961  void operator()(const FT& vIn, PT& vOut) { vOut = vIn;}
962  };
963 
967  template<typename R>
968  void adaptFutureUnwrap(Future<AnyReference>& f, Promise<R>& p);
969 
977  template<typename FT, typename PT>
978  void adaptFuture(const Future<FT>& f, Promise<PT>& p, AdaptFutureOption option = AdaptFutureOption_ForwardCancel);
979 
980  template<typename R>
981  void adaptFuture(Future<AnyReference>& f, Promise<R>& p);
982 
984  template<typename FT, typename PT, typename CONV>
985  void adaptFuture(const Future<FT>& f, Promise<PT>& p, CONV converter,
987 
989  template <typename T>
990  inline boost::function<void()> makeCanceler(Future<T>& future)
991  {
992  return future.makeCanceler();
993  }
994 }
995 
996 #ifdef _MSC_VER
997 # pragma warning( pop )
998 #endif
999 
1000 #endif // _QI_FUTURE_HPP_
FutureSync< T > sync()
Definition: future_fwd.hpp:303
asked for error, but there is no error
Definition: future_fwd.hpp:108
void setError(qi::Future< T > &future, const std::string &message)
Definition: future.hxx:420
AdaptFutureOption
Definition: future_fwd.hpp:94
void operator()(const FT &vIn, PT &vOut)
Definition: future_fwd.hpp:961
bool isValid() const
Definition: future_fwd.hpp:188
Future< T > _future
Definition: future_fwd.hpp:697
void setup(boost::function< void(qi::Promise< T > &)> cancelCallback, FutureCallbackType async=FutureCallbackType_Auto)
Definition: future_fwd.hpp:820
void connect(const AF &fun, FutureCallbackType type=FutureCallbackType_Auto)
Definition: future_fwd.hpp:484
The future has been canceled.
Definition: future_fwd.hpp:78
friend void adaptFuture(const Future< FT > &f, Promise< PT > &p, AdaptFutureOption option)
Feed a promise from a future of possibly different type.
Definition: future.hxx:673
#define QI_API
Definition: api.hpp:33
void PromiseNoop(qi::Promise< T > &)
Helper function that does nothing on future cancelation.
Definition: future_fwd.hpp:953
FutureTimeout
Definition: future_fwd.hpp:89
void setCanceled(qi::Future< T > &future)
Definition: future.hxx:441
void connect(const Connection &s)
Definition: future_fwd.hpp:665
typename Future< T >::Connection Connection
Definition: future_fwd.hpp:585
FutureState waitFor(qi::Duration duration) const
Definition: future_fwd.hpp:653
FutureBasePrivate * _p
Definition: future_fwd.hpp:884
auto andThen(FutureCallbackType type, AF &&func) -> qi::Future< typename detail::DecayAsyncResult< AF, ValueType >::type >
Same as then(), but the callback is called only if this future finishes with a value.
Definition: future_fwd.hpp:445
void _connect(const boost::function< void()> &s)
Definition: future_fwd.hpp:519
void setValue(qi::Future< T > &future, const ValueType &value)
Definition: future.hxx:391
bool isValid() const
Definition: future_fwd.hpp:656
friend void adaptFutureUnwrap(Future< AnyReference > &f, Promise< R > &p)
Feed a promise from a generic future which may be unwrapped if it contains itself a future...
Definition: future.hxx:663
TimePoint< SteadyClock > time_point
Definition: clock.hpp:53
void setError(const std::string &msg)
Definition: future_fwd.hpp:767
FutureState wait(qi::Duration duration) const
Definition: future_fwd.hpp:652
ValueType & value()
Definition: future_fwd.hpp:792
void set(qi::Future< T > &future)
Definition: future.hxx:406
friend void adaptFutureUnwrap(Future< AnyReference > &f, Promise< R > &p)
Feed a promise from a generic future which may be unwrapped if it contains itself a future...
Definition: future.hxx:663
void callCbNotify(qi::Future< T > &future)
Definition: future.hxx:356
#define QI_ASSERT(expr__)
Definition: assert.hpp:27
Promise(Future< T > &f)
Definition: future_fwd.hpp:826
ExceptionState state() const
Definition: future_fwd.hpp:119
const ValueType & value(int msecs=FutureTimeout_Infinite) const
Definition: future_fwd.hpp:649
bool isCanceled() const
Definition: future_fwd.hpp:659
FutureUserException(const std::string &str=std::string())
Definition: future_fwd.hpp:136
FutureState wait(qi::SteadyClock::time_point timepoint) const
Definition: future_fwd.hpp:243
dll import/export and compiler message
bool isCanceled() const
Definition: future_fwd.hpp:269
FutureSync(const Future< T > &b)
Definition: future_fwd.hpp:589
boost::function< void()> makeCanceler()
Get a functor that will cancel the future.
Definition: future.hxx:302
void trigger()
Definition: future_fwd.hpp:795
typename Future< T >::ValueType ValueType
Definition: future_fwd.hpp:583
Specialize this struct to provide conversion between future values.
Definition: future_fwd.hpp:959
qi::Future< T > makeFutureError(const std::string &error)
Helper function to return a future with the error set.
Definition: future.hxx:601
void _connect(const boost::function< void()> &s)
Definition: future_fwd.hpp:666
const std::string & error(int msecs=FutureTimeout_Infinite) const
Definition: future_fwd.hpp:662
NanoSeconds Duration
Definition: clock.hpp:32
bool isCancelRequested() const
Definition: future_fwd.hpp:781
#define QI_NOEXCEPT(cond)
Specify that a function may throw or not.
Definition: macro.hpp:305
Future< T > _f
Definition: future_fwd.hpp:830
typename detail::FutureType< void >::type ValueType
Definition: future_fwd.hpp:708
Future< T > future() const
Get a future linked to this promise. Can be called multiple times.
Definition: future_fwd.hpp:786
typename Future< T >::ValueTypeCast ValueTypeCast
Definition: future_fwd.hpp:584
Future< R > andThenR(FutureCallbackType type, AF &&func)
Same as thenR(), but the callback is called only if this future finishes with a value.
Definition: future.hxx:238
boost::shared_ptr< detail::FutureBaseTyped< T > > _p
Definition: future_fwd.hpp:533
virtual ~FutureUserException()
Definition: future_fwd.hpp:140
boost::function< void(Future< void >)> Connection
Definition: future_fwd.hpp:472
the future is not associated to a promise
Definition: future_fwd.hpp:111
const ValueType & value(int msecs) const
Definition: future.hxx:499
FutureState
Definition: future_fwd.hpp:75
FutureState wait(qi::SteadyClock::time_point timepoint) const
Definition: future_fwd.hpp:654
Future< R > async(boost::function< R()> callback, uint64_t usDelay)
Definition: eventloop.hpp:186
typename FutureType< T >::type ValueType
Definition: future_fwd.hpp:893
#define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma)
Definition: session.hpp:107
friend class ServiceBoundObject
Definition: future_fwd.hpp:553
Future< T > async()
Definition: future_fwd.hpp:689
Future is not tied to a promise.
Definition: future_fwd.hpp:76
boost::function< void()> makeCanceler(Future< T > &future)
Definition: future_fwd.hpp:990
Operation pending.
Definition: future_fwd.hpp:77
#define QI_API_DEPRECATED_MSG(msg__)
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
Definition: macro.hpp:53
FutureState waitUntil(qi::SteadyClock::time_point timepoint) const
Definition: future_fwd.hpp:655
FutureException(const ExceptionState &es, const std::string &str=std::string())
Definition: future_fwd.hpp:114
void setOnDestroyed(boost::function< void(ValueType)> f)
Definition: future.hxx:452
~FutureSync() QI_NOEXCEPT(false)
Definition: future_fwd.hpp:628
Promise(FutureCallbackType async=FutureCallbackType_Auto)
Definition: future_fwd.hpp:715
bool operator==(const Future< T > &other) const
Definition: future_fwd.hpp:166
bool isCancelable() const
Definition: future_fwd.hpp:324
typename detail::FutureType< void >::type ValueType
Definition: future_fwd.hpp:152
bool isRunning() const
Definition: future_fwd.hpp:260
void cancel()
Definition: future_fwd.hpp:314
Future(const Future< T > &b)
Definition: future_fwd.hpp:162
auto then(AF &&func) -> qi::Future< typename detail::DecayAsyncResult< AF, qi::Future< T >>::type >
Same as then(), but with type defaulted to FutureCallbackType_Auto.
Definition: future_fwd.hpp:404
void connect(qi::Future< T > future, const boost::function< void(qi::Future< T >)> &s, FutureCallbackType type)
Definition: future.hxx:458
FutureState wait(qi::Duration duration) const
Definition: future_fwd.hpp:233
auto then(FutureCallbackType type, AF &&func) -> qi::Future< typename detail::DecayAsyncResult< AF, qi::Future< T >>::type >
Execute a callback when the future is finished.
Definition: future_fwd.hpp:394
bool isCancelable() const
Definition: future_fwd.hpp:664
The operation is finished with an error.
Definition: future_fwd.hpp:79
Future< R > thenR(FutureCallbackType type, AF &&func)
Execute a callback when the future is finished.
Definition: future.hxx:199
FutureSync< T > & operator=(const Future< T > &b)
Definition: future_fwd.hpp:618
auto andThen(AF &&func) -> qi::Future< typename detail::DecayAsyncResult< AF, ValueType >::type >
Same as andThen(), but with type defaulted to FutureCallbackType_Auto.
Definition: future_fwd.hpp:455
FutureState waitFor(qi::Duration duration) const
Definition: future_fwd.hpp:236
bool isRunning() const
Definition: future_fwd.hpp:657
void setCanceled()
Definition: future_fwd.hpp:774
boost::function< void(Promise< T > &)> CancelCallback
Definition: future_fwd.hpp:892
FutureState wait(int msecs=FutureTimeout_Infinite) const
Definition: future_fwd.hpp:651
virtual ~FutureException()
Definition: future_fwd.hpp:123
FutureState wait(int msecs=FutureTimeout_Infinite) const
Definition: future_fwd.hpp:226
void cancel(qi::Future< T > &future)
Definition: future.hxx:324
bool hasValue(int msecs=FutureTimeout_Infinite) const
Definition: future_fwd.hpp:661
void setOnCancel(boost::function< void(qi::Promise< T > &)> cancelCallback)
Definition: future_fwd.hpp:802
friend void adaptFuture(const Future< FT > &f, Promise< PT > &p, AdaptFutureOption option)
Feed a promise from a future of possibly different type.
Definition: future.hxx:673
void futureCancelAdapter(boost::weak_ptr< FutureBaseTyped< FT > > wf)
Definition: future.hxx:631
Promise(FUNC &&cancelCallback, FutureCallbackType async=FutureCallbackType_Auto)
Definition: future_fwd.hpp:732
const std::string & error(int msecs=FutureTimeout_Infinite) const
Definition: future_fwd.hpp:297
Promise< T > & operator=(const Promise< T > &rhs)
Definition: future_fwd.hpp:808
bool isFinished() const
Definition: future_fwd.hpp:253
bool hasValue(int msecs=FutureTimeout_Infinite) const
Definition: future_fwd.hpp:288
const ValueType & value(int msecs=FutureTimeout_Infinite) const
Return the value associated to a Future.
Definition: future_fwd.hpp:214
FutureSync(const FutureSync< T > &b)
Definition: future_fwd.hpp:595
FutureUniqueId uniqueId() const
Definition: future_fwd.hpp:644
Promise(const qi::Promise< T > &rhs)
Definition: future_fwd.hpp:746
FutureUniqueId uniqueId() const
Definition: future_fwd.hpp:182
FutureCallbackType
Definition: future_fwd.hpp:83
void setBroken(qi::Future< T > &future)
Definition: future.hxx:431
void setValue(const ValueType &value)
Definition: future_fwd.hpp:760
FutureSync< T > & operator=(const FutureSync< T > &b)
Definition: future_fwd.hpp:610
Promise(boost::function< void(qi::Promise< T >)> cancelCallback, FutureCallbackType async=FutureCallbackType_Auto)
Definition: future_fwd.hpp:739
Future< T > & operator=(const Future< T > &b)
Definition: future_fwd.hpp:171
void setOnCancel(qi::Promise< T > &promise, CancelCallback onCancel)
Definition: future.hxx:342
bool hasError(int msecs=FutureTimeout_Infinite) const
Definition: future_fwd.hpp:660
void adaptFuture(const Future< FT > &f, Promise< PT > &p, AdaptFutureOption option)
Feed a promise from a future of possibly different type.
Definition: future.hxx:673
bool isFinished() const
Definition: future_fwd.hpp:658
void * FutureUniqueId
Definition: future_fwd.hpp:99
boost::shared_ptr< detail::FutureBaseTyped< T > > impl()
Definition: future_fwd.hpp:524
FutureState waitUntil(qi::SteadyClock::time_point timepoint) const
Definition: future_fwd.hpp:246
void connectWithStrand(qi::Strand *strand, const boost::function< void(const Future< T > &)> &cb)
Definition: future.hxx:275
The operation is finished with a value.
Definition: future_fwd.hpp:80
typename detail::FutureType< void >::typecast ValueTypeCast
Definition: future_fwd.hpp:153
std::enable_if< std::is_function< RF >::value, boost::function< RF > >::type bind(AF &&fun, Arg0 &&arg0, Args &&...args)
Definition: trackable.hxx:327
#define QI_GEN(f)
Definition: preproc.hpp:476
Future(boost::shared_ptr< detail::FutureBaseTyped< T > > p)
Definition: future_fwd.hpp:525
void adaptFutureUnwrap(Future< AnyReference > &f, Promise< R > &p)
Feed a promise from a generic future which may be unwrapped if it contains itself a future...
Definition: future.hxx:663
bool hasError(int msecs=FutureTimeout_Infinite) const
Definition: future_fwd.hpp:278