Changeset 10475 for code/branches/core7/src
- Timestamp:
- May 25, 2015, 2:41:57 PM (10 years ago)
- Location:
- code/branches/core7/src/libraries/network
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/network/FunctionCall.cc
r10474 r10475 47 47 48 48 bool FunctionCall::execute(){ 49 NetworkFunctionBase* fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getInstance().getFunction ( this->functionID_ ));49 NetworkFunctionBase* fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getInstance().getFunctionByNetworkId( this->functionID_ )); 50 50 assert( this->nrOfArguments_==this->arguments_.size() ); 51 51 switch(this->nrOfArguments_) -
code/branches/core7/src/libraries/network/NetworkFunction.cc
r10474 r10475 32 32 namespace orxonox 33 33 { 34 NetworkFunctionBase::NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& p )34 NetworkFunctionBase::NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& pointer) 35 35 { 36 36 static uint32_t networkID = 0; 37 37 this->networkID_ = networkID++; 38 39 38 this->name_ = name; 40 NetworkFunctionManager::getInstance().getNameMap()[name] = this; 41 NetworkFunctionManager::getInstance().getFunctorMap()[p] = this; 42 NetworkFunctionManager::getInstance().getIdMap()[this->getNetworkID()] = this; 39 this->pointer_ = pointer; 40 NetworkFunctionManager::getInstance().registerFunction(this); 43 41 } 44 42 45 43 void NetworkFunctionBase::setNetworkID(uint32_t id) 46 44 { 47 NetworkFunctionManager::getInstance(). getIdMap().erase(this->networkID_); // removeold id45 NetworkFunctionManager::getInstance().unregisterFunction(this); // unregister with old id 48 46 this->networkID_ = id; 49 NetworkFunctionManager::getInstance(). getIdMap()[this->networkID_] = this; // addnew id47 NetworkFunctionManager::getInstance().registerFunction(this); // register with new id 50 48 } 51 49 } -
code/branches/core7/src/libraries/network/NetworkFunction.h
r10472 r10475 69 69 class _NetworkExport NetworkFunctionBase { 70 70 public: 71 NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& p );71 NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& pointer); 72 72 virtual ~NetworkFunctionBase() {} 73 73 74 74 void setNetworkID(uint32_t id); 75 inline uint32_t getNetworkID() const { return this->networkID_; } 76 inline const std::string& getName() const { return name_; } 75 inline uint32_t getNetworkID() const { return this->networkID_; } 76 inline const std::string& getName() const { return this->name_; } 77 inline const NetworkFunctionPointer& getPointer() const { return this->pointer_; } 77 78 78 79 virtual bool call(uint32_t objectID)=0; … … 86 87 uint32_t networkID_; 87 88 std::string name_; 89 NetworkFunctionPointer pointer_; 88 90 89 91 }; -
code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h
r10474 r10475 51 51 NetworkFunctionPointer p1; \ 52 52 copyPtr( functionPointer, p1 ); \ 53 FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunction (p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \53 FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \ 54 54 } 55 55 … … 59 59 NetworkFunctionPointer p1; \ 60 60 copyPtr( &class::function, p1 ); \ 61 FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunction (p1)->getNetworkID(), objectID, __VA_ARGS__); \61 FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), objectID, __VA_ARGS__); \ 62 62 } 63 63 -
code/branches/core7/src/libraries/network/NetworkFunctionManager.cc
r10474 r10475 38 38 } 39 39 40 void NetworkFunctionManager:: setNetworkID(const std::string& name, uint32_t id)40 void NetworkFunctionManager::registerFunction(NetworkFunctionBase* function) 41 41 { 42 std::map<std::string, NetworkFunctionBase*>& map = this->nameMap_; 43 assert( map.find(name)!=map.end() ); 44 map[name]->setNetworkID(id); 42 this->functions_.insert(function); 43 this->nameMap_[function->getName()] = function; 44 this->idMap_[function->getNetworkID()] = function; 45 this->functorMap_[function->getPointer()] = function; 46 } 47 48 void NetworkFunctionManager::unregisterFunction(NetworkFunctionBase* function) 49 { 50 this->functions_.erase(function); 51 this->nameMap_.erase(function->getName()); 52 this->idMap_.erase(function->getNetworkID()); 53 this->functorMap_.erase(function->getPointer()); 45 54 } 46 55 47 56 void NetworkFunctionManager::destroyAllNetworkFunctions() 48 57 { 49 std::map<std::string, NetworkFunctionBase*>& map = this->nameMap_; 50 std::map<std::string, NetworkFunctionBase*>::iterator it; 51 for (it = map.begin(); it != map.end(); ++it) 52 delete it->second; 58 std::set<NetworkFunctionBase*>::iterator it; 59 for (it = this->functions_.begin(); it != this->functions_.end(); ++it) 60 delete (*it); 53 61 } 54 62 55 NetworkFunctionBase* NetworkFunctionManager::getFunction(const NetworkFunctionPointer& p) 63 NetworkFunctionBase* NetworkFunctionManager::getFunctionByName(const std::string& name) 64 { 65 std::map<std::string, NetworkFunctionBase*>::iterator it = nameMap_.find(name); 66 assert(it != nameMap_.end()); 67 return it->second; 68 } 69 70 NetworkFunctionBase* NetworkFunctionManager::getFunctionByFunctionPointer(const NetworkFunctionPointer& p) 56 71 { 57 72 std::map<NetworkFunctionPointer, NetworkFunctionBase*>::iterator it = functorMap_.find(p); … … 60 75 } 61 76 62 NetworkFunctionBase* NetworkFunctionManager::getFunction (uint32_t id)77 NetworkFunctionBase* NetworkFunctionManager::getFunctionByNetworkId(uint32_t id) 63 78 { 64 79 std::map<uint32_t, NetworkFunctionBase*>::iterator it = idMap_.find(id); -
code/branches/core7/src/libraries/network/NetworkFunctionManager.h
r10474 r10475 34 34 #include <cassert> 35 35 #include <map> 36 #include <set> 36 37 37 38 namespace orxonox … … 42 43 static NetworkFunctionManager& getInstance(); 43 44 44 void setNetworkID(const std::string& name, uint32_t id); 45 void registerFunction(NetworkFunctionBase* function); 46 void unregisterFunction(NetworkFunctionBase* function); 47 45 48 void destroyAllNetworkFunctions(); 46 49 47 inline std::map<std::string, NetworkFunctionBase*>& getNameMap() 48 { return nameMap_; } 49 inline std::map<NetworkFunctionPointer, NetworkFunctionBase*>& getFunctorMap() 50 { return functorMap_; } 51 inline std::map<uint32_t, NetworkFunctionBase*>& getIdMap() 52 { return idMap_; } 50 inline const std::set<NetworkFunctionBase*>& getAllFunctions() 51 { return functions_; } 53 52 54 NetworkFunctionBase* getFunction(const NetworkFunctionPointer& p); 55 NetworkFunctionBase* getFunction(uint32_t id); 53 NetworkFunctionBase* getFunctionByName(const std::string& name); 54 NetworkFunctionBase* getFunctionByFunctionPointer(const NetworkFunctionPointer& p); 55 NetworkFunctionBase* getFunctionByNetworkId(uint32_t id); 56 56 57 57 private: 58 std::set<NetworkFunctionBase*> functions_; 58 59 std::map<std::string, NetworkFunctionBase*> nameMap_; 59 60 std::map<NetworkFunctionPointer, NetworkFunctionBase*> functorMap_; -
code/branches/core7/src/libraries/network/packet/FunctionIDs.cc
r10474 r10475 56 56 57 57 //calculate total needed size (for all strings and integers) 58 std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getInstance().getNameMap();59 std:: map<std::string, NetworkFunctionBase*>::iterator it;60 for (it = map.begin(); it != map.end(); ++it)58 const std::set<NetworkFunctionBase*>& set = NetworkFunctionManager::getInstance().getAllFunctions(); 59 std::set<NetworkFunctionBase*>::const_iterator it; 60 for (it = set.begin(); it != set.end(); ++it) 61 61 { 62 const std::string& functionname = it->second->getName();63 networkID = it->second->getNetworkID();62 const std::string& functionname = (*it)->getName(); 63 networkID = (*it)->getNetworkID(); 64 64 // now push the network id and the classname to the stack 65 65 tempQueue.push( std::pair<unsigned int, std::string>(networkID, functionname) ); … … 140 140 functionname = temp+2*sizeof(uint32_t); 141 141 orxout(internal_info, context::packets) << "processing functionid: " << networkID << " name: " << functionname << endl; 142 NetworkFunctionManager::getInstance(). setNetworkID((const char*)functionname,networkID);142 NetworkFunctionManager::getInstance().getFunctionByName((const char*)functionname)->setNetworkID(networkID); 143 143 temp += 2*sizeof(uint32_t) + stringsize; 144 144 }
Note: See TracChangeset
for help on using the changeset viewer.