Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 4, 2008, 8:53:10 PM (16 years ago)
Author:
rgrieder
Message:

merged network branch back to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/Synchronisable.cc

    r1505 r1534  
    4545
    4646#include "core/CoreIncludes.h"
     47// #include "core/Identifier.h"
    4748
    4849namespace network
     
    6667
    6768  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;
    6873  }
    6974 
     
    8792  * @param size size of the datatype the variable consists of
    8893  */
    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){
    9095    // create temporary synch.Var struct
    9196    synchronisableVariable *temp = new synchronisableVariable;
     
    9499    temp->mode = mode;
    95100    temp->type = t;
     101    temp->callback = cb;
    96102    COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl;
    97103    // increase datasize
     
    218224      }
    219225      COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
     226      bool callback=false;
    220227      switch((*i)->type){
    221228      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;
    222232        memcpy((void*)(*i)->var, data, (*i)->size);
    223233        data+=(*i)->size;
     
    227237        COUT(5) << "string size: " << (*i)->size << std::endl;
    228238        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;
    229242        *((std::string *)((*i)->var)) = std::string((const char*)data);
    230243        COUT(5) << "synchronisable: char: " << (const char*)data << " string: " << std::string((const char*)data) << std::endl;
     
    232245        break;
    233246      }
     247      // call the callback function, if defined
     248      if(callback)
     249        (*i)->callback->call();
    234250    }
    235251    return true;
Note: See TracChangeset for help on using the changeset viewer.