Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2015, 9:12:21 PM (9 years ago)
Author:
landauf
Message:

merged branch core7 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/network/FunctionCall.cc

    r7503 r10624  
    3232#include "util/MultiType.h"
    3333#include "NetworkFunction.h"
     34#include "NetworkFunctionManager.h"
    3435
    3536namespace orxonox {
     
    4647
    4748bool FunctionCall::execute(){
    48   if( this->bIsStatic_ )
     49  NetworkFunctionBase* fct = NetworkFunctionManager::getInstance().getFunctionByNetworkId( this->functionID_ );
     50  assert( fct != NULL );
     51  assert( this->nrOfArguments_==this->arguments_.size() );
     52  switch(this->nrOfArguments_)
    4953  {
    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     }
     54    case 0:
     55      return fct->call(this->objectID_);
     56    case 1:
     57      return fct->call(this->objectID_, this->arguments_[0]);
     58    case 2:
     59      return fct->call(this->objectID_, this->arguments_[0], this->arguments_[1]);
     60    case 3:
     61      return fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2]);
     62    case 4:
     63      return fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]);
     64    case 5:
     65      return fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]);
     66    default:
     67      assert(0);
     68      return true; // return true to avoid that this functions gets called over and over again
    7569  }
    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         if( !fct->call(this->objectID_) )
    83           return false;
    84         break;
    85       case 1:
    86         if( !fct->call(this->objectID_, this->arguments_[0]) )
    87           return false;
    88         break;
    89       case 2:
    90         if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1]) )
    91           return false;
    92         break;
    93       case 3:
    94         if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2]) )
    95           return false;
    96         break;
    97       case 4:
    98         if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]) )
    99           return false;
    100         break;
    101       case 5:
    102         if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]) )
    103           return false;
    104         break;
    105       default:
    106         assert(0);
    107     }
    108   }
    109   return true;
    11070}
    11171
    112 void FunctionCall::setCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
     72void FunctionCall::setCall( uint32_t networkID, uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){
    11373
    11474  // first determine the size that has to be reserved for this call
    115   uint32_t callsize = 2*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and for bool isStatic
     75  uint32_t callsize = 3*sizeof(uint32_t); //size for network-function-id and nrOfArguments and the objectID
    11676  uint32_t nrOfArguments = 0;
    117   if(mt1)
     77  if(!mt1.null())
    11878  {
    11979    nrOfArguments++;
    120     callsize += mt1->getNetworkSize();
    121     this->arguments_.push_back(*mt1);
    122     if(mt2)
     80    callsize += mt1.getNetworkSize();
     81    this->arguments_.push_back(mt1);
     82    if(!mt2.null())
    12383    {
    12484      nrOfArguments++;
    125       callsize += mt2->getNetworkSize();
    126       this->arguments_.push_back(*mt2);
    127       if(mt3)
     85      callsize += mt2.getNetworkSize();
     86      this->arguments_.push_back(mt2);
     87      if(!mt3.null())
    12888      {
    12989        nrOfArguments++;
    130         callsize += mt3->getNetworkSize();
    131         this->arguments_.push_back(*mt3);
    132         if(mt4)
     90        callsize += mt3.getNetworkSize();
     91        this->arguments_.push_back(mt3);
     92        if(!mt4.null())
    13393        {
    13494          nrOfArguments++;
    135           callsize += mt4->getNetworkSize();
    136           this->arguments_.push_back(*mt4);
    137           if(mt5)
     95          callsize += mt4.getNetworkSize();
     96          this->arguments_.push_back(mt4);
     97          if(!mt5.null())
    13898          {
    13999            nrOfArguments++;
    140             callsize += mt5->getNetworkSize();
    141             this->arguments_.push_back(*mt5);
     100            callsize += mt5.getNetworkSize();
     101            this->arguments_.push_back(mt5);
    142102          }
    143103        }
     
    146106  }
    147107  this->nrOfArguments_ = nrOfArguments;
     108  this->functionID_ = networkID;
     109  this->objectID_ = objectID;
    148110  this->size_ = callsize;
    149   this->bIsStatic_ = true;
    150   this->functionID_ = networkID;
    151 }
    152 
    153 void FunctionCall::setCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
    154 
    155   // first determine the size that has to be reserved for this call
    156   uint32_t callsize = 3*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and the objectID and bIsStatic
    157   uint32_t nrOfArguments = 0;
    158   if(mt1)
    159   {
    160     nrOfArguments++;
    161     callsize += mt1->getNetworkSize();
    162     this->arguments_.push_back(*mt1);
    163     if(mt2)
    164     {
    165       nrOfArguments++;
    166       callsize += mt2->getNetworkSize();
    167       this->arguments_.push_back(*mt2);
    168       if(mt3)
    169       {
    170         nrOfArguments++;
    171         callsize += mt3->getNetworkSize();
    172         this->arguments_.push_back(*mt3);
    173         if(mt4)
    174         {
    175           nrOfArguments++;
    176           callsize += mt4->getNetworkSize();
    177           this->arguments_.push_back(*mt4);
    178           if(mt5)
    179           {
    180             nrOfArguments++;
    181             callsize += mt5->getNetworkSize();
    182             this->arguments_.push_back(*mt5);
    183           }
    184         }
    185       }
    186     }
    187   }
    188   this->nrOfArguments_ = nrOfArguments;
    189   this->bIsStatic_ = false;
    190   this->functionID_ = networkID;
    191   this->size_ = callsize;
    192   this->objectID_ = objectID;
    193111}
    194112
     
    196114{
    197115  this->functionID_ = *(uint32_t*)mem;
    198   this->bIsStatic_ = *(uint8_t*)(mem+sizeof(uint32_t));
    199   this->nrOfArguments_ = *(uint32_t*)(mem+sizeof(uint32_t)+sizeof(uint8_t));
    200   if( this->bIsStatic_ )
    201   {
    202     mem += 2*sizeof(uint32_t)+sizeof(uint8_t);
    203   }
    204   else
    205   {
    206     this->objectID_ = *(uint32_t*)(mem+2*sizeof(uint32_t)+sizeof(uint8_t));
    207     mem += 3*sizeof(uint32_t)+sizeof(uint8_t);
    208   }
     116  this->nrOfArguments_ = *(uint32_t*)(mem+sizeof(uint32_t));
     117  this->objectID_ = *(uint32_t*)(mem+2*sizeof(uint32_t));
     118  mem += 3*sizeof(uint32_t);
    209119  for( unsigned int i=0; i<this->nrOfArguments_; ++i )
    210120  {
     
    218128  // now serialise the mt values and copy the function id and isStatic
    219129  *(uint32_t*)mem = this->functionID_;
    220   *(uint8_t*)(mem+sizeof(uint32_t)) = this->bIsStatic_;
    221   *(uint32_t*)(mem+sizeof(uint32_t)+sizeof(uint8_t)) = this->nrOfArguments_;
    222   if( this->bIsStatic_ )
    223   {
    224     mem += 2*sizeof(uint32_t)+sizeof(uint8_t);
    225   }
    226   else
    227   {
    228     *(uint32_t*)(mem+2*sizeof(uint32_t)+sizeof(uint8_t)) = this->objectID_;
    229     mem += 3*sizeof(uint32_t)+sizeof(uint8_t);
    230   }
     130  *(uint32_t*)(mem+sizeof(uint32_t)) = this->nrOfArguments_;
     131  *(uint32_t*)(mem+2*sizeof(uint32_t)) = this->objectID_;
     132  mem += 3*sizeof(uint32_t);
    231133  for( std::vector<MultiType>::iterator it = this->arguments_.begin(); it!=this->arguments_.end(); ++it )
    232134  {
Note: See TracChangeset for help on using the changeset viewer.