Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10518


Ignore:
Timestamp:
May 31, 2015, 10:56:32 AM (9 years ago)
Author:
landauf
Message:

load modules AFTER core was initialized. load each module with a separate ModuleInstance. unloading is not yet implemented…

Location:
code/branches/core7/src/libraries/core
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/Core.cc

    r10509 r10518  
    111111        , graphicsScope_(NULL)
    112112        , bGraphicsLoaded_(false)
     113        , rootModule_(NULL)
    113114        , config_(NULL)
    114115        , destructionHelper_(this)
     
    121122        // Create a new dynamic library manager
    122123        this->dynLibManager_ = new DynLibManager();
    123 
    124         // Load modules
    125         orxout(internal_info) << "Loading modules:" << endl;
    126         const std::vector<std::string>& modulePaths = ApplicationPaths::getInstance().getModulePaths();
    127         for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)
    128         {
    129             try
    130             {
    131                 this->dynLibManager_->load(*it);
    132             }
    133             catch (...)
    134             {
    135                 orxout(user_error) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << endl;
    136             }
    137         }
    138124
    139125        // TODO: initialize Root-Context
     
    142128        // TODO: initialize CommandLineParser here
    143129        // TODO: initialize ConsoleCommandManager here
    144         ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances();
     130        this->rootModule_ = ModuleInstance::getCurrentModuleInstance();
     131        this->rootModule_->loadAllStaticallyInitializedInstances();
    145132
    146133        // Parse command line arguments AFTER the modules have been loaded (static code!)
     
    258245        IdentifierManager::getInstance().destroyAllIdentifiers();
    259246        safeObjectDelete(&signalHandler_);
     247//        if (this->rootModule_)
     248//            this->rootModule_->unloadAllStaticallyInitializedInstances();
     249//        safeObjectDelete(&rootModule_);
    260250        safeObjectDelete(&dynLibManager_);
    261251        safeObjectDelete(&configurablePaths_);
     
    263253
    264254        orxout(internal_status) << "finished destroying Core object" << endl;
     255    }
     256
     257    void Core::loadModules()
     258    {
     259        orxout(internal_info) << "Loading modules:" << endl;
     260
     261        const std::vector<std::string>& modulePaths = ApplicationPaths::getInstance().getModulePaths();
     262        for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)
     263        {
     264            try
     265            {
     266                ModuleInstance* module = new ModuleInstance(*it);
     267                this->loadModule(module);
     268                this->modules_.push_back(module);
     269            }
     270            catch (...)
     271            {
     272                orxout(user_error) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << endl;
     273            }
     274        }
     275
     276        orxout(internal_info) << "finished loading modules" << endl;
     277    }
     278
     279    void Core::loadModule(ModuleInstance* module)
     280    {
     281        ModuleInstance::setCurrentModuleInstance(module);
     282        DynLib* dynLib = this->dynLibManager_->load(module->getName());
     283        module->setDynLib(dynLib);
     284        module->loadAllStaticallyInitializedInstances();
     285        IdentifierManager::getInstance().createClassHierarchy();
     286        ScopeManager::getInstance().updateListeners();
     287    }
     288
     289    void Core::unloadModules()
     290    {
     291        for (std::list<ModuleInstance*>::iterator it = this->modules_.begin(); it != this->modules_.end(); ++it)
     292        {
     293            ModuleInstance* module = (*it);
     294            this->unloadModule(module);
     295            delete module;
     296        }
     297        this->modules_.clear();
     298    }
     299
     300    void Core::unloadModule(ModuleInstance* module)
     301    {
     302        module->unloadAllStaticallyInitializedInstances();
     303        module->deleteAllStaticallyInitializedInstances();
     304        this->dynLibManager_->unload(module->getDynLib());
     305        module->setDynLib(NULL);
    265306    }
    266307
  • code/branches/core7/src/libraries/core/Core.h

    r10509 r10518  
    6060    {
    6161        friend class Singleton<Core>;
    62         friend class Game;
    6362
    6463        public:
     
    7776            void destroy();
    7877
     78            void preUpdate(const Clock& time);
     79            void postUpdate(const Clock& time);
     80
     81            void loadGraphics();
     82            void unloadGraphics();
     83
     84            void loadModules();
     85            void unloadModules();
     86            void loadModule(ModuleInstance* module);
     87            void unloadModule(ModuleInstance* module);
     88
    7989            inline CoreConfig* getConfig() const
    8090                { return this->config_; }
     
    8292        private:
    8393            Core(const Core&); //!< Don't use (undefined symbol)
    84 
    85             void preUpdate(const Clock& time);
    86             void postUpdate(const Clock& time);
    87 
    88             void loadGraphics();
    89             void unloadGraphics();
    9094
    9195            void setThreadAffinity(int limitToCPU);
     
    108112            Scope<ScopeID::GRAPHICS>* graphicsScope_;
    109113            bool                      bGraphicsLoaded_;
     114            ModuleInstance*           rootModule_;
     115            std::list<ModuleInstance*>modules_;
    110116
    111117            /// Helper object that stores the config values
  • code/branches/core7/src/libraries/core/Game.cc

    r10479 r10518  
    110110        orxout(internal_info) << "creating Core object:" << endl;
    111111        this->core_ = new Core(cmdLine);
     112        this->core_->loadModules();
    112113
    113114        // Do this after the Core creation!
     
    141142        GameStateFactory::getFactories().clear();
    142143        safeObjectDelete(&config_);
     144//        if (this->core_)
     145//            this->core_->unloadModules();
    143146        safeObjectDelete(&core_);
    144147        safeObjectDelete(&gameClock_);
  • code/branches/core7/src/libraries/core/class/IdentifierManager.cc

    r10483 r10518  
    100100            {
    101101                Identifier* identifier = (*it);
     102                if (identifier->isInitialized())
     103                    continue;
    102104
    103105                orxout(verbose, context::identifier) << "Initialize ClassIdentifier<" << identifier->getName() << ">-Singleton." << endl;
     
    135137            if (initializedIdentifiers.find(identifier) != initializedIdentifiers.end())
    136138                identifier->finishInitialization();
    137             else
     139            else if (!identifier->isInitialized())
    138140                orxout(internal_error) << "Identifier was registered late and is not initialized: " << identifier->getName() << " / " << identifier->getTypeInfo().name() << endl;
    139141        }
  • code/branches/core7/src/libraries/core/module/ModuleInstance.cc

    r10404 r10518  
    3535    ModuleInstance* ModuleInstance::currentModuleInstance_s = NULL;
    3636
     37    ModuleInstance::ModuleInstance(const std::string& name)
     38        : name_(name)
     39        , dynLib_(NULL)
     40    {
     41    }
     42
    3743    ModuleInstance::~ModuleInstance()
    3844    {
    39         std::list<StaticallyInitializedInstance*> copy(this->staticallyInitializedInstances_);
    40         for (std::list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
    41             delete (*it);
     45        this->deleteAllStaticallyInitializedInstances();
    4246    }
    4347
    4448    void ModuleInstance::addStaticallyInitializedInstance(StaticallyInitializedInstance* instance)
    4549    {
    46         this->staticallyInitializedInstances_.push_back(instance);
     50        this->staticallyInitializedInstances_.insert(instance);
    4751    }
    4852
    4953    void ModuleInstance::loadAllStaticallyInitializedInstances()
    5054    {
    51         for (std::list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
     55        for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
    5256            (*it)->load();
    5357    }
     
    5559    void ModuleInstance::unloadAllStaticallyInitializedInstances()
    5660    {
    57         for (std::list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
     61        for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
    5862            (*it)->unload();
    5963    }
     
    6165    void ModuleInstance::removeStaticallyInitializedInstance(StaticallyInitializedInstance* instance)
    6266    {
    63         this->staticallyInitializedInstances_.remove(instance);
     67        this->staticallyInitializedInstances_.erase(instance);
    6468    }
     69
     70    void ModuleInstance::deleteAllStaticallyInitializedInstances()
     71    {
     72        std::set<StaticallyInitializedInstance*> copy(this->staticallyInitializedInstances_);
     73        this->staticallyInitializedInstances_.clear();
     74        for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)
     75            delete (*it);
     76    }
     77
    6578
    6679    /*static*/ void ModuleInstance::setCurrentModuleInstance(ModuleInstance* instance)
     
    7285    {
    7386        if (!ModuleInstance::currentModuleInstance_s)
    74             ModuleInstance::currentModuleInstance_s = new ModuleInstance();
     87            ModuleInstance::currentModuleInstance_s = new ModuleInstance("");
    7588        return ModuleInstance::currentModuleInstance_s;
    7689    }
  • code/branches/core7/src/libraries/core/module/ModuleInstance.h

    r10404 r10518  
    3232#include "core/CorePrereqs.h"
    3333
    34 #include <list>
     34#include <set>
     35#include <string>
    3536
    3637namespace orxonox
     
    3940    {
    4041        public:
     42            ModuleInstance(const std::string& name);
    4143            ~ModuleInstance();
    4244
     
    4547            void unloadAllStaticallyInitializedInstances();
    4648            void removeStaticallyInitializedInstance(StaticallyInitializedInstance* instance);
     49            void deleteAllStaticallyInitializedInstances();
     50
     51            inline const std::string& getName() const
     52                { return this->name_; }
     53
     54            inline void setDynLib(DynLib* dynLib)
     55                { this->dynLib_ = dynLib; }
     56            inline DynLib* getDynLib() const
     57                { return this->dynLib_; }
    4758
    4859            static void setCurrentModuleInstance(ModuleInstance* instance);
     
    5061
    5162        private:
    52             std::list<StaticallyInitializedInstance*> staticallyInitializedInstances_;
     63            std::set<StaticallyInitializedInstance*> staticallyInitializedInstances_;
     64            std::string name_;
     65            DynLib* dynLib_;
    5366
    5467            static ModuleInstance* currentModuleInstance_s;
Note: See TracChangeset for help on using the changeset viewer.