|
Urbi SDK Remote for C++
2.7.3
|
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 00011 #ifndef UCONTEXT_IMPL_HH 00012 # define UCONTEXT_IMPL_HH 00013 00014 #include <set> 00015 00016 #include <boost/function.hpp> 00017 #include <libport/system-warning-push.hh> 00018 #include <boost/thread.hpp> 00019 #include <libport/system-warning-pop.hh> 00020 00021 #include <libport/asio.hh> 00022 00023 #include <urbi/fwd.hh> 00024 #include <urbi/uprop.hh> 00025 00026 namespace urbi 00027 { 00032 namespace impl 00033 { 00034 class URBI_SDK_API UContextImpl 00035 { 00036 public: 00037 virtual ~UContextImpl() = 0; 00039 void init(); 00041 bool bind(const std::string& name, std::string rename = std::string()); 00043 virtual void newUObjectClass(urbi::baseURBIStarter* s) = 0; 00044 virtual void newUObjectHubClass(urbi::baseURBIStarterHub* s) = 0; 00046 virtual UObjectHub* getUObjectHub(const std::string& n); 00048 virtual UObject* getUObject(const std::string& n); 00051 virtual void uobject_unarmorAndSend(const char* str) = 0; 00052 00054 virtual void send(const char* str) = 0; 00055 00057 virtual void send(const void* buf, size_t size) = 0; 00058 00060 void send(const std::string& s); 00061 00062 virtual void call(const std::string& object, 00063 const std::string& method, 00064 UAutoValue v1 = UAutoValue(), 00065 UAutoValue v2 = UAutoValue(), 00066 UAutoValue v3 = UAutoValue(), 00067 UAutoValue v4 = UAutoValue(), 00068 UAutoValue v5 = UAutoValue(), 00069 UAutoValue v6 = UAutoValue()) = 0; 00070 00071 virtual void declare_event(const UEvent* owner) = 0; 00072 00073 virtual void emit(const std::string& object, 00074 UAutoValue& v1, 00075 UAutoValue& v2, 00076 UAutoValue& v3, 00077 UAutoValue& v4, 00078 UAutoValue& v5, 00079 UAutoValue& v6, 00080 UAutoValue& v7) = 0; 00081 00083 virtual UObjectMode getRunningMode() const = 0; 00085 virtual std::pair<int, int> kernelVersion() const = 0; 00086 00089 virtual void yield() const = 0; 00090 00092 virtual void yield_until(libport::utime_t deadline) const = 0; 00093 00096 virtual void yield_for(libport::utime_t delay) const; 00097 00101 virtual void yield_until_things_changed() const = 0; 00102 00106 virtual void side_effect_free_set(bool s) = 0; 00108 virtual bool side_effect_free_get() const = 0; 00109 virtual UVarImpl* getVarImpl() = 0; 00110 virtual UObjectImpl* getObjectImpl() = 0; 00111 virtual UGenericCallbackImpl* getGenericCallbackImpl() = 0; 00113 virtual void registerObject(UObject*o); 00114 virtual TimerHandle setTimer(UTimerCallback* cb) = 0; 00115 virtual void registerHub(UObjectHub*); 00116 virtual void removeHub(UObjectHub*) = 0; 00117 virtual void setHubUpdate(UObjectHub*, ufloat) = 0; 00119 virtual void instanciated(UObject*) = 0; 00120 typedef boost::unordered_map<std::string, UObject*> objects_type; 00121 objects_type objects; 00122 typedef boost::unordered_map<std::string, UObjectHub*> hubs_type; 00123 hubs_type hubs; 00124 std::set<void*> initialized; 00125 00131 class CleanupStack 00132 { 00133 public: 00134 CleanupStack(UContextImpl& owner); 00135 ~CleanupStack(); 00136 private: 00137 UContextImpl& owner_; 00138 }; 00139 00141 template<typename T> 00142 void addCleanup(T* ptr); 00143 00145 void addCleanup(boost::function0<void> op); 00146 00148 void pushCleanupStack(); 00150 void popCleanupStack(); 00151 00155 virtual void lock() = 0; 00157 virtual void unlock() = 0; 00159 virtual boost::asio::io_service& getIoService() = 0; 00160 00162 typedef void(*RTPSend)(UObject* rtp, const UValue& v); 00163 typedef void(*RTPSendGrouped)(UObject* rtp, const std::string&, 00164 const UValue&, 00165 libport::utime_t); 00166 RTPSend rtpSend; 00167 RTPSendGrouped rtpSendGrouped; 00168 private: 00169 typedef std::vector<std::vector<boost::function0<void> > > CleanupList; 00170 boost::thread_specific_ptr<CleanupList> cleanup_list_; 00171 }; 00172 00173 class URBI_SDK_API UObjectImpl 00174 { 00175 public: 00176 virtual ~UObjectImpl() = 0; 00177 // Called by uobject constructor 00178 virtual void initialize(UObject* owner) = 0; 00179 virtual void clean() = 0; 00180 virtual void setUpdate(ufloat period) = 0; 00181 virtual bool removeTimer(TimerHandle h) = 0; 00182 }; 00183 00184 class URBI_SDK_API UVarImpl 00185 { 00186 public: 00187 virtual ~UVarImpl() = 0; 00188 virtual void initialize(UVar* owner) = 0; 00189 virtual void clean() = 0; 00190 virtual void setOwned() = 0; 00191 virtual void sync() = 0; 00192 virtual void request() = 0; 00193 virtual void keepSynchronized() = 0; 00194 // Set the UVar value from v. Must deep-copy unless bypass mode is enabled 00195 virtual void set(const UValue& v) = 0; 00196 virtual const UValue& get() const = 0; 00197 virtual UDataType type() const = 0; 00198 virtual UValue getProp(UProperty prop) = 0; 00199 virtual void setProp(UProperty prop, const UValue& v) = 0; 00200 virtual bool setBypass(bool enable) = 0; 00201 virtual time_t timestamp() const = 0; 00202 virtual void unnotify() = 0; 00203 virtual void useRTP(bool enable) = 0; 00204 virtual void setInputPort(bool enable) = 0; 00205 }; 00206 } 00207 } 00208 00209 # include <urbi/ucontext-impl.hxx> 00210 00211 #endif