libqi-api  2.0.6.8
/home/opennao/work/master/sdk/libqi/qi/trackable.hpp
Go to the documentation of this file.
00001 #pragma once
00002 /*
00003  * Copyright (c) 2013 Aldebaran Robotics. All rights reserved.
00004  * Use of this source code is governed by a BSD-style license that can be
00005  * found in the COPYING file.
00006  */
00007 
00008 
00009 #ifndef _QI_TRACKABLE_HPP_
00010 #define _QI_TRACKABLE_HPP_
00011 
00012 #include <boost/thread/mutex.hpp>
00013 #include <boost/shared_ptr.hpp>
00014 #include <boost/thread/condition_variable.hpp>
00015 #include <boost/function.hpp>
00016 
00017 #include <qi/log.hpp>
00018 
00019 namespace qi
00020 {
00021 
00023   class TrackableBase {};
00024 
00039   template<typename T>
00040   class Trackable: public TrackableBase
00041   {
00042   public:
00043     Trackable(T* ptr);
00044     ~Trackable();
00045 
00049     boost::shared_ptr<T> lock();
00050 
00055     boost::weak_ptr<T>   weakPtr();
00056 
00060     void wait();
00061   protected:
00065     void destroy();
00066   private:
00067     void _destroyed();
00068 
00069     boost::shared_ptr<T>      _ptr;
00070     boost::condition_variable _cond;
00071     boost::mutex              _mutex;
00072     bool                      _wasDestroyed;
00073   };
00074 
00075   class QI_API PointerLockException: public std::exception
00076   {
00077   public:
00078     virtual const char* what() const throw()
00079     {
00080       return "Pointer Lock failed";
00081     }
00082   };
00083 
00084 #ifdef DOXYGEN
00085 
00090   template<typename RF, typename AF> boost::function<RF> bind(const AF& fun, ...);
00091 #endif
00092 
00099   template<typename F, typename ARG0>
00100   boost::function<F> track(const boost::function<F>& f, const ARG0& arg0);
00101   template<typename F, typename ARG0>
00102   boost::function<F> trackWithFallback(boost::function<void()> onFail,
00103       const boost::function<F>& f, const ARG0& arg0);
00104 }
00105 
00106 #include <qi/details/trackable.hxx>
00107 #endif  // _QI_TRACKABLE_HPP_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines