Urbi SDK Remote for C++  2.7.5
uobject.hxx
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009-2011, 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_UOBJECT_HXX
00014 # define URBI_UOBJECT_HXX
00015 
00016 # include <libport/debug.hh>
00017 
00018 # define URBI_BINDVARS(r, obj, v) UBindVar(obj, v);
00019 # define URBI_BINDFUNCTIONS(r, obj, v) UBindFunction(obj, v);
00020 # define URBI_BINDEVENTS(r, obj, v) UBindEvent(obj, v);
00021 
00022 namespace urbi
00023 {
00024 
00025   /*----------.
00026   | UObject.  |
00027   `----------*/
00028 
00029   inline
00030   int
00031   UObject::update()
00032   {
00033     return 0;
00034   }
00035 
00036   inline
00037   int
00038   UObject::voidfun()
00039   {
00040     return 0;
00041   }
00042 
00043   inline
00044   void
00045   UObject::clean()
00046   {
00047     aver(impl_);
00048     impl_->clean();
00049   }
00050 
00051   inline
00052   void
00053   UObject::USetUpdate(ufloat period)
00054   {
00055     aver(impl_);
00056     impl_->setUpdate(period);
00057   }
00058 
00059   inline
00060   void
00061   UObject::USync(UVar &v)
00062   {
00063     v.keepSynchronized();
00064   }
00065 
00066   inline
00067   bool
00068   UObject::removeTimer(TimerHandle h)
00069   {
00070     return impl_->removeTimer(h);
00071   }
00072 
00073   inline
00074   impl::UObjectImpl*
00075   UObject::impl_get()
00076   {
00077     return impl_;
00078   }
00079 
00080   inline
00081   libport::ThreadPool::rTaskLock
00082   UObject::getTaskLock(LockMode m, const std::string& what)
00083   {
00084     return getTaskLock(LockSpec(m), what);
00085   }
00086 
00087   inline
00088   libport::ThreadPool::rTaskLock
00089   UObject::getTaskLock(LockSpec m, const std::string& what)
00090   {
00091     GD_CATEGORY(Urbi.UObject);
00092     typedef libport::ThreadPool::rTaskLock rTaskLock;
00093     typedef libport::ThreadPool::TaskLock TaskLock;
00094     // Static in inlined functions are per-module.
00095     static rTaskLock module_lock(new TaskLock);
00096     switch(m.lockMode)
00097     {
00098     case LOCK_NONE:
00099       return 0;
00100       break;
00101     case LOCK_FUNCTION:
00102       {
00103         rTaskLock& res = taskLocks_[what];
00104         if (!res)
00105         {
00106           res = new TaskLock(m.maxQueueSize);
00107           GD_FINFO_TRACE("Creating taskLock for %s with %s: %s", what,
00108                          m.maxQueueSize, res.get());
00109         }
00110         return res;
00111       }
00112       break;
00113     case LOCK_INSTANCE:
00114       return taskLock_;
00115       break;
00116     case LOCK_CLASS:
00117       return getClassTaskLock();
00118       break;
00119     case LOCK_MODULE:
00120       return module_lock;
00121       break;
00122     }
00123     return 0;
00124   }
00125 
00126 
00127 #ifndef NO_UOBJECT_CASTER
00128   inline UObject*
00129   uvalue_caster<UObject*>::operator()(UValue& v)
00130   {
00131     if (v.type != DATA_STRING && v.type != DATA_SLOTNAME)
00132       return 0;
00133     return getUObject(*v.stringValue);
00134   }
00135   inline
00136   UValue& operator,(UValue&a, const UObject* b)
00137   {
00138     if (!b)
00139       a = "nil";
00140     else
00141       a = b->__name;
00142     a.type = DATA_SLOTNAME;
00143     return a;
00144   }
00145 
00146 #ifndef NO_ANY_POINTER_CASTER
00147   template<typename T> struct
00148   uvalue_caster<T*> {
00149     T* operator()(UValue& v)
00150     {
00151       UObject* res = uvalue_caster<UObject*>()(v);
00152       return dynamic_cast<T*>(res);
00153     }
00154   };
00155 #endif
00156 #endif
00157 }
00158 
00159 #endif // !URBI_UOBJECT_HXX