Changeset 2836 for code/branches/netp2/src/network/synchronisable
- Timestamp:
- Mar 23, 2009, 5:00:54 PM (16 years ago)
- Location:
- code/branches/netp2/src/network/synchronisable
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp2/src/network/synchronisable/NetworkCallbackManager.cc
r2662 r2836 32 32 33 33 namespace orxonox{ 34 34 35 35 std::set<NetworkCallbackBase*> NetworkCallbackManager::callbackSet_; 36 36 std::queue<NetworkCallbackBase*> NetworkCallbackManager::triggeredCallbacks_; … … 60 60 while( triggeredCallbacks_.empty()==false ) 61 61 { 62 triggeredCallbacks_.front()->call(); 62 //make sure callback hasn't been deleted before 63 if ( callbackSet_.find(triggeredCallbacks_.front()) != callbackSet_.end() ) 64 triggeredCallbacks_.front()->call(); 63 65 triggeredCallbacks_.pop(); 64 66 } -
code/branches/netp2/src/network/synchronisable/Synchronisable.cc
r2826 r2836 66 66 objectID=OBJECTID_UNKNOWN; 67 67 classID = static_cast<uint32_t>(-1); 68 68 69 // set dataSize to 0 70 this->dataSize_ = 0; 69 71 // set standard priority 70 72 this->setPriority( priority::normal ); … … 96 98 // delete callback function objects 97 99 if(!Identifier::isCreatingHierarchy()){ 98 for(std:: list<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)100 for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++) 99 101 delete (*it); 100 102 if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer())) … … 236 238 * @return true: if !doSync or if everything was successfully saved 237 239 */ 238 boolSynchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){240 uint32_t Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){ 239 241 if(mode==0x0) 240 242 mode=state_; 241 243 //if this tick is we dont synchronise, then abort now 242 244 if(!doSync(id, mode)) 243 return true;245 return 0; 244 246 uint32_t tempsize = 0; 245 247 if (this->classID==0) … … 250 252 251 253 assert(this->classID==this->getIdentifier()->getNetworkID()); 252 std::list<SynchronisableVariableBase*>::iterator i; 253 uint32_t size; 254 size=getSize(id, mode); 254 std::vector<SynchronisableVariableBase*>::iterator i; 255 255 256 256 // start copy header 257 257 SynchronisableHeader header(mem); 258 header.setDataSize( size ); 258 mem += SynchronisableHeader::getSize(); 259 // end copy header 260 261 262 COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << std::endl; 263 // copy to location 264 for(i=syncList.begin(); i!=syncList.end(); ++i){ 265 tempsize += (*i)->getData( mem, mode ); 266 //tempsize += (*i)->getSize( mode ); 267 } 268 269 tempsize += SynchronisableHeader::getSize(); 259 270 header.setObjectID( this->objectID ); 260 271 header.setCreatorID( this->creatorID ); 261 272 header.setClassID( this->classID ); 262 273 header.setDataAvailable( true ); 263 tempsize += SynchronisableHeader::getSize(); 264 mem += SynchronisableHeader::getSize(); 265 // end copy header 266 267 268 COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl; 269 // copy to location 270 for(i=syncList.begin(); i!=syncList.end(); ++i){ 271 (*i)->getData( mem, mode ); 272 tempsize += (*i)->getSize( mode ); 273 } 274 header.setDataSize( tempsize ); 275 276 #ifndef NDEBUG 277 uint32_t size; 278 size=getSize(id, mode); 274 279 assert(tempsize==size); 275 return true; 280 #endif 281 return tempsize; 276 282 } 277 283 … … 286 292 if(mode==0x0) 287 293 mode=state_; 288 std:: list<SynchronisableVariableBase *>::iterator i;294 std::vector<SynchronisableVariableBase *>::iterator i; 289 295 if(syncList.empty()){ 290 296 assert(0); … … 325 331 uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){ 326 332 int tsize=SynchronisableHeader::getSize(); 327 if (mode==0x0)333 if (mode==0x0) 328 334 mode=state_; 329 if (!doSync(id, mode))335 if (!doSync(id, mode)) 330 336 return 0; 331 std::list<SynchronisableVariableBase*>::iterator i; 332 for(i=syncList.begin(); i!=syncList.end(); i++){ 337 assert( mode==state_ ); 338 tsize += this->dataSize_; 339 std::vector<SynchronisableVariableBase*>::iterator i; 340 for(i=stringList.begin(); i!=stringList.end(); ++i){ 333 341 tsize += (*i)->getSize( mode ); 334 342 } -
code/branches/netp2/src/network/synchronisable/Synchronisable.h
r2826 r2836 33 33 34 34 #include <list> 35 #include <vector> 35 36 #include <map> 36 37 #include <queue> 37 38 #include <cassert> 39 #include <string> 38 40 #include "util/Math.h" 39 41 #include "util/mbool.h" … … 139 141 Synchronisable(BaseObject* creator); 140 142 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false); 141 template <class T> void unregisterVariable(T& var);143 //template <class T> void unregisterVariable(T& var); 142 144 void setObjectMode(uint8_t mode); 143 145 void setPriority(unsigned int freq){ objectFrequency_ = freq; } … … 145 147 146 148 private: 147 boolgetData(uint8_t*& men, int32_t id, uint8_t mode=0x0);149 uint32_t getData(uint8_t*& men, int32_t id, uint8_t mode=0x0); 148 150 uint32_t getSize(int32_t id, uint8_t mode=0x0); 149 151 bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false); … … 155 157 uint32_t classID; 156 158 157 std::list<SynchronisableVariableBase*> syncList; 159 std::vector<SynchronisableVariableBase*> syncList; 160 std::vector<SynchronisableVariableBase*> stringList; 161 uint32_t dataSize_; //size of all variables except strings 158 162 static uint8_t state_; // detemines wheter we are server (default) or client 159 163 bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server) … … 164 168 }; 165 169 166 template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)167 {168 if (bidirectional)169 syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));170 else171 syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));172 }173 174 template <class T> void Synchronisable::unregisterVariable(T& var){175 std::list<SynchronisableVariableBase*>::iterator it = syncList.begin();176 while(it!=syncList.end()){177 if( ((*it)->getReference()) == &var ){178 delete (*it);179 syncList.erase(it);180 return;181 }182 else183 it++;184 }185 bool unregistered_nonexistent_variable = false;186 assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:187 // the variable has not been registered before188 }189 190 170 // ================= Specialisation declarations 171 172 // template <> _NetworkExport void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 173 template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 191 174 template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); 192 175 template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); … … 200 183 template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); 201 184 template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); 185 186 template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 187 { 188 if (bidirectional) 189 syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb)); 190 else 191 syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb)); 192 if ( this->state_ == mode ) 193 this->dataSize_ += syncList.back()->getSize(state_); 194 } 195 196 197 198 // template <class T> void Synchronisable::unregisterVariable(T& var){ 199 // std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); 200 // while(it!=syncList.end()){ 201 // if( ((*it)->getReference()) == &var ){ 202 // delete (*it); 203 // syncList.erase(it); 204 // return; 205 // } 206 // else 207 // it++; 208 // } 209 // bool unregistered_nonexistent_variable = false; 210 // assert(unregistered_nonexistent_variable); //if we reach this point something went wrong: 211 // // the variable has not been registered before 212 // } 213 214 202 215 } 203 216 -
code/branches/netp2/src/network/synchronisable/SynchronisableSpecialisations.cc
r2662 r2836 29 29 30 30 #include "network/synchronisable/Synchronisable.h" 31 #include <string> 31 32 32 33 // ================ template spezialisation … … 34 35 35 36 namespace orxonox{ 37 38 // template <> void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 39 // { 40 // if (bidirectional) 41 // syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb)); 42 // else 43 // syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb)); 44 // stringList.push_back(syncList.back()); 45 // } 46 47 template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 48 { 49 if (bidirectional) 50 syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb)); 51 else 52 syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb)); 53 stringList.push_back(syncList.back()); 54 } 36 55 37 56 template <> void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional) -
code/branches/netp2/src/network/synchronisable/SynchronisableVariable.h
r2710 r2836 56 56 { 57 57 public: 58 virtual voidgetData(uint8_t*& mem, uint8_t mode)=0;58 virtual uint32_t getData(uint8_t*& mem, uint8_t mode)=0; 59 59 virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false)=0; 60 60 virtual uint32_t getSize(uint8_t mode)=0; … … 74 74 75 75 virtual inline uint8_t getMode(){ return mode_; } 76 virtual inline voidgetData(uint8_t*& mem, uint8_t mode);76 virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode); 77 77 virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false); 78 78 virtual inline uint32_t getSize(uint8_t mode); 79 79 virtual inline void* getReference(){ return (void *)&this->variable_; } 80 80 protected: 81 bool checkEquality(uint8_t* mem);82 void setAndIncrease(uint8_t*& mem);83 void getAndIncrease(uint8_t*& mem);84 uint32_t returnSize();81 inline bool checkEquality(uint8_t* mem); 82 inline void setAndIncrease(uint8_t*& mem); 83 inline void getAndIncrease(uint8_t*& mem); 84 inline uint32_t returnSize(); 85 85 86 86 T& variable_; … … 97 97 98 98 virtual inline uint8_t getMode(){ return 0x3; } //this basically is a hack ^^ 99 virtual voidgetData(uint8_t*& mem, uint8_t mode);99 virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode); 100 100 virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false); 101 virtual uint32_t getSize(uint8_t mode);101 virtual inline uint32_t getSize(uint8_t mode); 102 102 private: 103 103 T varBuffer_; … … 122 122 } 123 123 124 template <class T> voidSynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)124 template <class T> inline uint32_t SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode) 125 125 { 126 126 if ( state_ == this->mode_ ) 127 { 127 128 getAndIncrease( mem ); 129 return returnSize(); 130 } 131 else 132 return 0; 128 133 // mem += SynchronisableVariable<T>::getSize(); 129 134 } … … 143 148 // write the data 144 149 setAndIncrease( mem ); 145 // mem += SynchronisableVariable<T>::getSize();146 150 // now do a callback if neccessary 147 151 if ( callback ) 148 152 NetworkCallbackManager::triggerCallback( this->callback_ ); 149 //this->callback_->call(); 150 } 151 152 template <class T> uint32_t SynchronisableVariable<T>::getSize(uint8_t mode) 153 } 154 155 template <class T> inline uint32_t SynchronisableVariable<T>::getSize(uint8_t mode) 153 156 { 154 157 if ( mode == this->mode_ ) … … 232 235 } 233 236 234 template <class T> voidSynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode)237 template <class T> uint32_t SynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode) 235 238 { 236 239 if ( this->mode_ == mode ) … … 248 251 SynchronisableVariable<T>::getAndIncrease( mem ); 249 252 // mem += SynchronisableVariable<T>::getSize(); 253 return SynchronisableVariableBidirectional::getSize(mode); 250 254 } 251 255 … … 304 308 } 305 309 306 template <class T> uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode)310 template <class T> inline uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode) 307 311 { 308 312 return SynchronisableVariable<T>::returnSize() + sizeof(varReference_); … … 312 316 } 313 317 318 #include "network/synchronisable/SynchronisableVariableSpecialisations.h" 314 319 315 320 #endif
Note: See TracChangeset
for help on using the changeset viewer.