libqi-api  2.1.4.13
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trackable.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright (c) 2013 Aldebaran Robotics. All rights reserved.
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the COPYING file.
6  */
7 
8 
9 #ifndef _QI_TRACKABLE_HPP_
10 #define _QI_TRACKABLE_HPP_
11 
12 #include <boost/thread/mutex.hpp>
13 #include <boost/shared_ptr.hpp>
14 #include <boost/thread/condition_variable.hpp>
15 #include <boost/function.hpp>
16 
17 #include <qi/log.hpp>
18 
19 namespace qi
20 {
21 
23  class TrackableBase {};
24 
39  template<typename T>
40  class Trackable: public TrackableBase
41  {
42  public:
43  Trackable(T* ptr);
44  ~Trackable();
45 
49  boost::shared_ptr<T> lock();
50 
55  boost::weak_ptr<T> weakPtr();
56 
60  void wait();
61  protected:
65  void destroy();
66  private:
67  void _destroyed();
68 
69  boost::shared_ptr<T> _ptr;
70  boost::condition_variable _cond;
71  boost::mutex _mutex;
72  bool _wasDestroyed;
73  };
74 
75  class QI_API PointerLockException: public std::exception
76  {
77  public:
78  virtual const char* what() const throw()
79  {
80  return "Pointer Lock failed";
81  }
82  };
83 
84 #ifdef DOXYGEN
85 
90  template<typename RF, typename AF> boost::function<RF> bind(const AF& fun, ...);
91 #endif
92 
99  template<typename F, typename ARG0>
100  boost::function<F> track(const boost::function<F>& f, const ARG0& arg0);
101  template<typename F, typename ARG0>
102  boost::function<F> trackWithFallback(boost::function<void()> onFail,
103  const boost::function<F>& f, const ARG0& arg0);
104 }
105 
106 #include <qi/details/trackable.hxx>
107 #endif // _QI_TRACKABLE_HPP_
void destroy()
Definition: trackable.hxx:28
boost::weak_ptr< T > weakPtr()
Definition: trackable.hxx:73
boost::shared_ptr< T > lock()
Definition: trackable.hxx:67
Trackable(T *ptr)
Definition: trackable.hxx:21
boost::function< F > trackWithFallback(boost::function< void()> onFail, const boost::function< F > &f, const ARG0 &arg0)
Definition: trackable.hxx:199
boost::function< RF > bind(const AF &fun,...)
Common base class to templates Trackable for compile-time detection.
Definition: trackable.hpp:23
boost::function< F > track(const boost::function< F > &f, const ARG0 &arg0)
Definition: trackable.hxx:193
virtual const char * what() const
Definition: trackable.hpp:78
Convenient log macro.
#define QI_API
Definition: api.hpp:24