- Timestamp:
- Jan 17, 2010, 11:49:48 AM (15 years ago)
- Location:
- code/branches/network2/src/libraries/network/synchronisable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network2/src/libraries/network/synchronisable/Serialise.h
r6417 r6449 72 72 return *(uint32_t*)(mem) == variable->getObjectID(); 73 73 else 74 return *(uint32_t*)(mem) == OBJECTID_UNKNOWN;74 return variable == variable->getSynchronisable(*(uint32_t*)(mem)); 75 75 } 76 76 } -
code/branches/network2/src/libraries/network/synchronisable/Synchronisable.cc
r6417 r6449 101 101 deletedObjects_.push(objectID_); 102 102 } 103 // delete all Synchronisable Variables from syncList ( which are also in stringList)104 for(std::vector<SynchronisableVariableBase*>::iterator it = syncList .begin(); it!=syncList.end(); it++)103 // delete all Synchronisable Variables from syncList_ ( which are also in stringList_ ) 104 for(std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); it!=syncList_.end(); it++) 105 105 delete (*it); 106 syncList .clear();107 stringList .clear();106 syncList_.clear(); 107 stringList_.clear(); 108 108 std::map<uint32_t, Synchronisable*>::iterator it; 109 109 it = objectMap_.find(objectID_); … … 132 132 * @return pointer to the newly created synchronisable 133 133 */ 134 Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode)134 Synchronisable *Synchronisable::fabricate(uint8_t*& mem, bool diffed, uint8_t mode) 135 135 { 136 136 SynchronisableHeader header(mem); 137 138 if(!header.isDataAvailable())139 {140 mem += header.getDataSize();141 return 0;142 }143 137 144 138 COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl; … … 160 154 if (!synchronisable_creator) 161 155 { 162 mem += header.getDataSize() ; //.TODO: this suckz.... remove size from header156 mem += header.getDataSize()+SynchronisableHeader::getSize(); //.TODO: this suckz.... remove size from header 163 157 assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^ 164 158 return 0; … … 245 239 * @return true: if !doSync or if everything was successfully saved 246 240 */ 247 uint32_t Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){ 241 uint32_t Synchronisable::getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode){ 242 unsigned int test = 0; 248 243 if(mode==0x0) 249 244 mode=state_; … … 253 248 uint32_t tempsize = 0; 254 249 #ifndef NDEBUG 250 uint8_t* oldmem = mem; 255 251 if (this->classID_==0) 256 252 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; … … 270 266 // end copy header 271 267 272 273 COUT(5) << "Synchronisable getting data from objectID_: " << objectID_ << " classID_: " << classID_ << std::endl;268 CCOUT(5) << "getting data from objectID_: " << objectID_ << ", classID_: " << classID_ << std::endl; 269 // COUT(4) << "objectid: " << this->objectID_ << ":"; 274 270 // copy to location 275 for(i=syncList.begin(); i!=syncList.end(); ++i){ 276 tempsize += (*i)->getData( mem, mode ); 271 for(i=syncList_.begin(); i!=syncList_.end(); ++i){ 272 uint32_t varsize = (*i)->getData( mem, mode ); 273 // COUT(4) << " " << varsize; 274 tempsize += varsize; 275 sizes.push_back(varsize); 276 ++test; 277 277 //tempsize += (*i)->getSize( mode ); 278 278 } 279 280 tempsize += SynchronisableHeader::getSize(); 279 // COUT(4) << endl; 280 281 281 header.setObjectID( this->objectID_ ); 282 282 header.setCreatorID( this->creatorID_ ); 283 283 header.setClassID( this->classID_ ); 284 header.setDataAvailable( true );285 284 header.setDataSize( tempsize ); 285 assert( tempsize == mem-oldmem-SynchronisableHeader::getSize() ); 286 assert( test == this->getNrOfVariables() ); 287 header.setDiffed(false); 288 tempsize += SynchronisableHeader::getSize(); 286 289 287 290 #ifndef NDEBUG … … 303 306 if(mode==0x0) 304 307 mode=state_; 305 std::vector<SynchronisableVariableBase *>::iterator i; 306 if(syncList.empty()){ 308 if(syncList_.empty()){ 307 309 assert(0); 308 COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;310 COUT(4) << "Synchronisable::updateData syncList_ is empty" << std::endl; 309 311 return false; 310 312 } … … 316 318 assert(syncHeader.getCreatorID()==this->creatorID_); 317 319 assert(syncHeader.getClassID()==this->classID_); 318 if(syncHeader.isDataAvailable()==false){319 mem += syncHeader.getDataSize();320 return true;321 }322 320 323 321 mem += SynchronisableHeader::getSize(); … … 325 323 326 324 //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl; 327 for(i=syncList.begin(); i!=syncList.end(); i++) 328 { 329 assert( mem <= data+syncHeader.getDataSize() ); // always make sure we don't exceed the datasize in our stream 330 (*i)->putData( mem, mode, forceCallback ); 331 } 332 assert(mem == data+syncHeader.getDataSize()); 325 if( !syncHeader.isDiffed() ) 326 { 327 std::vector<SynchronisableVariableBase *>::iterator i; 328 for(i=syncList_.begin(); i!=syncList_.end(); i++) 329 { 330 assert( mem <= data+syncHeader.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream 331 (*i)->putData( mem, mode, forceCallback ); 332 } 333 } 334 else 335 { 336 COUT(0) << "objectID: " << this->objectID_ << endl; 337 while( mem < data+syncHeader.getDataSize()+SynchronisableHeader::getSize() ) 338 { 339 uint32_t varID = *(uint32_t*)mem; 340 COUT(0) << "varID: " << varID << endl; 341 if( varID == 22 ) 342 COUT(6) << " blub " << endl; 343 assert( varID < syncList_.size() ); 344 mem += sizeof(uint32_t); 345 syncList_[varID]->putData( mem, mode, forceCallback ); 346 } 347 } 348 assert(mem == data+syncHeader.getDataSize()+SynchronisableHeader::getSize() ); 333 349 return true; 334 350 } … … 341 357 */ 342 358 uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){ 343 int tsize=SynchronisableHeader::getSize();359 uint32_t tsize=SynchronisableHeader::getSize(); 344 360 if (mode==0x0) 345 361 mode=state_; … … 349 365 tsize += this->dataSize_; 350 366 std::vector<SynchronisableVariableBase*>::iterator i; 351 for(i=stringList .begin(); i!=stringList.end(); ++i){367 for(i=stringList_.begin(); i!=stringList_.end(); ++i){ 352 368 tsize += (*i)->getSize( mode ); 353 369 } … … 363 379 if(mode==0x0) 364 380 mode=state_; 365 return ( (this->objectMode_ & mode)!=0 && (!syncList.empty() ) ); 366 } 367 368 /** 369 * This function looks at the header located in the bytestream and checks wheter objectID_ and classID_ match with the Synchronisables ones 370 * @param mem pointer to the bytestream 371 */ 372 bool Synchronisable::isMyData(uint8_t* mem) 373 { 374 SynchronisableHeader header(mem); 375 assert(header.getObjectID()==this->objectID_); 376 return header.isDataAvailable(); 381 return ( (this->objectMode_ & mode)!=0 && (!syncList_.empty() ) ); 377 382 } 378 383 … … 397 402 else 398 403 sv = new SynchronisableVariable<std::string>(variable, mode, cb); 399 syncList .push_back(sv);400 stringList .push_back(sv);404 syncList_.push_back(sv); 405 stringList_.push_back(sv); 401 406 } 402 407 -
code/branches/network2/src/libraries/network/synchronisable/Synchronisable.h
r6417 r6449 71 71 * in an emulated bitset. 72 72 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 73 * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 073 * Bit 32 is a bool and defines whether the variables are stored in diff mode 74 74 * Byte 5 to 8: objectID_ 75 75 * Byte 9 to 12: classID_ … … 88 88 inline void setDataSize(uint32_t size) 89 89 { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); } 90 inline bool isD ataAvailable() const90 inline bool isDiffed() const 91 91 { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; } 92 inline void setD ataAvailable( bool b)92 inline void setDiffed( bool b) 93 93 { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); } 94 94 inline uint32_t getObjectID() const … … 108 108 }; 109 109 110 /** 111 * @brief: stores information about a Synchronisable (light version) 112 * 113 * This class stores the information about a Synchronisable (objectID_, dataSize) 114 * in an emulated bitset. 115 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 116 * Bit 32 is a bool and defines whether the variables are stored in diff mode 117 * Byte 5 to 8: objectID_ 118 */ 119 class _NetworkExport SynchronisableHeaderLight{ 120 private: 121 uint8_t *data_; 122 public: 123 SynchronisableHeader(uint8_t* data) 124 { data_ = data; } 125 inline static uint32_t getSize() 126 { return 16; } 127 inline uint32_t getDataSize() const 128 { return (*(uint32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits 129 inline void setDataSize(uint32_t size) 130 { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); } 131 inline bool isDiffed() const 132 { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; } 133 inline void setDiffed( bool b) 134 { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); } 135 inline uint32_t getObjectID() const 136 { return *(uint32_t*)(data_+4); } 137 inline void setObjectID(uint32_t objectID_) 138 { *(uint32_t*)(data_+4) = objectID_; } 139 inline void operator=(SynchronisableHeader& h) 140 { memcpy(data_, h.data_, getSize()); } 141 }; 110 142 111 143 /** … … 121 153 static void setClient(bool b); 122 154 123 static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);155 static Synchronisable *fabricate(uint8_t*& mem, bool diffed, uint8_t mode=0x0); 124 156 static bool deleteObject(uint32_t objectID_); 125 157 static Synchronisable *getSynchronisable(uint32_t objectID_); … … 134 166 135 167 void setSyncMode(uint8_t mode); 168 169 inline uint32_t getNrOfVariables(){ return this->syncList_.size(); } 170 inline uint32_t getVarSize( uint32_t ID ) 171 { return this->syncList_[ID]->getSize(state_); } 136 172 137 173 protected: … … 143 179 144 180 private: 145 uint32_t getData(uint8_t*& me n, int32_t id, uint8_t mode=0x0);181 uint32_t getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode); 146 182 uint32_t getSize(int32_t id, uint8_t mode=0x0); 147 183 bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false); 148 bool isMyData(uint8_t* mem);149 184 bool doSync(int32_t id, uint8_t mode=0x0); 150 185 … … 156 191 uint32_t classID_; 157 192 158 std::vector<SynchronisableVariableBase*> syncList ;159 std::vector<SynchronisableVariableBase*> stringList ;193 std::vector<SynchronisableVariableBase*> syncList_; 194 std::vector<SynchronisableVariableBase*> stringList_; 160 195 uint32_t dataSize_; //size of all variables except strings 161 196 static uint8_t state_; // detemines wheter we are server (default) or client … … 171 206 if (bidirectional) 172 207 { 173 syncList .push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb));174 this->dataSize_ += syncList .back()->getSize(state_);208 syncList_.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb)); 209 this->dataSize_ += syncList_.back()->getSize(state_); 175 210 } 176 211 else 177 212 { 178 syncList .push_back(new SynchronisableVariable<T>(variable, mode, cb));213 syncList_.push_back(new SynchronisableVariable<T>(variable, mode, cb)); 179 214 if ( this->state_ == mode ) 180 this->dataSize_ += syncList .back()->getSize(state_);215 this->dataSize_ += syncList_.back()->getSize(state_); 181 216 } 182 217 }
Note: See TracChangeset
for help on using the changeset viewer.