[Orxonox-commit 5812] r10472 - code/branches/core7/src/libraries/network

landauf at orxonox.net landauf at orxonox.net
Mon May 25 13:51:40 CEST 2015


Author: landauf
Date: 2015-05-25 13:51:40 +0200 (Mon, 25 May 2015)
New Revision: 10472

Modified:
   code/branches/core7/src/libraries/network/FunctionCall.cc
   code/branches/core7/src/libraries/network/FunctionCall.h
   code/branches/core7/src/libraries/network/NetworkFunction.h
Log:
use the same interface for static an member functions

Modified: code/branches/core7/src/libraries/network/FunctionCall.cc
===================================================================
--- code/branches/core7/src/libraries/network/FunctionCall.cc	2015-05-25 11:37:50 UTC (rev 10471)
+++ code/branches/core7/src/libraries/network/FunctionCall.cc	2015-05-25 11:51:40 UTC (rev 10472)
@@ -46,68 +46,26 @@
 
 
 bool FunctionCall::execute(){
-  if( this->bIsStatic_ )
+  NetworkFunctionBase* fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getFunction( this->functionID_ ));
+  assert( this->nrOfArguments_==this->arguments_.size() );
+  switch(this->nrOfArguments_)
   {
-    NetworkFunctionStatic *fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getFunction( this->functionID_ ));
-    assert( this->nrOfArguments_==this->arguments_.size() );
-    switch(this->nrOfArguments_)
-    {
-      case 0:
-        fct->call();
-        break;
-      case 1:
-        fct->call(this->arguments_[0]);
-        break;
-      case 2:
-        fct->call(this->arguments_[0], this->arguments_[1]);
-        break;
-      case 3:
-        fct->call(this->arguments_[0], this->arguments_[1], this->arguments_[2]);
-        break;
-      case 4:
-        fct->call(this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]);
-        break;
-      case 5:
-        fct->call(this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]);
-        break;
-      default:
-        assert(0);
-    }
+    case 0:
+      return !fct->call(this->objectID_);
+    case 1:
+      return !fct->call(this->objectID_, this->arguments_[0]);
+    case 2:
+      return !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1]);
+    case 3:
+      return !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2]);
+    case 4:
+      return !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]);
+    case 5:
+      return !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]);
+    default:
+      assert(0);
+      return true; // return true to avoid that this functions gets called over and over again
   }
-  else // not a static function, so also handle with the objectID
-  {
-    NetworkMemberFunctionBase *fct = static_cast<NetworkMemberFunctionBase*>(NetworkFunctionManager::getFunction( this->functionID_ ));
-    switch(this->nrOfArguments_)
-    {
-      case 0:
-        if( !fct->call(this->objectID_) )
-          return false;
-        break;
-      case 1:
-        if( !fct->call(this->objectID_, this->arguments_[0]) )
-          return false;
-        break;
-      case 2:
-        if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1]) )
-          return false;
-        break;
-      case 3:
-        if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2]) )
-          return false;
-        break;
-      case 4:
-        if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]) )
-          return false;
-        break;
-      case 5:
-        if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]) )
-          return false;
-        break;
-      default:
-        assert(0);
-    }
-  }
-  return true;
 }
 
 void FunctionCall::setCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
@@ -147,7 +105,6 @@
   }
   this->nrOfArguments_ = nrOfArguments;
   this->size_ = callsize;
-  this->bIsStatic_ = true;
   this->functionID_ = networkID;
 }
 
@@ -187,7 +144,6 @@
     }
   }
   this->nrOfArguments_ = nrOfArguments;
-  this->bIsStatic_ = false;
   this->functionID_ = networkID;
   this->size_ = callsize;
   this->objectID_ = objectID;
@@ -196,17 +152,9 @@
 void FunctionCall::loadData(uint8_t*& mem)
 {
   this->functionID_ = *(uint32_t*)mem;
-  this->bIsStatic_ = *(uint8_t*)(mem+sizeof(uint32_t));
-  this->nrOfArguments_ = *(uint32_t*)(mem+sizeof(uint32_t)+sizeof(uint8_t));
-  if( this->bIsStatic_ )
-  {
-    mem += 2*sizeof(uint32_t)+sizeof(uint8_t);
-  }
-  else
-  {
-    this->objectID_ = *(uint32_t*)(mem+2*sizeof(uint32_t)+sizeof(uint8_t));
-    mem += 3*sizeof(uint32_t)+sizeof(uint8_t);
-  }
+  this->nrOfArguments_ = *(uint32_t*)(mem+sizeof(uint32_t));
+  this->objectID_ = *(uint32_t*)(mem+2*sizeof(uint32_t));
+  mem += 3*sizeof(uint32_t);
   for( unsigned int i=0; i<this->nrOfArguments_; ++i )
   {
     this->arguments_.push_back(MultiType());
@@ -218,17 +166,9 @@
 {
   // now serialise the mt values and copy the function id and isStatic
   *(uint32_t*)mem = this->functionID_;
-  *(uint8_t*)(mem+sizeof(uint32_t)) = this->bIsStatic_;
-  *(uint32_t*)(mem+sizeof(uint32_t)+sizeof(uint8_t)) = this->nrOfArguments_;
-  if( this->bIsStatic_ )
-  {
-    mem += 2*sizeof(uint32_t)+sizeof(uint8_t);
-  }
-  else
-  {
-    *(uint32_t*)(mem+2*sizeof(uint32_t)+sizeof(uint8_t)) = this->objectID_;
-    mem += 3*sizeof(uint32_t)+sizeof(uint8_t);
-  }
+  *(uint32_t*)(mem+sizeof(uint32_t)) = this->nrOfArguments_;
+  *(uint32_t*)(mem+2*sizeof(uint32_t)) = this->objectID_;
+  mem += 3*sizeof(uint32_t);
   for( std::vector<MultiType>::iterator it = this->arguments_.begin(); it!=this->arguments_.end(); ++it )
   {
     it->exportData( mem );

Modified: code/branches/core7/src/libraries/network/FunctionCall.h
===================================================================
--- code/branches/core7/src/libraries/network/FunctionCall.h	2015-05-25 11:37:50 UTC (rev 10471)
+++ code/branches/core7/src/libraries/network/FunctionCall.h	2015-05-25 11:51:40 UTC (rev 10472)
@@ -58,7 +58,6 @@
   void loadData( uint8_t*& mem );
 private:
   uint32_t                  nrOfArguments_;
-  bool                      bIsStatic_;
   uint32_t                  functionID_;
   uint32_t                  objectID_;
   uint32_t                  size_;

Modified: code/branches/core7/src/libraries/network/NetworkFunction.h
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunction.h	2015-05-25 11:37:50 UTC (rev 10471)
+++ code/branches/core7/src/libraries/network/NetworkFunction.h	2015-05-25 11:51:40 UTC (rev 10472)
@@ -75,6 +75,13 @@
     inline uint32_t     getNetworkID() const            { return this->networkID_; }
     inline const std::string& getName() const           { return name_; }
 
+    virtual bool call(uint32_t objectID)=0;
+    virtual bool call(uint32_t objectID, const MultiType& mt1)=0;
+    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2)=0;
+    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)=0;
+    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)=0;
+    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)=0;
+
   private:
     uint32_t networkID_;
     std::string name_;
@@ -89,12 +96,13 @@
         , functor_(functor)
     { }
 
-    inline void call(){ (*this->functor_)(); }
-    inline void call(const MultiType& mt1){ (*this->functor_)(mt1); }
-    inline void call(const MultiType& mt1, const MultiType& mt2){ (*this->functor_)(mt1, mt2); }
-    inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3){ (*this->functor_)(mt1, mt2, mt3); }
-    inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4){ (*this->functor_)(mt1, mt2, mt3, mt4); }
-    inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); }
+    // ignore the objectID because its a static function
+    virtual bool call(uint32_t objectID){ (*this->functor_)(); return true; }
+    virtual bool call(uint32_t objectID, const MultiType& mt1){ (*this->functor_)(mt1); return true; }
+    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2){ (*this->functor_)(mt1, mt2); return true; }
+    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3){ (*this->functor_)(mt1, mt2, mt3); return true; }
+    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4){ (*this->functor_)(mt1, mt2, mt3, mt4); return true; }
+    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); return true; }
 
   private:
     FunctorStaticPtr functor_;
@@ -107,14 +115,6 @@
     NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p)
         : NetworkFunctionBase(name, p)
     { }
-
-    //
-    virtual bool call(uint32_t objectID)=0;
-    virtual bool call(uint32_t objectID, const MultiType& mt1)=0;
-    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2)=0;
-    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)=0;
-    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)=0;
-    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)=0;
 };
 
 




More information about the Orxonox-commit mailing list