- Timestamp:
- Jan 17, 2010, 11:49:48 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.