[Orxonox-commit 5858] r10518 - in code/branches/core7/src/libraries/core: . class module
landauf at orxonox.net
landauf at orxonox.net
Sun May 31 10:56:32 CEST 2015
Author: landauf
Date: 2015-05-31 10:56:32 +0200 (Sun, 31 May 2015)
New Revision: 10518
Modified:
code/branches/core7/src/libraries/core/Core.cc
code/branches/core7/src/libraries/core/Core.h
code/branches/core7/src/libraries/core/Game.cc
code/branches/core7/src/libraries/core/class/IdentifierManager.cc
code/branches/core7/src/libraries/core/module/ModuleInstance.cc
code/branches/core7/src/libraries/core/module/ModuleInstance.h
Log:
load modules AFTER core was initialized. load each module with a separate ModuleInstance. unloading is not yet implemented...
Modified: code/branches/core7/src/libraries/core/Core.cc
===================================================================
--- code/branches/core7/src/libraries/core/Core.cc 2015-05-31 08:54:39 UTC (rev 10517)
+++ code/branches/core7/src/libraries/core/Core.cc 2015-05-31 08:56:32 UTC (rev 10518)
@@ -110,6 +110,7 @@
, guiManager_(NULL)
, graphicsScope_(NULL)
, bGraphicsLoaded_(false)
+ , rootModule_(NULL)
, config_(NULL)
, destructionHelper_(this)
{
@@ -121,27 +122,13 @@
// Create a new dynamic library manager
this->dynLibManager_ = new DynLibManager();
- // Load modules
- orxout(internal_info) << "Loading modules:" << endl;
- const std::vector<std::string>& modulePaths = ApplicationPaths::getInstance().getModulePaths();
- for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)
- {
- try
- {
- this->dynLibManager_->load(*it);
- }
- catch (...)
- {
- orxout(user_error) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << endl;
- }
- }
-
// TODO: initialize Root-Context
// TODO: initialize IdentifierManager here
// TODO: initialize ScopeManager here
// TODO: initialize CommandLineParser here
// TODO: initialize ConsoleCommandManager here
- ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances();
+ this->rootModule_ = ModuleInstance::getCurrentModuleInstance();
+ this->rootModule_->loadAllStaticallyInitializedInstances();
// Parse command line arguments AFTER the modules have been loaded (static code!)
CommandLineParser::parse(cmdLine);
@@ -257,6 +244,9 @@
Context::setRootContext(NULL);
IdentifierManager::getInstance().destroyAllIdentifiers();
safeObjectDelete(&signalHandler_);
+// if (this->rootModule_)
+// this->rootModule_->unloadAllStaticallyInitializedInstances();
+// safeObjectDelete(&rootModule_);
safeObjectDelete(&dynLibManager_);
safeObjectDelete(&configurablePaths_);
safeObjectDelete(&applicationPaths_);
@@ -264,6 +254,57 @@
orxout(internal_status) << "finished destroying Core object" << endl;
}
+ void Core::loadModules()
+ {
+ orxout(internal_info) << "Loading modules:" << endl;
+
+ const std::vector<std::string>& modulePaths = ApplicationPaths::getInstance().getModulePaths();
+ for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)
+ {
+ try
+ {
+ ModuleInstance* module = new ModuleInstance(*it);
+ this->loadModule(module);
+ this->modules_.push_back(module);
+ }
+ catch (...)
+ {
+ orxout(user_error) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << endl;
+ }
+ }
+
+ orxout(internal_info) << "finished loading modules" << endl;
+ }
+
+ void Core::loadModule(ModuleInstance* module)
+ {
+ ModuleInstance::setCurrentModuleInstance(module);
+ DynLib* dynLib = this->dynLibManager_->load(module->getName());
+ module->setDynLib(dynLib);
+ module->loadAllStaticallyInitializedInstances();
+ IdentifierManager::getInstance().createClassHierarchy();
+ ScopeManager::getInstance().updateListeners();
+ }
+
+ void Core::unloadModules()
+ {
+ for (std::list<ModuleInstance*>::iterator it = this->modules_.begin(); it != this->modules_.end(); ++it)
+ {
+ ModuleInstance* module = (*it);
+ this->unloadModule(module);
+ delete module;
+ }
+ this->modules_.clear();
+ }
+
+ void Core::unloadModule(ModuleInstance* module)
+ {
+ module->unloadAllStaticallyInitializedInstances();
+ module->deleteAllStaticallyInitializedInstances();
+ this->dynLibManager_->unload(module->getDynLib());
+ module->setDynLib(NULL);
+ }
+
void Core::loadGraphics()
{
orxout(internal_info) << "loading graphics in Core" << endl;
Modified: code/branches/core7/src/libraries/core/Core.h
===================================================================
--- code/branches/core7/src/libraries/core/Core.h 2015-05-31 08:54:39 UTC (rev 10517)
+++ code/branches/core7/src/libraries/core/Core.h 2015-05-31 08:56:32 UTC (rev 10518)
@@ -59,7 +59,6 @@
class _CoreExport Core : public Singleton<Core>
{
friend class Singleton<Core>;
- friend class Game;
public:
/**
@@ -76,18 +75,23 @@
/// Destructor that also executes when the object fails to construct
void destroy();
+ void preUpdate(const Clock& time);
+ void postUpdate(const Clock& time);
+
+ void loadGraphics();
+ void unloadGraphics();
+
+ void loadModules();
+ void unloadModules();
+ void loadModule(ModuleInstance* module);
+ void unloadModule(ModuleInstance* module);
+
inline CoreConfig* getConfig() const
{ return this->config_; }
private:
Core(const Core&); //!< Don't use (undefined symbol)
- void preUpdate(const Clock& time);
- void postUpdate(const Clock& time);
-
- void loadGraphics();
- void unloadGraphics();
-
void setThreadAffinity(int limitToCPU);
ApplicationPaths* applicationPaths_;
@@ -107,6 +111,8 @@
GUIManager* guiManager_; //!< Interface to GUI
Scope<ScopeID::GRAPHICS>* graphicsScope_;
bool bGraphicsLoaded_;
+ ModuleInstance* rootModule_;
+ std::list<ModuleInstance*>modules_;
/// Helper object that stores the config values
CoreConfig* config_;
Modified: code/branches/core7/src/libraries/core/Game.cc
===================================================================
--- code/branches/core7/src/libraries/core/Game.cc 2015-05-31 08:54:39 UTC (rev 10517)
+++ code/branches/core7/src/libraries/core/Game.cc 2015-05-31 08:56:32 UTC (rev 10518)
@@ -109,6 +109,7 @@
// Create the Core
orxout(internal_info) << "creating Core object:" << endl;
this->core_ = new Core(cmdLine);
+ this->core_->loadModules();
// Do this after the Core creation!
this->config_ = new GameConfig();
@@ -140,6 +141,8 @@
GameStateFactory::getFactories().clear();
safeObjectDelete(&config_);
+// if (this->core_)
+// this->core_->unloadModules();
safeObjectDelete(&core_);
safeObjectDelete(&gameClock_);
Modified: code/branches/core7/src/libraries/core/class/IdentifierManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/class/IdentifierManager.cc 2015-05-31 08:54:39 UTC (rev 10517)
+++ code/branches/core7/src/libraries/core/class/IdentifierManager.cc 2015-05-31 08:56:32 UTC (rev 10518)
@@ -99,6 +99,8 @@
for (std::set<Identifier*>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it)
{
Identifier* identifier = (*it);
+ if (identifier->isInitialized())
+ continue;
orxout(verbose, context::identifier) << "Initialize ClassIdentifier<" << identifier->getName() << ">-Singleton." << endl;
// To initialize the identifier, we create a new object and delete it afterwards.
@@ -134,7 +136,7 @@
if (initializedIdentifiers.find(identifier) != initializedIdentifiers.end())
identifier->finishInitialization();
- else
+ else if (!identifier->isInitialized())
orxout(internal_error) << "Identifier was registered late and is not initialized: " << identifier->getName() << " / " << identifier->getTypeInfo().name() << endl;
}
Modified: code/branches/core7/src/libraries/core/module/ModuleInstance.cc
===================================================================
--- code/branches/core7/src/libraries/core/module/ModuleInstance.cc 2015-05-31 08:54:39 UTC (rev 10517)
+++ code/branches/core7/src/libraries/core/module/ModuleInstance.cc 2015-05-31 08:56:32 UTC (rev 10518)
@@ -34,35 +34,48 @@
{
ModuleInstance* ModuleInstance::currentModuleInstance_s = NULL;
+ ModuleInstance::ModuleInstance(const std::string& name)
+ : name_(name)
+ , dynLib_(NULL)
+ {
+ }
+
ModuleInstance::~ModuleInstance()
{
- std::list<StaticallyInitializedInstance*> copy(this->staticallyInitializedInstances_);
- for (std::list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
- delete (*it);
+ this->deleteAllStaticallyInitializedInstances();
}
void ModuleInstance::addStaticallyInitializedInstance(StaticallyInitializedInstance* instance)
{
- this->staticallyInitializedInstances_.push_back(instance);
+ this->staticallyInitializedInstances_.insert(instance);
}
void ModuleInstance::loadAllStaticallyInitializedInstances()
{
- for (std::list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
+ for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
(*it)->load();
}
void ModuleInstance::unloadAllStaticallyInitializedInstances()
{
- for (std::list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
+ for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
(*it)->unload();
}
void ModuleInstance::removeStaticallyInitializedInstance(StaticallyInitializedInstance* instance)
{
- this->staticallyInitializedInstances_.remove(instance);
+ this->staticallyInitializedInstances_.erase(instance);
}
+ void ModuleInstance::deleteAllStaticallyInitializedInstances()
+ {
+ std::set<StaticallyInitializedInstance*> copy(this->staticallyInitializedInstances_);
+ this->staticallyInitializedInstances_.clear();
+ for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
+ delete (*it);
+ }
+
+
/*static*/ void ModuleInstance::setCurrentModuleInstance(ModuleInstance* instance)
{
ModuleInstance::currentModuleInstance_s = instance;
@@ -71,7 +84,7 @@
/*static*/ ModuleInstance* ModuleInstance::getCurrentModuleInstance()
{
if (!ModuleInstance::currentModuleInstance_s)
- ModuleInstance::currentModuleInstance_s = new ModuleInstance();
+ ModuleInstance::currentModuleInstance_s = new ModuleInstance("");
return ModuleInstance::currentModuleInstance_s;
}
}
Modified: code/branches/core7/src/libraries/core/module/ModuleInstance.h
===================================================================
--- code/branches/core7/src/libraries/core/module/ModuleInstance.h 2015-05-31 08:54:39 UTC (rev 10517)
+++ code/branches/core7/src/libraries/core/module/ModuleInstance.h 2015-05-31 08:56:32 UTC (rev 10518)
@@ -31,25 +31,38 @@
#include "core/CorePrereqs.h"
-#include <list>
+#include <set>
+#include <string>
namespace orxonox
{
class _CoreExport ModuleInstance
{
public:
+ ModuleInstance(const std::string& name);
~ModuleInstance();
void addStaticallyInitializedInstance(StaticallyInitializedInstance* instance);
void loadAllStaticallyInitializedInstances();
void unloadAllStaticallyInitializedInstances();
void removeStaticallyInitializedInstance(StaticallyInitializedInstance* instance);
+ void deleteAllStaticallyInitializedInstances();
+ inline const std::string& getName() const
+ { return this->name_; }
+
+ inline void setDynLib(DynLib* dynLib)
+ { this->dynLib_ = dynLib; }
+ inline DynLib* getDynLib() const
+ { return this->dynLib_; }
+
static void setCurrentModuleInstance(ModuleInstance* instance);
static ModuleInstance* getCurrentModuleInstance();
private:
- std::list<StaticallyInitializedInstance*> staticallyInitializedInstances_;
+ std::set<StaticallyInitializedInstance*> staticallyInitializedInstances_;
+ std::string name_;
+ DynLib* dynLib_;
static ModuleInstance* currentModuleInstance_s;
};
More information about the Orxonox-commit
mailing list