Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7490 for code/trunk


Ignore:
Timestamp:
Sep 26, 2010, 6:41:19 PM (14 years ago)
Author:
scheusso
Message:

cleaning up function calls a bit in order to buffer calls for not (yet) existing objects

Location:
code/trunk/src/libraries/network
Files:
5 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/network/CMakeLists.txt

    r7459 r7490  
    2525  ClientConnectionListener.cc
    2626  Connection.cc
     27  FunctionCall.cc
    2728  FunctionCallManager.cc
    2829  GamestateManager.cc
     
    4546  ClientInformation.h
    4647  Connection.h
     48  FunctionCall.h
    4749  FunctionCallManager.h
    4850  GamestateClient.h
  • code/trunk/src/libraries/network/FunctionCall.cc

    r7489 r7490  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
     23 *      Oliver Scheuss <scheusso [at] orxonox.net>, (C) 2010
    2424 *   Co-authors:
    2525 *      ...
     
    2727 */
    2828
    29 #include "FunctionCalls.h"
     29#include "FunctionCall.h"
    3030
    3131#include <cassert>
    32 #include <cstring>
    3332#include "util/MultiType.h"
    34 #include "network/NetworkFunction.h"
     33#include "NetworkFunction.h"
    3534
    3635namespace orxonox {
    37 namespace packet {
    38 
    39 #define   PACKET_FLAGS_FUNCTIONCALLS PacketFlag::Reliable
    40 #define   _PACKETID         0
    41 const unsigned int FUNCTIONCALLS_MEM_ALLOCATION = 1000;
    42 
    43 FunctionCalls::FunctionCalls()
    44  : Packet()
    45 {
    46   flags_ = flags_ | PACKET_FLAGS_FUNCTIONCALLS;
    47   currentSize_ = 2*sizeof(uint32_t); // for packetid and nrOfCalls
    48   nrOfCalls_ = 0;
    49   currentMemBlocks_ = 1;
    50   data_=new uint8_t[ FUNCTIONCALLS_MEM_ALLOCATION ];
    51   *(Type::Value *)(data_ + _PACKETID ) = Type::FunctionCalls;
    52   *(uint32_t*)(data_+sizeof(uint32_t)) = 0; // set nrOfCalls to 0
    53 }
    54 
    55 FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID )
    56   : Packet(data, clientID)
    57 {
    58 }
    59 
    60 FunctionCalls::~FunctionCalls()
    61 {
    62 }
    63 
    64 
    65 bool FunctionCalls::process(){
    66   assert(isDataENetAllocated());
    67   uint8_t* temp = data_+sizeof(uint32_t); //skip packetid
    68   this->nrOfCalls_ = *(uint32_t*)temp;
    69   temp += sizeof(uint32_t);
    70   for( unsigned int i = 0; i<this->nrOfCalls_; i++ )
    71   {
    72     uint32_t functionID = *(uint32_t*)temp;
    73     bool isStatic = *(uint8_t*)(temp+sizeof(uint32_t));
    74     if( isStatic )
    75     {
    76       MultiType mt1, mt2, mt3, mt4, mt5;
    77       NetworkFunctionStatic *fct = NetworkFunctionStatic::getFunction( functionID );
    78       uint32_t nrOfArguments = *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t));
    79       temp+=2*sizeof(uint32_t)+sizeof(uint8_t);
    80       switch(nrOfArguments)
    81       {
    82         case 0:
    83           fct->call();
    84           break;
    85         case 1:
    86           mt1.importData(temp);
    87           fct->call(mt1);
    88           break;
    89         case 2:
    90           mt1.importData(temp);
    91           mt2.importData(temp);
    92           fct->call(mt1, mt2);
    93           break;
    94         case 3:
    95           mt1.importData(temp);
    96           mt2.importData(temp);
    97           mt3.importData(temp);
    98           fct->call(mt1, mt2, mt3);
    99           break;
    100         case 4:
    101           mt1.importData(temp);
    102           mt2.importData(temp);
    103           mt3.importData(temp);
    104           mt4.importData(temp);
    105           fct->call(mt1, mt2, mt3, mt4);
    106           break;
    107         case 5:
    108           mt1.importData(temp);
    109           mt2.importData(temp);
    110           mt3.importData(temp);
    111           mt4.importData(temp);
    112           mt5.importData(temp);
    113           fct->call(mt1, mt2, mt3, mt4, mt5);
    114           break;
    115         default:
    116           assert(0);
    117       }
    118     }
    119     else // not a static function, so also handle the objectID
    120     {
    121       MultiType mt1, mt2, mt3, mt4, mt5;
    122       NetworkMemberFunctionBase *fct = NetworkMemberFunctionBase::getFunction( functionID );
    123       uint32_t nrOfArguments = *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t));
    124       uint32_t objectID = *(uint32_t*)(temp+2*sizeof(uint32_t)+sizeof(uint8_t));
    125       temp+=3*sizeof(uint32_t)+sizeof(uint8_t);
    126       switch(nrOfArguments)
    127       {
    128         case 0:
    129           fct->call(objectID);
    130           break;
    131         case 1:
    132           mt1.importData(temp);
    133           fct->call(objectID, mt1);
    134           break;
    135         case 2:
    136           mt1.importData(temp);
    137           mt2.importData(temp);
    138           fct->call(objectID, mt1, mt2);
    139           break;
    140         case 3:
    141           mt1.importData(temp);
    142           mt2.importData(temp);
    143           mt3.importData(temp);
    144           fct->call(objectID, mt1, mt2, mt3);
    145           break;
    146         case 4:
    147           mt1.importData(temp);
    148           mt2.importData(temp);
    149           mt3.importData(temp);
    150           mt4.importData(temp);
    151           fct->call(objectID, mt1, mt2, mt3, mt4);
    152           break;
    153         case 5:
    154           mt1.importData(temp);
    155           mt2.importData(temp);
    156           mt3.importData(temp);
    157           mt4.importData(temp);
    158           mt5.importData(temp);
    159           fct->call(objectID, mt1, mt2, mt3, mt4, mt5);
    160           break;
    161         default:
    162           assert(0);
    163           break;
    164       }
    165     }
    166   }
    167   delete this;
     36
     37FunctionCall::FunctionCall()
     38 : nrOfArguments_(-1), objectID_(OBJECTID_UNKNOWN), size_(0)
     39{
     40}
     41
     42FunctionCall::~FunctionCall()
     43{
     44}
     45
     46
     47bool FunctionCall::execute(){
     48  if( this->bIsStatic_ )
     49  {
     50    NetworkFunctionStatic *fct = NetworkFunctionStatic::getFunction( this->functionID_ );
     51    assert( this->nrOfArguments_==this->arguments_.size() );
     52    switch(this->nrOfArguments_)
     53    {
     54      case 0:
     55        fct->call();
     56        break;
     57      case 1:
     58        fct->call(this->arguments_[0]);
     59        break;
     60      case 2:
     61        fct->call(this->arguments_[0], this->arguments_[1]);
     62        break;
     63      case 3:
     64        fct->call(this->arguments_[0], this->arguments_[1], this->arguments_[2]);
     65        break;
     66      case 4:
     67        fct->call(this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]);
     68        break;
     69      case 5:
     70        fct->call(this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]);
     71        break;
     72      default:
     73        assert(0);
     74    }
     75  }
     76  else // not a static function, so also handle with the objectID
     77  {
     78    NetworkMemberFunctionBase *fct = NetworkMemberFunctionBase::getFunction( this->functionID_ );
     79    switch(this->nrOfArguments_)
     80    {
     81      case 0:
     82        fct->call(this->objectID_);
     83        break;
     84      case 1:
     85        fct->call(this->objectID_, this->arguments_[0]);
     86        break;
     87      case 2:
     88        fct->call(this->objectID_, this->arguments_[0], this->arguments_[1]);
     89        break;
     90      case 3:
     91        fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2]);
     92        break;
     93      case 4:
     94        fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]);
     95        break;
     96      case 5:
     97        fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]);
     98        break;
     99      default:
     100        assert(0);
     101    }
     102  }
    168103  return true;
    169104}
    170105
    171 void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
    172   assert(!isDataENetAllocated());
     106void FunctionCall::setCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
    173107
    174108  // first determine the size that has to be reserved for this call
     
    179113    nrOfArguments++;
    180114    callsize += mt1->getNetworkSize();
     115    this->arguments_.push_back(*mt1);
    181116    if(mt2)
    182117    {
    183118      nrOfArguments++;
    184119      callsize += mt2->getNetworkSize();
     120      this->arguments_.push_back(*mt2);
    185121      if(mt3)
    186122      {
    187123        nrOfArguments++;
    188124        callsize += mt3->getNetworkSize();
     125        this->arguments_.push_back(*mt3);
    189126        if(mt4)
    190127        {
    191128          nrOfArguments++;
    192129          callsize += mt4->getNetworkSize();
     130          this->arguments_.push_back(*mt4);
    193131          if(mt5)
    194132          {
    195133            nrOfArguments++;
    196134            callsize += mt5->getNetworkSize();
     135            this->arguments_.push_back(*mt5);
    197136          }
    198137        }
     
    200139    }
    201140  }
    202 
    203   // now allocated mem if neccessary
    204   if( currentSize_ + callsize > currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION )
    205   {
    206     currentMemBlocks_ = (currentSize_ + callsize)%FUNCTIONCALLS_MEM_ALLOCATION+1;
    207     uint8_t *temp = new uint8_t[currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION];
    208     memcpy( temp, data_, currentSize_ );
    209     delete[] data_;
    210     data_ = temp;
    211   }
    212 
    213   // now serialise the mt values and copy the function id and isStatic
    214   uint8_t* temp = data_+currentSize_;
    215   *(uint32_t*)(data_+sizeof(uint32_t)) = *(uint32_t*)(data_+sizeof(uint32_t))+1; // increase number of calls
    216   *(uint32_t*)temp = networkID;
    217   *(uint8_t*)(temp+sizeof(uint32_t)) = true;
    218   *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t)) = nrOfArguments;
    219   temp += 2*sizeof(uint32_t)+sizeof(uint8_t);
    220   if(mt1)
    221   {
    222     mt1->exportData( temp ); //temp gets automatically increased
    223     if(mt2)
    224     {
    225       mt2->exportData( temp ); //temp gets automatically increased
    226       if(mt3)
    227       {
    228         mt3->exportData( temp ); //temp gets automatically increased
    229         if(mt4)
    230         {
    231           mt4->exportData( temp ); //temp gets automatically increased
    232           if(mt5)
    233           {
    234             mt5->exportData( temp ); //temp gets automatically increased
    235           }
    236         }
    237       }
    238     }
    239   }
    240   //currentSize_ += callsize;
    241   currentSize_ = temp-data_;
    242 
    243 }
    244 
    245 void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
    246   assert(!isDataENetAllocated());
     141  this->nrOfArguments_ = nrOfArguments;
     142  this->size_ = callsize;
     143  this->bIsStatic_ = true;
     144  this->functionID_ = networkID;
     145}
     146
     147void FunctionCall::setCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
    247148
    248149  // first determine the size that has to be reserved for this call
    249   uint32_t callsize = 3*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and the objectID
     150  uint32_t callsize = 3*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and the objectID and bIsStatic
    250151  uint32_t nrOfArguments = 0;
    251152  if(mt1)
     
    253154    nrOfArguments++;
    254155    callsize += mt1->getNetworkSize();
     156    this->arguments_.push_back(*mt1);
    255157    if(mt2)
    256158    {
    257159      nrOfArguments++;
    258160      callsize += mt2->getNetworkSize();
     161      this->arguments_.push_back(*mt2);
    259162      if(mt3)
    260163      {
    261164        nrOfArguments++;
    262165        callsize += mt3->getNetworkSize();
     166        this->arguments_.push_back(*mt3);
    263167        if(mt4)
    264168        {
    265169          nrOfArguments++;
    266170          callsize += mt4->getNetworkSize();
     171          this->arguments_.push_back(*mt4);
    267172          if(mt5)
    268173          {
    269174            nrOfArguments++;
    270175            callsize += mt5->getNetworkSize();
     176            this->arguments_.push_back(*mt5);
    271177          }
    272178        }
     
    274180    }
    275181  }
    276 
    277   // now allocated mem if neccessary
    278   if( currentSize_ + callsize > currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION )
    279   {
    280     currentMemBlocks_ = (currentSize_ + callsize)%FUNCTIONCALLS_MEM_ALLOCATION+1;
    281     uint8_t *temp = new uint8_t[currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION];
    282     memcpy( temp, data_, currentSize_ );
    283     delete[] data_;
    284     data_ = temp;
    285   }
    286 
    287   // now serialise the mt values and copy the function id
    288   uint8_t* temp = data_+currentSize_;
    289   *(uint32_t*)(data_+sizeof(uint32_t)) = *(uint32_t*)(data_+sizeof(uint32_t))+1; // increase number of calls
    290   *(uint32_t*)temp = networkID;
    291   *(uint8_t*)(temp+sizeof(uint32_t)) = false;
    292   *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t)) = nrOfArguments;
    293   *(uint32_t*)(temp+2*sizeof(uint32_t)+sizeof(uint8_t)) = objectID;
    294   temp += 3*sizeof(uint32_t)+sizeof(uint8_t);
    295   if(mt1)
    296   {
    297     mt1->exportData( temp ); //temp gets automatically increased
    298     if(mt2)
    299     {
    300       mt2->exportData( temp ); //temp gets automatically increased
    301       if(mt3)
    302       {
    303         mt3->exportData( temp ); //temp gets automatically increased
    304         if(mt4)
    305         {
    306           mt4->exportData( temp ); //temp gets automatically increased
    307           if(mt5)
    308           {
    309             mt5->exportData( temp ); //temp gets automatically increased
    310           }
    311         }
    312       }
    313     }
    314   }
    315   currentSize_ += callsize;
    316 
    317 }
    318 
    319 
    320 } //namespace packet
     182  this->nrOfArguments_ = nrOfArguments;
     183  this->bIsStatic_ = false;
     184  this->functionID_ = networkID;
     185  this->size_ = callsize;
     186  this->objectID_ = objectID;
     187}
     188
     189void FunctionCall::loadData(uint8_t*& mem)
     190{
     191  this->functionID_ = *(uint32_t*)mem;
     192  this->bIsStatic_ = *(uint8_t*)(mem+sizeof(uint32_t));
     193  this->nrOfArguments_ = *(uint32_t*)(mem+sizeof(uint32_t)+sizeof(uint8_t));
     194  if( this->bIsStatic_ )
     195  {
     196    mem += 2*sizeof(uint32_t)+sizeof(uint8_t);
     197  }
     198  else
     199  {
     200    this->objectID_ = *(uint32_t*)(mem+2*sizeof(uint32_t)+sizeof(uint8_t));
     201    mem += 3*sizeof(uint32_t)+sizeof(uint8_t);
     202  }
     203  for( unsigned int i=0; i<this->nrOfArguments_; ++i )
     204  {
     205    this->arguments_.push_back(MultiType());
     206    this->arguments_.back().importData(mem);
     207  }
     208}
     209
     210void FunctionCall::saveData(uint8_t*& mem)
     211{
     212  // now serialise the mt values and copy the function id and isStatic
     213  *(uint32_t*)mem = this->functionID_;
     214  *(uint8_t*)(mem+sizeof(uint32_t)) = this->bIsStatic_;
     215  *(uint32_t*)(mem+sizeof(uint32_t)+sizeof(uint8_t)) = this->nrOfArguments_;
     216  if( this->bIsStatic_ )
     217  {
     218    mem += 2*sizeof(uint32_t)+sizeof(uint8_t);
     219  }
     220  {
     221    *(uint32_t*)(mem+2*sizeof(uint32_t)+sizeof(uint8_t)) = this->objectID_;
     222    mem += 3*sizeof(uint32_t)+sizeof(uint8_t);
     223  }
     224  for( std::vector<MultiType>::iterator it = this->arguments_.begin(); it!=this->arguments_.end(); ++it )
     225  {
     226    it->exportData( mem );
     227  }
     228}
     229
     230
     231
    321232} //namespace orxonox
  • code/trunk/src/libraries/network/FunctionCall.h

    r7489 r7490  
    2727 */
    2828
    29 #ifndef _FunctionCalls_H__
    30 #define _FunctionCalls_H__
     29#ifndef _FunctionCall_H__
     30#define _FunctionCall_H__
    3131
    3232#include "network/NetworkPrereqs.h"
     33#include "util/UtilPrereqs.h"
    3334
    3435#include <cassert>
    35 #include "util/UtilPrereqs.h"
    36 #include "Packet.h"
     36#include <vector>
    3737
    3838namespace orxonox {
    39 
    40 namespace packet {
    4139/**
    4240    @author
     
    4442
    4543
    46 class _NetworkExport FunctionCalls : public Packet
     44class _NetworkExport FunctionCall
    4745{
    4846public:
    49   FunctionCalls();
    50   FunctionCalls( uint8_t* data, unsigned int clientID );
    51   ~FunctionCalls();
     47  FunctionCall();
     48  ~FunctionCall();
    5249
    53   inline unsigned int getSize() const
    54     { assert(!this->isDataENetAllocated()); return currentSize_; }
    55   bool process();
     50  inline unsigned int getSize() const { return this->size_; }
     51  bool execute();
    5652
    57   void addCallStatic( uint32_t networkID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
    58   void addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
     53  void setCallStatic( uint32_t networkID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
     54  void setCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
     55 
     56  void saveData( uint8_t*& mem );
     57  void loadData( uint8_t*& mem );
    5958private:
    60   uint32_t nrOfCalls_;
    61   unsigned int clientID_;
    62   uint32_t currentSize_;
    63   uint32_t currentMemBlocks_; // this saves the number of memory blocks (of size FUNCTIONCALLS_MEM_ALLOCATION) allocated
     59  uint32_t                  nrOfArguments_;
     60  bool                      bIsStatic_;
     61  uint32_t                  functionID_;
     62  uint32_t                  objectID_;
     63  uint32_t                  size_;
     64  std::vector<MultiType>    arguments_;
    6465};
    6566
    66 } //namespace packet
    6767} //namespace orxonox
    6868
  • code/trunk/src/libraries/network/NetworkPrereqs.h

    r7163 r7490  
    115115  class ClientInformation;
    116116  class Connection;
     117  class FunctionCall;
    117118  class FunctionCallManager;
    118119  class GamestateClient;
  • code/trunk/src/libraries/network/packet/FunctionCalls.cc

    r6417 r7490  
    3030
    3131#include <cassert>
    32 #include <cstring>
    33 #include "util/MultiType.h"
    34 #include "network/NetworkFunction.h"
     32#include "network/FunctionCall.h"
    3533
    3634namespace orxonox {
     
    4644  flags_ = flags_ | PACKET_FLAGS_FUNCTIONCALLS;
    4745  currentSize_ = 2*sizeof(uint32_t); // for packetid and nrOfCalls
    48   nrOfCalls_ = 0;
    49   currentMemBlocks_ = 1;
    50   data_=new uint8_t[ FUNCTIONCALLS_MEM_ALLOCATION ];
    51   *(Type::Value *)(data_ + _PACKETID ) = Type::FunctionCalls;
    52   *(uint32_t*)(data_+sizeof(uint32_t)) = 0; // set nrOfCalls to 0
    5346}
    5447
     
    6558bool FunctionCalls::process(){
    6659  assert(isDataENetAllocated());
     60 
    6761  uint8_t* temp = data_+sizeof(uint32_t); //skip packetid
    68   this->nrOfCalls_ = *(uint32_t*)temp;
     62  uint32_t nrOfCalls = *(uint32_t*)temp;
    6963  temp += sizeof(uint32_t);
    70   for( unsigned int i = 0; i<this->nrOfCalls_; i++ )
     64  for( unsigned int i = 0; i<nrOfCalls; i++ )
    7165  {
    72     uint32_t functionID = *(uint32_t*)temp;
    73     bool isStatic = *(uint8_t*)(temp+sizeof(uint32_t));
    74     if( isStatic )
    75     {
    76       MultiType mt1, mt2, mt3, mt4, mt5;
    77       NetworkFunctionStatic *fct = NetworkFunctionStatic::getFunction( functionID );
    78       uint32_t nrOfArguments = *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t));
    79       temp+=2*sizeof(uint32_t)+sizeof(uint8_t);
    80       switch(nrOfArguments)
    81       {
    82         case 0:
    83           fct->call();
    84           break;
    85         case 1:
    86           mt1.importData(temp);
    87           fct->call(mt1);
    88           break;
    89         case 2:
    90           mt1.importData(temp);
    91           mt2.importData(temp);
    92           fct->call(mt1, mt2);
    93           break;
    94         case 3:
    95           mt1.importData(temp);
    96           mt2.importData(temp);
    97           mt3.importData(temp);
    98           fct->call(mt1, mt2, mt3);
    99           break;
    100         case 4:
    101           mt1.importData(temp);
    102           mt2.importData(temp);
    103           mt3.importData(temp);
    104           mt4.importData(temp);
    105           fct->call(mt1, mt2, mt3, mt4);
    106           break;
    107         case 5:
    108           mt1.importData(temp);
    109           mt2.importData(temp);
    110           mt3.importData(temp);
    111           mt4.importData(temp);
    112           mt5.importData(temp);
    113           fct->call(mt1, mt2, mt3, mt4, mt5);
    114           break;
    115         default:
    116           assert(0);
    117       }
    118     }
    119     else // not a static function, so also handle the objectID
    120     {
    121       MultiType mt1, mt2, mt3, mt4, mt5;
    122       NetworkMemberFunctionBase *fct = NetworkMemberFunctionBase::getFunction( functionID );
    123       uint32_t nrOfArguments = *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t));
    124       uint32_t objectID = *(uint32_t*)(temp+2*sizeof(uint32_t)+sizeof(uint8_t));
    125       temp+=3*sizeof(uint32_t)+sizeof(uint8_t);
    126       switch(nrOfArguments)
    127       {
    128         case 0:
    129           fct->call(objectID);
    130           break;
    131         case 1:
    132           mt1.importData(temp);
    133           fct->call(objectID, mt1);
    134           break;
    135         case 2:
    136           mt1.importData(temp);
    137           mt2.importData(temp);
    138           fct->call(objectID, mt1, mt2);
    139           break;
    140         case 3:
    141           mt1.importData(temp);
    142           mt2.importData(temp);
    143           mt3.importData(temp);
    144           fct->call(objectID, mt1, mt2, mt3);
    145           break;
    146         case 4:
    147           mt1.importData(temp);
    148           mt2.importData(temp);
    149           mt3.importData(temp);
    150           mt4.importData(temp);
    151           fct->call(objectID, mt1, mt2, mt3, mt4);
    152           break;
    153         case 5:
    154           mt1.importData(temp);
    155           mt2.importData(temp);
    156           mt3.importData(temp);
    157           mt4.importData(temp);
    158           mt5.importData(temp);
    159           fct->call(objectID, mt1, mt2, mt3, mt4, mt5);
    160           break;
    161         default:
    162           assert(0);
    163           break;
    164       }
    165     }
     66    FunctionCall fctCall;
     67    fctCall.loadData(temp);
     68    fctCall.execute();
    16669  }
     70 
    16771  delete this;
    16872  return true;
     
    17175void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
    17276  assert(!isDataENetAllocated());
    173 
    174   // first determine the size that has to be reserved for this call
    175   uint32_t callsize = 2*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and for bool isStatic
    176   uint32_t nrOfArguments = 0;
    177   if(mt1)
    178   {
    179     nrOfArguments++;
    180     callsize += mt1->getNetworkSize();
    181     if(mt2)
    182     {
    183       nrOfArguments++;
    184       callsize += mt2->getNetworkSize();
    185       if(mt3)
    186       {
    187         nrOfArguments++;
    188         callsize += mt3->getNetworkSize();
    189         if(mt4)
    190         {
    191           nrOfArguments++;
    192           callsize += mt4->getNetworkSize();
    193           if(mt5)
    194           {
    195             nrOfArguments++;
    196             callsize += mt5->getNetworkSize();
    197           }
    198         }
    199       }
    200     }
    201   }
    202 
    203   // now allocated mem if neccessary
    204   if( currentSize_ + callsize > currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION )
    205   {
    206     currentMemBlocks_ = (currentSize_ + callsize)%FUNCTIONCALLS_MEM_ALLOCATION+1;
    207     uint8_t *temp = new uint8_t[currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION];
    208     memcpy( temp, data_, currentSize_ );
    209     delete[] data_;
    210     data_ = temp;
    211   }
    212 
    213   // now serialise the mt values and copy the function id and isStatic
    214   uint8_t* temp = data_+currentSize_;
    215   *(uint32_t*)(data_+sizeof(uint32_t)) = *(uint32_t*)(data_+sizeof(uint32_t))+1; // increase number of calls
    216   *(uint32_t*)temp = networkID;
    217   *(uint8_t*)(temp+sizeof(uint32_t)) = true;
    218   *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t)) = nrOfArguments;
    219   temp += 2*sizeof(uint32_t)+sizeof(uint8_t);
    220   if(mt1)
    221   {
    222     mt1->exportData( temp ); //temp gets automatically increased
    223     if(mt2)
    224     {
    225       mt2->exportData( temp ); //temp gets automatically increased
    226       if(mt3)
    227       {
    228         mt3->exportData( temp ); //temp gets automatically increased
    229         if(mt4)
    230         {
    231           mt4->exportData( temp ); //temp gets automatically increased
    232           if(mt5)
    233           {
    234             mt5->exportData( temp ); //temp gets automatically increased
    235           }
    236         }
    237       }
    238     }
    239   }
    240   //currentSize_ += callsize;
    241   currentSize_ = temp-data_;
    242 
     77 
     78  this->functionCalls_.push(orxonox::FunctionCall());
     79  this->functionCalls_.back().setCallStatic( networkID, mt1, mt2, mt3, mt4, mt5 );
     80  this->currentSize_ += this->functionCalls_.back().getSize();
    24381}
    24482
    24583void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
    24684  assert(!isDataENetAllocated());
     85 
     86  this->functionCalls_.push(orxonox::FunctionCall());
     87  this->functionCalls_.back().setCallMember( networkID, objectID, mt1, mt2, mt3, mt4, mt5 );
     88  this->currentSize_ += this->functionCalls_.back().getSize();
     89}
    24790
    248   // first determine the size that has to be reserved for this call
    249   uint32_t callsize = 3*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and the objectID
    250   uint32_t nrOfArguments = 0;
    251   if(mt1)
     91bool FunctionCalls::send()
     92{
     93  assert(this->functionCalls_.size());
     94  data_=new uint8_t[ currentSize_ ];
     95  *(Type::Value *)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID
     96  *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls to 0
     97  uint8_t* temp = data_+2*sizeof(uint32_t);
     98 
     99  while( this->functionCalls_.size() )
    252100  {
    253     nrOfArguments++;
    254     callsize += mt1->getNetworkSize();
    255     if(mt2)
    256     {
    257       nrOfArguments++;
    258       callsize += mt2->getNetworkSize();
    259       if(mt3)
    260       {
    261         nrOfArguments++;
    262         callsize += mt3->getNetworkSize();
    263         if(mt4)
    264         {
    265           nrOfArguments++;
    266           callsize += mt4->getNetworkSize();
    267           if(mt5)
    268           {
    269             nrOfArguments++;
    270             callsize += mt5->getNetworkSize();
    271           }
    272         }
    273       }
    274     }
     101    this->functionCalls_.front().saveData( temp );
     102    this->functionCalls_.pop();
    275103  }
     104 
     105  assert( temp==data_+currentSize_ );
     106 
     107  Packet::send();
     108  return true;
     109}
    276110
    277   // now allocated mem if neccessary
    278   if( currentSize_ + callsize > currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION )
    279   {
    280     currentMemBlocks_ = (currentSize_ + callsize)%FUNCTIONCALLS_MEM_ALLOCATION+1;
    281     uint8_t *temp = new uint8_t[currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION];
    282     memcpy( temp, data_, currentSize_ );
    283     delete[] data_;
    284     data_ = temp;
    285   }
    286 
    287   // now serialise the mt values and copy the function id
    288   uint8_t* temp = data_+currentSize_;
    289   *(uint32_t*)(data_+sizeof(uint32_t)) = *(uint32_t*)(data_+sizeof(uint32_t))+1; // increase number of calls
    290   *(uint32_t*)temp = networkID;
    291   *(uint8_t*)(temp+sizeof(uint32_t)) = false;
    292   *(uint32_t*)(temp+sizeof(uint32_t)+sizeof(uint8_t)) = nrOfArguments;
    293   *(uint32_t*)(temp+2*sizeof(uint32_t)+sizeof(uint8_t)) = objectID;
    294   temp += 3*sizeof(uint32_t)+sizeof(uint8_t);
    295   if(mt1)
    296   {
    297     mt1->exportData( temp ); //temp gets automatically increased
    298     if(mt2)
    299     {
    300       mt2->exportData( temp ); //temp gets automatically increased
    301       if(mt3)
    302       {
    303         mt3->exportData( temp ); //temp gets automatically increased
    304         if(mt4)
    305         {
    306           mt4->exportData( temp ); //temp gets automatically increased
    307           if(mt5)
    308           {
    309             mt5->exportData( temp ); //temp gets automatically increased
    310           }
    311         }
    312       }
    313     }
    314   }
    315   currentSize_ += callsize;
    316 
    317 }
    318111
    319112
  • code/trunk/src/libraries/network/packet/FunctionCalls.h

    r6073 r7490  
    3333
    3434#include <cassert>
    35 #include "util/UtilPrereqs.h"
     35#include <queue>
    3636#include "Packet.h"
     37#include "network/FunctionCall.h"
    3738
    3839namespace orxonox {
     
    5758  void addCallStatic( uint32_t networkID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
    5859  void addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
     60  virtual bool send();
    5961private:
    60   uint32_t nrOfCalls_;
    61   unsigned int clientID_;
    62   uint32_t currentSize_;
    63   uint32_t currentMemBlocks_; // this saves the number of memory blocks (of size FUNCTIONCALLS_MEM_ALLOCATION) allocated
     62  std::queue<orxonox::FunctionCall> functionCalls_;
     63  unsigned int                      clientID_;
     64  uint32_t                          currentSize_;
    6465};
    6566
  • code/trunk/src/libraries/network/packet/Packet.h

    r6073 r7490  
    7676      { clientID_ = id; }
    7777
    78     bool send();
     78    virtual bool send();
    7979  protected:
    8080    Packet();
Note: See TracChangeset for help on using the changeset viewer.