[Orxonox-commit 5815] r10475 - in code/branches/core7/src/libraries/network: . packet
landauf at orxonox.net
landauf at orxonox.net
Mon May 25 14:41:57 CEST 2015
Author: landauf
Date: 2015-05-25 14:41:57 +0200 (Mon, 25 May 2015)
New Revision: 10475
Modified:
code/branches/core7/src/libraries/network/FunctionCall.cc
code/branches/core7/src/libraries/network/NetworkFunction.cc
code/branches/core7/src/libraries/network/NetworkFunction.h
code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h
code/branches/core7/src/libraries/network/NetworkFunctionManager.cc
code/branches/core7/src/libraries/network/NetworkFunctionManager.h
code/branches/core7/src/libraries/network/packet/FunctionIDs.cc
Log:
refactored the interface of NetworkFunctionManager: maps are better encapsulated now
Modified: code/branches/core7/src/libraries/network/FunctionCall.cc
===================================================================
--- code/branches/core7/src/libraries/network/FunctionCall.cc 2015-05-25 12:14:16 UTC (rev 10474)
+++ code/branches/core7/src/libraries/network/FunctionCall.cc 2015-05-25 12:41:57 UTC (rev 10475)
@@ -46,7 +46,7 @@
bool FunctionCall::execute(){
- NetworkFunctionBase* fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getInstance().getFunction( this->functionID_ ));
+ NetworkFunctionBase* fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getInstance().getFunctionByNetworkId( this->functionID_ ));
assert( this->nrOfArguments_==this->arguments_.size() );
switch(this->nrOfArguments_)
{
Modified: code/branches/core7/src/libraries/network/NetworkFunction.cc
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunction.cc 2015-05-25 12:14:16 UTC (rev 10474)
+++ code/branches/core7/src/libraries/network/NetworkFunction.cc 2015-05-25 12:41:57 UTC (rev 10475)
@@ -31,21 +31,19 @@
namespace orxonox
{
- NetworkFunctionBase::NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& p)
+ NetworkFunctionBase::NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& pointer)
{
static uint32_t networkID = 0;
this->networkID_ = networkID++;
-
this->name_ = name;
- NetworkFunctionManager::getInstance().getNameMap()[name] = this;
- NetworkFunctionManager::getInstance().getFunctorMap()[p] = this;
- NetworkFunctionManager::getInstance().getIdMap()[this->getNetworkID()] = this;
+ this->pointer_ = pointer;
+ NetworkFunctionManager::getInstance().registerFunction(this);
}
void NetworkFunctionBase::setNetworkID(uint32_t id)
{
- NetworkFunctionManager::getInstance().getIdMap().erase(this->networkID_); // remove old id
+ NetworkFunctionManager::getInstance().unregisterFunction(this); // unregister with old id
this->networkID_ = id;
- NetworkFunctionManager::getInstance().getIdMap()[this->networkID_] = this; // add new id
+ NetworkFunctionManager::getInstance().registerFunction(this); // register with new id
}
}
Modified: code/branches/core7/src/libraries/network/NetworkFunction.h
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunction.h 2015-05-25 12:14:16 UTC (rev 10474)
+++ code/branches/core7/src/libraries/network/NetworkFunction.h 2015-05-25 12:41:57 UTC (rev 10475)
@@ -68,12 +68,13 @@
class _NetworkExport NetworkFunctionBase {
public:
- NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& p);
+ NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& pointer);
virtual ~NetworkFunctionBase() {}
void setNetworkID(uint32_t id);
- inline uint32_t getNetworkID() const { return this->networkID_; }
- inline const std::string& getName() const { return name_; }
+ inline uint32_t getNetworkID() const { return this->networkID_; }
+ inline const std::string& getName() const { return this->name_; }
+ inline const NetworkFunctionPointer& getPointer() const { return this->pointer_; }
virtual bool call(uint32_t objectID)=0;
virtual bool call(uint32_t objectID, const MultiType& mt1)=0;
@@ -85,6 +86,7 @@
private:
uint32_t networkID_;
std::string name_;
+ NetworkFunctionPointer pointer_;
};
Modified: code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h 2015-05-25 12:14:16 UTC (rev 10474)
+++ code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h 2015-05-25 12:41:57 UTC (rev 10475)
@@ -50,7 +50,7 @@
{ \
NetworkFunctionPointer p1; \
copyPtr( functionPointer, p1 ); \
- FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunction(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \
+ FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \
}
// call it with class, function, objectID, clientID, args
@@ -58,7 +58,7 @@
{ \
NetworkFunctionPointer p1; \
copyPtr( &class::function, p1 ); \
- FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunction(p1)->getNetworkID(), objectID, __VA_ARGS__); \
+ FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunctionByFunctionPointer(p1)->getNetworkID(), objectID, __VA_ARGS__); \
}
template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name )
Modified: code/branches/core7/src/libraries/network/NetworkFunctionManager.cc
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunctionManager.cc 2015-05-25 12:14:16 UTC (rev 10474)
+++ code/branches/core7/src/libraries/network/NetworkFunctionManager.cc 2015-05-25 12:41:57 UTC (rev 10475)
@@ -37,29 +37,44 @@
return instance;
}
- void NetworkFunctionManager::setNetworkID(const std::string& name, uint32_t id)
+ void NetworkFunctionManager::registerFunction(NetworkFunctionBase* function)
{
- std::map<std::string, NetworkFunctionBase*>& map = this->nameMap_;
- assert( map.find(name)!=map.end() );
- map[name]->setNetworkID(id);
+ this->functions_.insert(function);
+ this->nameMap_[function->getName()] = function;
+ this->idMap_[function->getNetworkID()] = function;
+ this->functorMap_[function->getPointer()] = function;
}
+ void NetworkFunctionManager::unregisterFunction(NetworkFunctionBase* function)
+ {
+ this->functions_.erase(function);
+ this->nameMap_.erase(function->getName());
+ this->idMap_.erase(function->getNetworkID());
+ this->functorMap_.erase(function->getPointer());
+ }
+
void NetworkFunctionManager::destroyAllNetworkFunctions()
{
- std::map<std::string, NetworkFunctionBase*>& map = this->nameMap_;
- std::map<std::string, NetworkFunctionBase*>::iterator it;
- for (it = map.begin(); it != map.end(); ++it)
- delete it->second;
+ std::set<NetworkFunctionBase*>::iterator it;
+ for (it = this->functions_.begin(); it != this->functions_.end(); ++it)
+ delete (*it);
}
- NetworkFunctionBase* NetworkFunctionManager::getFunction(const NetworkFunctionPointer& p)
+ NetworkFunctionBase* NetworkFunctionManager::getFunctionByName(const std::string& name)
{
+ std::map<std::string, NetworkFunctionBase*>::iterator it = nameMap_.find(name);
+ assert(it != nameMap_.end());
+ return it->second;
+ }
+
+ NetworkFunctionBase* NetworkFunctionManager::getFunctionByFunctionPointer(const NetworkFunctionPointer& p)
+ {
std::map<NetworkFunctionPointer, NetworkFunctionBase*>::iterator it = functorMap_.find(p);
assert(it != functorMap_.end());
return it->second;
}
- NetworkFunctionBase* NetworkFunctionManager::getFunction(uint32_t id)
+ NetworkFunctionBase* NetworkFunctionManager::getFunctionByNetworkId(uint32_t id)
{
std::map<uint32_t, NetworkFunctionBase*>::iterator it = idMap_.find(id);
assert(it != idMap_.end());
Modified: code/branches/core7/src/libraries/network/NetworkFunctionManager.h
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunctionManager.h 2015-05-25 12:14:16 UTC (rev 10474)
+++ code/branches/core7/src/libraries/network/NetworkFunctionManager.h 2015-05-25 12:41:57 UTC (rev 10475)
@@ -33,6 +33,7 @@
#include <cassert>
#include <map>
+#include <set>
namespace orxonox
{
@@ -41,20 +42,20 @@
public:
static NetworkFunctionManager& getInstance();
- void setNetworkID(const std::string& name, uint32_t id);
+ void registerFunction(NetworkFunctionBase* function);
+ void unregisterFunction(NetworkFunctionBase* function);
+
void destroyAllNetworkFunctions();
- inline std::map<std::string, NetworkFunctionBase*>& getNameMap()
- { return nameMap_; }
- inline std::map<NetworkFunctionPointer, NetworkFunctionBase*>& getFunctorMap()
- { return functorMap_; }
- inline std::map<uint32_t, NetworkFunctionBase*>& getIdMap()
- { return idMap_; }
+ inline const std::set<NetworkFunctionBase*>& getAllFunctions()
+ { return functions_; }
- NetworkFunctionBase* getFunction(const NetworkFunctionPointer& p);
- NetworkFunctionBase* getFunction(uint32_t id);
+ NetworkFunctionBase* getFunctionByName(const std::string& name);
+ NetworkFunctionBase* getFunctionByFunctionPointer(const NetworkFunctionPointer& p);
+ NetworkFunctionBase* getFunctionByNetworkId(uint32_t id);
private:
+ std::set<NetworkFunctionBase*> functions_;
std::map<std::string, NetworkFunctionBase*> nameMap_;
std::map<NetworkFunctionPointer, NetworkFunctionBase*> functorMap_;
std::map<uint32_t, NetworkFunctionBase*> idMap_;
Modified: code/branches/core7/src/libraries/network/packet/FunctionIDs.cc
===================================================================
--- code/branches/core7/src/libraries/network/packet/FunctionIDs.cc 2015-05-25 12:14:16 UTC (rev 10474)
+++ code/branches/core7/src/libraries/network/packet/FunctionIDs.cc 2015-05-25 12:41:57 UTC (rev 10475)
@@ -55,12 +55,12 @@
std::queue<std::pair<uint32_t, std::string> > tempQueue;
//calculate total needed size (for all strings and integers)
- std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getInstance().getNameMap();
- std::map<std::string, NetworkFunctionBase*>::iterator it;
- for (it = map.begin(); it != map.end(); ++it)
+ const std::set<NetworkFunctionBase*>& set = NetworkFunctionManager::getInstance().getAllFunctions();
+ std::set<NetworkFunctionBase*>::const_iterator it;
+ for (it = set.begin(); it != set.end(); ++it)
{
- const std::string& functionname = it->second->getName();
- networkID = it->second->getNetworkID();
+ const std::string& functionname = (*it)->getName();
+ networkID = (*it)->getNetworkID();
// now push the network id and the classname to the stack
tempQueue.push( std::pair<unsigned int, std::string>(networkID, functionname) );
++nrOfFunctions;
@@ -139,7 +139,7 @@
stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
functionname = temp+2*sizeof(uint32_t);
orxout(internal_info, context::packets) << "processing functionid: " << networkID << " name: " << functionname << endl;
- NetworkFunctionManager::getInstance().setNetworkID((const char*)functionname, networkID);
+ NetworkFunctionManager::getInstance().getFunctionByName((const char*)functionname)->setNetworkID(networkID);
temp += 2*sizeof(uint32_t) + stringsize;
}
delete this;
More information about the Orxonox-commit
mailing list