Changeset 1534 for code/trunk/src/network/Synchronisable.cc
- Timestamp:
- Jun 4, 2008, 8:53:10 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/Synchronisable.cc
r1505 r1534 45 45 46 46 #include "core/CoreIncludes.h" 47 // #include "core/Identifier.h" 47 48 48 49 namespace network … … 66 67 67 68 Synchronisable::~Synchronisable(){ 69 // delete callback function objects 70 if(!orxonox::Identifier::isCreatingHierarchy()) 71 for(std::list<synchronisableVariable *>::iterator it = syncList->begin(); it!=syncList->end(); it++) 72 delete (*it)->callback; 68 73 } 69 74 … … 87 92 * @param size size of the datatype the variable consists of 88 93 */ 89 void Synchronisable::registerVar(void *var, int size, variableType t, int mode ){94 void Synchronisable::registerVar(void *var, int size, variableType t, int mode, NetworkCallbackBase *cb){ 90 95 // create temporary synch.Var struct 91 96 synchronisableVariable *temp = new synchronisableVariable; … … 94 99 temp->mode = mode; 95 100 temp->type = t; 101 temp->callback = cb; 96 102 COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl; 97 103 // increase datasize … … 218 224 } 219 225 COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl; 226 bool callback=false; 220 227 switch((*i)->type){ 221 228 case DATA: 229 if((*i)->callback) // check whether this variable changed (but only if callback was set) 230 if(strncmp((char *)(*i)->var, (char *)data, (*i)->size)!=0) 231 callback=true; 222 232 memcpy((void*)(*i)->var, data, (*i)->size); 223 233 data+=(*i)->size; … … 227 237 COUT(5) << "string size: " << (*i)->size << std::endl; 228 238 data+=sizeof(int); 239 if((*i)->callback) // check whether this string changed 240 if( *(std::string *)((*i)->var) != std::string((char *)data) ) 241 callback=true; 229 242 *((std::string *)((*i)->var)) = std::string((const char*)data); 230 243 COUT(5) << "synchronisable: char: " << (const char*)data << " string: " << std::string((const char*)data) << std::endl; … … 232 245 break; 233 246 } 247 // call the callback function, if defined 248 if(callback) 249 (*i)->callback->call(); 234 250 } 235 251 return true;
Note: See TracChangeset
for help on using the changeset viewer.