[Orxonox-commit 5808] r10468 - in code/branches/core7/src: libraries/network libraries/network/packet orxonox/gamestates

landauf at orxonox.net landauf at orxonox.net
Mon May 25 12:13:27 CEST 2015


Author: landauf
Date: 2015-05-25 12:13:27 +0200 (Mon, 25 May 2015)
New Revision: 10468

Added:
   code/branches/core7/src/libraries/network/NetworkFunctionManager.cc
   code/branches/core7/src/libraries/network/NetworkFunctionManager.h
Modified:
   code/branches/core7/src/libraries/network/CMakeLists.txt
   code/branches/core7/src/libraries/network/NetworkFunction.cc
   code/branches/core7/src/libraries/network/NetworkFunction.h
   code/branches/core7/src/libraries/network/packet/FunctionIDs.cc
   code/branches/core7/src/orxonox/gamestates/GSRoot.cc
Log:
moved static content of NetworkFunctionBase to NetworkFunctionManager

Modified: code/branches/core7/src/libraries/network/CMakeLists.txt
===================================================================
--- code/branches/core7/src/libraries/network/CMakeLists.txt	2015-05-25 09:50:15 UTC (rev 10467)
+++ code/branches/core7/src/libraries/network/CMakeLists.txt	2015-05-25 10:13:27 UTC (rev 10468)
@@ -33,6 +33,7 @@
   WANDiscovery.cc
   MasterServerComm.cc
   NetworkFunction.cc
+  NetworkFunctionManager.cc
   Host.cc
   Server.cc
   MasterServer.cc
@@ -60,6 +61,7 @@
   MasterServerComm.h
   NetworkChatListener.h
   NetworkFunction.h
+  NetworkFunctionManager.h
   NetworkPrecompiledHeaders.h
   NetworkPrereqs.h
   Server.h

Modified: code/branches/core7/src/libraries/network/NetworkFunction.cc
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunction.cc	2015-05-25 09:50:15 UTC (rev 10467)
+++ code/branches/core7/src/libraries/network/NetworkFunction.cc	2015-05-25 10:13:27 UTC (rev 10468)
@@ -27,12 +27,11 @@
  */
 
 #include "NetworkFunction.h"
+#include "NetworkFunctionManager.h"
 #include "core/CoreIncludes.h"
 
 namespace orxonox
 {
-  std::map<uint32_t, bool> NetworkFunctionBase::isStaticMap_;
-
   std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::functorMap_;
   std::map<uint32_t, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::idMap_;
 
@@ -49,29 +48,13 @@
     this->networkID_ = networkID++;
 
     this->name_ = name;
-    NetworkFunctionBase::getNameMap()[name] = this;
+    NetworkFunctionManager::getNameMap()[name] = this;
   }
   NetworkFunctionBase::~NetworkFunctionBase()
   {
   }
 
 
-  void NetworkFunctionBase::destroyAllNetworkFunctions()
-  {
-    std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionBase::getNameMap();
-    std::map<std::string, NetworkFunctionBase*>::iterator it;
-    for( it=map.begin(); it!=map.end(); ++it )
-      delete it->second;
-  }
-
-
-  /*static*/ std::map<std::string, NetworkFunctionBase*>& NetworkFunctionBase::getNameMap()
-  {
-    static std::map<std::string, NetworkFunctionBase*> nameMap_;
-    return nameMap_;
-  }
-
-
   NetworkFunctionStatic::NetworkFunctionStatic(const FunctorStaticPtr& functor, const std::string& name, const NetworkFunctionPointer& p):
     NetworkFunctionBase(name)
   {

Modified: code/branches/core7/src/libraries/network/NetworkFunction.h
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunction.h	2015-05-25 09:50:15 UTC (rev 10467)
+++ code/branches/core7/src/libraries/network/NetworkFunction.h	2015-05-25 10:13:27 UTC (rev 10468)
@@ -76,22 +76,8 @@
     virtual void        setNetworkID(uint32_t id)       { this->networkID_ = id; }
     inline uint32_t     getNetworkID() const            { return this->networkID_; }
     inline const std::string& getName() const           { return name_; }
-    static inline bool  isStatic( uint32_t networkID )  { return isStaticMap_[networkID]; }
 
-    static inline void setNetworkID(const std::string& name, uint32_t id)
-    {
-        std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionBase::getNameMap();
-        assert( map.find(name)!=map.end() );
-        map[name]->setNetworkID(id);
-    }
-
-    static void destroyAllNetworkFunctions();
-
-  protected:
-    static std::map<uint32_t, bool> isStaticMap_;
-
   private:
-    static std::map<std::string, NetworkFunctionBase*>& getNameMap();
     uint32_t networkID_;
     std::string name_;
 

Added: code/branches/core7/src/libraries/network/NetworkFunctionManager.cc
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunctionManager.cc	                        (rev 0)
+++ code/branches/core7/src/libraries/network/NetworkFunctionManager.cc	2015-05-25 10:13:27 UTC (rev 10468)
@@ -0,0 +1,62 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "NetworkFunctionManager.h"
+#include "NetworkFunction.h"
+
+namespace orxonox
+{
+    std::map<uint32_t, bool> NetworkFunctionManager::isStaticMap_;
+
+    /* static */NetworkFunctionManager& NetworkFunctionManager::getInstance()
+    {
+        static NetworkFunctionManager instance;
+        return instance;
+    }
+
+    /*static*/void NetworkFunctionManager::setNetworkID(const std::string& name, uint32_t id)
+    {
+        std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getNameMap();
+        assert( map.find(name)!=map.end() );
+        map[name]->setNetworkID(id);
+    }
+
+    /*static*/void NetworkFunctionManager::destroyAllNetworkFunctions()
+    {
+        std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getNameMap();
+        std::map<std::string, NetworkFunctionBase*>::iterator it;
+        for (it = map.begin(); it != map.end(); ++it)
+            delete it->second;
+    }
+
+    /*static*/std::map<std::string, NetworkFunctionBase*>& NetworkFunctionManager::getNameMap()
+    {
+        static std::map<std::string, NetworkFunctionBase*> nameMap_;
+        return nameMap_;
+    }
+}

Added: code/branches/core7/src/libraries/network/NetworkFunctionManager.h
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunctionManager.h	                        (rev 0)
+++ code/branches/core7/src/libraries/network/NetworkFunctionManager.h	2015-05-25 10:13:27 UTC (rev 10468)
@@ -0,0 +1,54 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef __NetworkFunctionManager_H__
+#define __NetworkFunctionManager_H__
+
+#include "NetworkPrereqs.h"
+
+#include <cassert>
+#include <map>
+
+namespace orxonox
+{
+    class _NetworkExport NetworkFunctionManager
+    {
+        public:
+            static NetworkFunctionManager& getInstance();
+
+            static inline bool  isStatic( uint32_t networkID )  { return isStaticMap_[networkID]; }
+            static void setNetworkID(const std::string& name, uint32_t id);
+            static void destroyAllNetworkFunctions();
+            static std::map<std::string, NetworkFunctionBase*>& getNameMap();
+
+          private:
+            static std::map<uint32_t, bool> isStaticMap_;
+    };
+}
+
+#endif /* __NetworkFunctionManager_H__ */

Modified: code/branches/core7/src/libraries/network/packet/FunctionIDs.cc
===================================================================
--- code/branches/core7/src/libraries/network/packet/FunctionIDs.cc	2015-05-25 09:50:15 UTC (rev 10467)
+++ code/branches/core7/src/libraries/network/packet/FunctionIDs.cc	2015-05-25 10:13:27 UTC (rev 10468)
@@ -36,6 +36,7 @@
 #include "util/Output.h"
 #include "core/object/ObjectList.h"
 #include "network/NetworkFunction.h"
+#include "network/NetworkFunctionManager.h"
 
 namespace orxonox {
 namespace packet {
@@ -137,7 +138,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;
-    NetworkFunctionBase::setNetworkID((const char*)functionname, networkID);
+    NetworkFunctionManager::setNetworkID((const char*)functionname, networkID);
     temp += 2*sizeof(uint32_t) + stringsize;
   }
   delete this;

Modified: code/branches/core7/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/core7/src/orxonox/gamestates/GSRoot.cc	2015-05-25 09:50:15 UTC (rev 10467)
+++ code/branches/core7/src/orxonox/gamestates/GSRoot.cc	2015-05-25 10:13:27 UTC (rev 10468)
@@ -34,6 +34,7 @@
 #include "core/GameMode.h"
 #include "core/command/ConsoleCommandIncludes.h"
 #include "network/NetworkFunctionIncludes.h"
+#include "network/NetworkFunctionManager.h"
 #include "tools/Timer.h"
 #include "tools/interfaces/Tickable.h"
 
@@ -67,7 +68,7 @@
 
     GSRoot::~GSRoot()
     {
-        NetworkFunctionBase::destroyAllNetworkFunctions();
+        NetworkFunctionManager::destroyAllNetworkFunctions();
     }
 
     void GSRoot::printObjects()




More information about the Orxonox-commit mailing list