Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 17, 2008, 2:35:51 PM (16 years ago)
Author:
rgrieder
Message:

merged network branch into new network2 branch (from trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network2/src/network/Synchronisable.cc

    r1062 r1098  
    5757    datasize=0;
    5858    objectID=idCounter++;
     59    syncList = new std::list<synchronisableVariable *>;
    5960    //registerAllVariables();
    6061  }
     
    7172  void Synchronisable::registerVar(const void *var, int size, variableType t){
    7273    // create temporary synch.Var struct
    73     synchronisableVariable temp={size, var, t};
     74    synchronisableVariable *temp = new synchronisableVariable;
     75    temp->size = size;
     76    temp->var = var;
     77    temp->type = t;
     78    COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl;
    7479    // increase datasize
    7580    datasize+=sizeof(int)+size;
    76     // push temp to syncList (at the bottom)
    77     syncList.push_back(temp);
     81    //std::cout << "push temp to syncList (at the bottom) " << datasize << std::endl;
     82    COUT(5) << "Syncronisable::objectID: " << objectID << " this: " << this << " name: " << this->getIdentifier()->getName() << " networkID: " << this->getIdentifier()->getNetworkID() << std::endl;
     83    syncList->push_back(temp);
    7884  }
    7985
     
    9197  //   int totalsize=0;
    9298  //   //figure out size of data to be allocated
    93   //   for(i=syncList.begin(); i!=syncList.end(); i++){
     99  //   for(i=syncList->begin(); i!=syncList->end(); i++){
    94100  //     // increase size (size of variable and size of size of variable ;)
    95101  //     if(i->type == STRING)
     
    107113  //   //CHANGED: REMOVED DECLARATION int n=0 FROM LOOP
    108114  //   int n=0;
    109   //   for(i=syncList.begin(); n<totalsize && i!=syncList.end(); i++){
     115  //   for(i=syncList->begin(); n<totalsize && i!=syncList->end(); i++){
    110116  //     std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int));
    111117  //     n+=sizeof(int);
     
    134140  */
    135141  syncData Synchronisable::getData(unsigned char *mem){
    136     std::list<synchronisableVariable>::iterator i;
     142    //std::cout << "inside getData" << std::endl;
     143    std::list<synchronisableVariable *>::iterator i;
    137144    syncData retVal;
    138145    retVal.objectID=this->objectID;
     
    141148    retVal.data=mem;
    142149    // copy to location
    143     int n=0;
    144     for(i=syncList.begin(); n<datasize && i!=syncList.end(); ++i){
    145       //COUT(2) << "size of variable: " << i->size << std::endl;
     150    int n=0; //offset
     151    for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){
    146152      //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
    147       memcpy( (void *)(retVal.data+n), (const void*)&(i->size), sizeof(int) );
     153      memcpy( (void *)(retVal.data+n), (const void *)&((*i)->size), sizeof(int) );
    148154      n+=sizeof(int);
    149       switch(i->type){
     155      switch((*i)->type){
    150156      case DATA:
    151         std::memcpy( (void *)(retVal.data+n), (const void*)(i->var), i->size);
    152         n+=i->size;
     157        std::memcpy( (void *)(retVal.data+n), (const void*)((*i)->var), (*i)->size);
     158        n+=(*i)->size;
    153159        break;
    154160      case STRING:
    155         std::memcpy( retVal.data+n, (const void*)( ( (std::string *) i->var)->c_str()), ( (std::string *)i->var )->length()+1);
    156         n+=((std::string *) i->var)->length()+1;
     161        std::memcpy( retVal.data+n, (const void*)( ( (std::string *) (*i)->var)->c_str()), (*i)->size);
     162        n+=(*i)->size;
    157163        break;
    158164      }
     
    168174  bool Synchronisable::updateData(syncData vars){
    169175    unsigned char *data=vars.data;
    170     std::list<synchronisableVariable>::iterator i;
    171     for(i=syncList.begin(); i!=syncList.end(); i++){
    172       if((int)*data==i->size || i->type==STRING){
    173         switch(i->type){
    174       case DATA:
    175         data+=sizeof(int);
    176         memcpy((void*)i->var, data, i->size);
    177         data+=i->size;
    178         break;
    179       case STRING:
    180         i->size = (int)*data;
    181         data+=sizeof(int);
    182         *((std::string *)i->var) = std::string((const char*)data);
    183         data += i->size;
    184         break;
     176    std::list<synchronisableVariable *>::iterator i;
     177    if(syncList->empty()){
     178      COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
     179      return false;
     180    }
     181    COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " synchronising data" << std::endl;
     182    for(i=syncList->begin(); i!=syncList->end(); i++){
     183      COUT(5) << "element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
     184      if(*(int *)data==(*i)->size || (*i)->type==STRING){
     185        switch((*i)->type){
     186        case DATA:
     187          data+=sizeof(int);
     188          memcpy((void*)(*i)->var, data, (*i)->size);
     189          data+=(*i)->size;
     190          break;
     191        case STRING:
     192          (*i)->size = *(int *)data;
     193          data+=sizeof(int);
     194          *((std::string *)((*i)->var)) = std::string((const char*)data);
     195          data += (*i)->size;
     196          break;
    185197        }
    186198      } else
     
    196208  int Synchronisable::getSize(){
    197209    int tsize=0;
    198     std::list<synchronisableVariable>::iterator i;
    199     for(i=syncList.begin(); i!=syncList.end(); i++){
    200       switch(i->type){
    201     case DATA:
    202       tsize+=sizeof(int);
    203       tsize+=i->size;
    204       break;
    205     case STRING:
    206       tsize+=sizeof(int);
    207       tsize+=((std::string *)i->var)->length()+1;
    208       break;
     210    std::list<synchronisableVariable *>::iterator i;
     211    for(i=syncList->begin(); i!=syncList->end(); i++){
     212      switch((*i)->type){
     213      case DATA:
     214        tsize+=sizeof(int);
     215        tsize+=(*i)->size;
     216        break;
     217      case STRING:
     218        tsize+=sizeof(int);
     219        (*i)->size=((std::string *)(*i)->var)->length()+1;
     220        tsize+=(*i)->size;
     221        break;
    209222      }
    210223    }
Note: See TracChangeset for help on using the changeset viewer.