Urbi SDK Remote for C++  2.7.5
utimer-callback.hh
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006, 2007, 2008, 2009, 2010, Gostai S.A.S.
00003  *
00004  * This software is provided "as is" without warranty of any kind,
00005  * either expressed or implied, including but not limited to the
00006  * implied warranties of fitness for a particular purpose.
00007  *
00008  * See the LICENSE file for more information.
00009  */
00010 
00012 
00013 #ifndef URBI_UTIMER_CALLBACK_HH
00014 # define URBI_UTIMER_CALLBACK_HH
00015 
00016 # include <string>
00017 
00018 # include <boost/function.hpp>
00019 
00020 # include <libport/ufloat.h>
00021 
00022 # include <urbi/export.hh>
00023 # include <urbi/utable.hh>
00024 
00025 namespace urbi
00026 {
00027 
00029 
00032   class URBI_SDK_API UTimerCallback
00033   {
00034   public:
00040     UTimerCallback(const std::string& objname,
00041                    ufloat period,
00042                    impl::UContextImpl* ctx);
00043     virtual ~UTimerCallback();
00044 
00045     virtual void call() = 0;
00046     void registerCallback();
00047     TimerHandle handle_get() { return handle_;}
00048     ufloat period;
00049     ufloat lastTimeCalled;
00050     std::string objname;
00051   private:
00052     impl::UContextImpl* ctx_;
00053     TimerHandle handle_;
00054   };
00055 
00056   // UTimerCallback subclasses
00057 
00058   template <class T>
00059   class UTimerCallbackobj : public UTimerCallback
00060   {
00061   public:
00062     UTimerCallbackobj(const std::string& objname,
00063                       ufloat period, T* obj,
00064                       boost::function0<void> fun, impl::UContextImpl* ctx)
00065       : UTimerCallback(objname, period, ctx)
00066       , obj(obj)
00067       , fun(fun)
00068     {
00069       registerCallback();
00070     }
00071 
00072     virtual void call()
00073     {
00074       fun();
00075     }
00076   private:
00077     T* obj;
00078     boost::function0<void> fun;
00079   };
00080 
00081 
00082 } // end namespace urbi
00083 
00084 #endif // ! URBI_UTIMER_CALLBACK_HH