Changeset 10476
- Timestamp:
- May 25, 2015, 3:23:55 PM (10 years ago)
- Location:
- code/branches/core7/src/libraries/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/network/NetworkFunction.cc
r10475 r10476 38 38 this->name_ = name; 39 39 this->pointer_ = pointer; 40 NetworkFunctionManager::getInstance().registerFunction(this);41 40 } 42 41 -
code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h
r10475 r10476 37 37 #include "NetworkFunction.h" 38 38 #include "NetworkFunctionManager.h" 39 #include "core/module/StaticallyInitializedInstance.h" 40 41 #define registerStaticNetworkFunction( functionPointer ) \ 42 static orxonox::NetworkFunctionBase& BOOST_PP_CAT( NETWORK_FUNCTION_, __UNIQUE_NUMBER__ ) \ 43 = (new orxonox::SI_NF(orxonox::registerStaticNetworkFunctionFct( functionPointer, #functionPointer )))->getFunction() 44 45 #define registerMemberNetworkFunction( class, function ) \ 46 static orxonox::NetworkFunctionBase& BOOST_PP_CAT( NETWORK_FUNCTION_##class, __UNIQUE_NUMBER__ ) \ 47 = (new orxonox::SI_NF(orxonox::registerMemberNetworkFunctionFct<class>( &class::function, #class "_" #function)))->getFunction() 48 49 // call it with functionPointer, clientID, args 50 #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, args 58 #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 } 39 64 40 65 namespace orxonox 41 66 { 42 #define registerStaticNetworkFunction( functionPointer ) \ 43 static void* BOOST_PP_CAT( NETWORK_FUNCTION_, __UNIQUE_NUMBER__ ) = registerStaticNetworkFunctionFct( functionPointer, #functionPointer ); 67 class _CoreExport StaticallyInitializedNetworkFunction : public StaticallyInitializedInstance 68 { 69 public: 70 StaticallyInitializedNetworkFunction(NetworkFunctionBase* function) : function_(function) {} 44 71 45 #define registerMemberNetworkFunction( class, function ) \ 46 static void* BOOST_PP_CAT( NETWORK_FUNCTION_##class, __UNIQUE_NUMBER__ ) = registerMemberNetworkFunctionFct<class>( &class::function, #class "_" #function); 72 virtual void load() 73 { NetworkFunctionManager::getInstance().registerFunction(this->function_); } 74 virtual void unload() 75 { NetworkFunctionManager::getInstance().unregisterFunction(this->function_); } 47 76 48 // call it with functionPointer, clientID, args 49 #define callStaticNetworkFunction( functionPointer, ...) \ 50 { \ 51 NetworkFunctionPointer p1; \ 52 copyPtr( functionPointer, p1 ); \ 53 FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \ 54 } 77 inline NetworkFunctionBase& getFunction() 78 { return *this->function_; } 55 79 56 // call it with class, function, objectID, clientID, args 57 #define callMemberNetworkFunction( class, function, objectID, ...) \ 58 { \ 59 NetworkFunctionPointer p1; \ 60 copyPtr( &class::function, p1 ); \ 61 FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), objectID, __VA_ARGS__); \ 62 } 80 private: 81 NetworkFunctionBase* function_; 82 }; 63 83 64 template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name ) 84 typedef StaticallyInitializedNetworkFunction SI_NF; 85 86 template<class T> inline NetworkFunctionBase* registerStaticNetworkFunctionFct( T ptr, const std::string& name ) 65 87 { 66 88 BOOST_STATIC_ASSERT( sizeof(T)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for static functions than defined above 67 89 NetworkFunctionPointer destptr; 68 90 copyPtr( ptr, destptr ); 69 new NetworkFunctionStatic( createFunctor(ptr), name, destptr ); 70 return 0; 91 return new NetworkFunctionStatic( createFunctor(ptr), name, destptr ); 71 92 } 72 93 73 template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, const std::string& name )94 template<class T, class PT> inline NetworkFunctionBase* registerMemberNetworkFunctionFct( PT ptr, const std::string& name ) 74 95 { 75 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 above 76 97 NetworkFunctionPointer destptr; 77 98 copyPtr( ptr, destptr ); 78 new NetworkMemberFunction<T>( createFunctor(ptr), name, destptr ); 79 return 0; 99 return new NetworkMemberFunction<T>( createFunctor(ptr), name, destptr ); 80 100 } 81 82 101 } 83 102
Note: See TracChangeset
for help on using the changeset viewer.