Changeset 10478 for code/branches/core7/src/libraries
- Timestamp:
- May 25, 2015, 5:37:15 PM (10 years ago)
- Location:
- code/branches/core7/src/libraries/network
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/network/CMakeLists.txt
r10477 r10478 34 34 MasterServerComm.cc 35 35 NetworkFunction.cc 36 NetworkFunctionIncludes.cc 36 37 NetworkFunctionManager.cc 37 38 Host.cc -
code/branches/core7/src/libraries/network/FunctionCall.cc
r10475 r10478 69 69 } 70 70 71 void FunctionCall::setCall( uint32_t networkID, uint32_t objectID, const MultiType * mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType*mt5){71 void FunctionCall::setCall( uint32_t networkID, uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ 72 72 73 73 // first determine the size that has to be reserved for this call 74 74 uint32_t callsize = 3*sizeof(uint32_t); //size for network-function-id and nrOfArguments and the objectID 75 75 uint32_t nrOfArguments = 0; 76 if( mt1)76 if(!mt1.null()) 77 77 { 78 78 nrOfArguments++; 79 callsize += mt1 ->getNetworkSize();80 this->arguments_.push_back( *mt1);81 if( mt2)79 callsize += mt1.getNetworkSize(); 80 this->arguments_.push_back(mt1); 81 if(!mt2.null()) 82 82 { 83 83 nrOfArguments++; 84 callsize += mt2 ->getNetworkSize();85 this->arguments_.push_back( *mt2);86 if( mt3)84 callsize += mt2.getNetworkSize(); 85 this->arguments_.push_back(mt2); 86 if(!mt3.null()) 87 87 { 88 88 nrOfArguments++; 89 callsize += mt3 ->getNetworkSize();90 this->arguments_.push_back( *mt3);91 if( mt4)89 callsize += mt3.getNetworkSize(); 90 this->arguments_.push_back(mt3); 91 if(!mt4.null()) 92 92 { 93 93 nrOfArguments++; 94 callsize += mt4 ->getNetworkSize();95 this->arguments_.push_back( *mt4);96 if( mt5)94 callsize += mt4.getNetworkSize(); 95 this->arguments_.push_back(mt4); 96 if(!mt5.null()) 97 97 { 98 98 nrOfArguments++; 99 callsize += mt5 ->getNetworkSize();100 this->arguments_.push_back( *mt5);99 callsize += mt5.getNetworkSize(); 100 this->arguments_.push_back(mt5); 101 101 } 102 102 } -
code/branches/core7/src/libraries/network/FunctionCall.h
r10473 r10478 52 52 bool execute(); 53 53 54 void setCall( 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);54 void setCall( uint32_t networkID, uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5); 55 55 56 56 void saveData( uint8_t*& mem ); -
code/branches/core7/src/libraries/network/FunctionCallManager.cc
r10473 r10478 40 40 41 41 42 void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID)43 {44 if(sPeerMap_.find(peerID)==sPeerMap_.end())45 {46 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;47 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);48 }49 FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID);50 }51 void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1)52 {53 if(sPeerMap_.find(peerID)==sPeerMap_.end())54 {55 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;56 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);57 }58 FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, &mt1);59 }60 void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)61 {62 if(sPeerMap_.find(peerID)==sPeerMap_.end())63 {64 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;65 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);66 }67 FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, &mt1, &mt2);68 }69 void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)70 {71 if(sPeerMap_.find(peerID)==sPeerMap_.end())72 {73 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;74 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);75 }76 FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, &mt1, &mt2, &mt3);77 }78 void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)79 {80 if(sPeerMap_.find(peerID)==sPeerMap_.end())81 {82 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;83 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);84 }85 FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, &mt1, &mt2, &mt3, &mt4);86 }87 42 void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) 88 43 { … … 92 47 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 93 48 } 94 FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);49 FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, mt1, mt2, mt3, mt4, mt5); 95 50 } 96 51 -
code/branches/core7/src/libraries/network/FunctionCallManager.h
r10473 r10478 46 46 { 47 47 public: 48 static void addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID);49 static void addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1);50 static void addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2);51 static void addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);52 static void addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);53 48 static void addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5); 54 49 -
code/branches/core7/src/libraries/network/NetworkFunction.h
r10475 r10478 193 193 }; 194 194 195 template<class T> inline void copyPtr( T ptr, NetworkFunctionPointer& destptr)196 {197 if( sizeof(NetworkFunctionPointer)-sizeof(T) > 0)198 memset((uint8_t*)&destptr + sizeof(T), 0, sizeof(NetworkFunctionPointer)-sizeof(T));199 T p2 = ptr;200 memcpy( &destptr, &p2, sizeof(T) );201 // for(unsigned int i=0; i<(sizeof(T)-1/4)+1; i++)202 // *((uint32_t*)destptr+i) = p2>>32*i;203 }204 205 195 } 206 196 -
code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h
r10476 r10478 36 36 37 37 #include "NetworkFunction.h" 38 #include "NetworkFunctionManager.h"39 38 #include "core/module/StaticallyInitializedInstance.h" 40 39 … … 47 46 = (new orxonox::SI_NF(orxonox::registerMemberNetworkFunctionFct<class>( &class::function, #class "_" #function)))->getFunction() 48 47 49 // call it with functionPointer, clientID, args50 #define callStaticNetworkFunction( functionPointer, ...) \51 { \52 NetworkFunctionPointer p1; \53 copyPtr( functionPointer, p1 ); \54 FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \55 }56 57 // call it with class, function, objectID, clientID, args58 #define callMemberNetworkFunction( class, function, objectID, ...) \59 { \60 NetworkFunctionPointer p1; \61 copyPtr( &class::function, p1 ); \62 FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), objectID, __VA_ARGS__); \63 }64 65 48 namespace orxonox 66 49 { 67 class _ CoreExport StaticallyInitializedNetworkFunction : public StaticallyInitializedInstance50 class _NetworkExport StaticallyInitializedNetworkFunction : public StaticallyInitializedInstance 68 51 { 69 52 public: 70 53 StaticallyInitializedNetworkFunction(NetworkFunctionBase* function) : function_(function) {} 71 54 72 virtual void load() 73 { NetworkFunctionManager::getInstance().registerFunction(this->function_); } 74 virtual void unload() 75 { NetworkFunctionManager::getInstance().unregisterFunction(this->function_); } 55 virtual void load(); 56 virtual void unload(); 76 57 77 58 inline NetworkFunctionBase& getFunction() … … 84 65 typedef StaticallyInitializedNetworkFunction SI_NF; 85 66 86 template<class T> inline NetworkFunctionBase* registerStaticNetworkFunctionFct( T ptr, const std::string& name ) 67 template<class PT> 68 inline NetworkFunctionBase* registerStaticNetworkFunctionFct(PT ptr, const std::string& name) 87 69 { 88 BOOST_STATIC_ASSERT( sizeof(T)<=sizeof(NetworkFunctionPointer)); // if this fails your compiler uses bigger pointers for static functions than defined above70 BOOST_STATIC_ASSERT(sizeof(PT) <= sizeof(NetworkFunctionPointer)); // if this fails your compiler uses bigger pointers for static functions than defined above 89 71 NetworkFunctionPointer destptr; 90 copyPtr( ptr, destptr);91 return new NetworkFunctionStatic( createFunctor(ptr), name, destptr);72 copyPtr(ptr, destptr); 73 return new NetworkFunctionStatic(createFunctor(ptr), name, destptr); 92 74 } 93 75 94 template<class T, class PT> inline NetworkFunctionBase* registerMemberNetworkFunctionFct( PT ptr, const std::string& name ) 76 template<class T, class PT> 77 inline NetworkFunctionBase* registerMemberNetworkFunctionFct(PT ptr, const std::string& name) 95 78 { 96 BOOST_STATIC_ASSERT( sizeof(PT)<=sizeof(NetworkFunctionPointer)); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above79 BOOST_STATIC_ASSERT(sizeof(PT) <= sizeof(NetworkFunctionPointer)); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above 97 80 NetworkFunctionPointer destptr; 98 copyPtr( ptr, destptr ); 99 return new NetworkMemberFunction<T>( createFunctor(ptr), name, destptr ); 81 copyPtr(ptr, destptr); 82 return new NetworkMemberFunction<T>(createFunctor(ptr), name, destptr); 83 } 84 85 _NetworkExport uint32_t getNetworkIdForPointer(const NetworkFunctionPointer& pointer); 86 87 // call it with functionPointer, clientID, args 88 template<class PT> 89 void callStaticNetworkFunction(PT ptr, uint32_t clientID, const MultiType& mt1 = MultiType::Null, const MultiType& mt2 = MultiType::Null, const MultiType& mt3 = MultiType::Null, const MultiType& mt4 = MultiType::Null, const MultiType& mt5 = MultiType::Null) 90 { 91 NetworkFunctionPointer destptr; 92 copyPtr(ptr, destptr); 93 FunctionCallManager::addCall(getNetworkIdForPointer(destptr), OBJECTID_UNKNOWN, clientID, mt1, mt2, mt3, mt4, mt5); 94 } 95 96 // call it with class::function, objectID, clientID, args 97 template<class PT> 98 void callMemberNetworkFunction(PT ptr, uint32_t objectID, uint32_t clientID, const MultiType& mt1 = MultiType::Null, const MultiType& mt2 = MultiType::Null, const MultiType& mt3 = MultiType::Null, const MultiType& mt4 = MultiType::Null, const MultiType& mt5 = MultiType::Null) 99 { 100 NetworkFunctionPointer destptr; 101 copyPtr(ptr, destptr); 102 FunctionCallManager::addCall(getNetworkIdForPointer(destptr), objectID, clientID, mt1, mt2, mt3, mt4, mt5); 103 } 104 105 template<class PT> 106 inline void copyPtr(PT ptr, NetworkFunctionPointer& destptr) 107 { 108 if (sizeof(NetworkFunctionPointer) - sizeof(PT) > 0) 109 memset((uint8_t*)&destptr + sizeof(PT), 0, sizeof(NetworkFunctionPointer) - sizeof(PT)); 110 PT p2 = ptr; 111 memcpy(&destptr, &p2, sizeof(PT)); 100 112 } 101 113 } -
code/branches/core7/src/libraries/network/packet/FunctionCalls.cc
r10473 r10478 82 82 } 83 83 84 void FunctionCalls::addCall( uint32_t networkID, uint32_t objectID, const MultiType * mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType*mt5)84 void FunctionCalls::addCall( uint32_t networkID, uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) 85 85 { 86 86 assert(!isDataENetAllocated()); -
code/branches/core7/src/libraries/network/packet/FunctionCalls.h
r10473 r10478 56 56 virtual bool process(orxonox::Host* host); 57 57 58 void addCall( 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);58 void addCall( uint32_t networkID, uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5); 59 59 virtual bool send(orxonox::Host* host); 60 60 private:
Note: See TracChangeset
for help on using the changeset viewer.