Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 6, 2015, 11:52:25 PM (9 years ago)
Author:
landauf
Message:

statically initialized instances are now registered with a type. CoreStaticInitializationHandler initializes all instances in core, NetworkStaticInitializationHandler initializes all instances in network.

Location:
code/branches/core7/src/libraries
Files:
2 added
18 edited

Legend:

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

    r10532 r10535  
    126126        this->dynLibManager_ = new DynLibManager();
    127127
    128         // TODO: initialize StaticInitializationManager
    129         this->staticInitHandler_ = new CoreStaticInitializationHandler();
    130         StaticInitializationManager::getInstance().addHandler(this->staticInitHandler_);
    131 
    132128        // TODO: initialize Root-Context
    133129        // TODO: initialize IdentifierManager here
     
    136132        // TODO: initialize ConsoleCommandManager here
    137133        // TODO: initialize NetworkFunctionManager here
     134        // TODO: initialize StaticInitializationManager
     135        this->staticInitHandler_ = new CoreStaticInitializationHandler();
     136        StaticInitializationManager::getInstance().addHandler(this->staticInitHandler_);
     137
    138138        this->rootModule_ = ModuleInstance::getCurrentModuleInstance();
    139         this->rootModule_->loadAllStaticallyInitializedInstances(0);
     139        StaticInitializationManager::getInstance().loadModule(this->rootModule_);
    140140
    141141        // Parse command line arguments AFTER the modules have been loaded (static code!)
     
    198198        // creates the class hierarchy for all classes with factories
    199199        orxout(internal_info) << "creating class hierarchy" << endl;
    200         IdentifierManager::getInstance().createClassHierarchy();
     200        this->staticInitHandler_->initInstances(this->rootModule_);
     201        this->staticInitHandler_->setInitInstances(true);
    201202
    202203        // Loader
     
    253254        if (this->rootModule_)
    254255        {
    255             this->rootModule_->unloadAllStaticallyInitializedInstances(0);
     256            StaticInitializationManager::getInstance().unloadModule(this->rootModule_);
    256257            this->rootModule_->deleteAllStaticallyInitializedInstances();
    257258        }
  • code/branches/core7/src/libraries/core/CoreIncludes.h

    r10530 r10535  
    226226        public:
    227227            StaticallyInitializedIdentifier(Identifier* identifier)
    228                 : StaticallyInitializedInstance(0)
     228                : StaticallyInitializedInstance(StaticInitialization::IDENTIFIER)
    229229                , identifier_(identifier)
    230230            {}
  • code/branches/core7/src/libraries/core/CorePrereqs.h

    r10532 r10535  
    8484        static const Value ROOT = 1;
    8585        static const Value GRAPHICS = 2;
     86    }
     87
     88    namespace StaticInitialization
     89    {
     90        typedef int Type;
     91
     92        static const Type STATIC_INITIALIZATION_HANDLER = 1;
     93        static const Type IDENTIFIER = 2;
     94        static const Type SCOPED_SINGLETON_WRAPPER = 3;
     95        static const Type COMMAND_LINE_ARGUMENT = 4;
     96        static const Type CONSOLE_COMMAND = 5;
    8697    }
    8798
  • code/branches/core7/src/libraries/core/CoreStaticInitializationHandler.cc

    r10532 r10535  
    4747    void CoreStaticInitializationHandler::loadModule(ModuleInstance* module)
    4848    {
    49         module->loadAllStaticallyInitializedInstances(0);
     49        this->loadInstances(module);
     50        if (this->bInitInstances_)
     51            this->initInstances(module);
     52    }
     53
     54    void CoreStaticInitializationHandler::loadInstances(ModuleInstance* module)
     55    {
     56        // the order of initialization is important
     57        module->loadAllStaticallyInitializedInstances(StaticInitialization::STATIC_INITIALIZATION_HANDLER);
     58        module->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
     59        module->loadAllStaticallyInitializedInstances(StaticInitialization::SCOPED_SINGLETON_WRAPPER);
     60        module->loadAllStaticallyInitializedInstances(StaticInitialization::COMMAND_LINE_ARGUMENT);
     61        module->loadAllStaticallyInitializedInstances(StaticInitialization::CONSOLE_COMMAND);
     62    }
     63
     64    void CoreStaticInitializationHandler::initInstances(ModuleInstance* module)
     65    {
    5066        IdentifierManager::getInstance().createClassHierarchy();
    5167        ScopeManager::getInstance().updateListeners();
     
    5470    void CoreStaticInitializationHandler::unloadModule(ModuleInstance* module)
    5571    {
    56         module->unloadAllStaticallyInitializedInstances(0);
     72        // inverted order of initialization
     73        module->unloadAllStaticallyInitializedInstances(StaticInitialization::CONSOLE_COMMAND);
     74        module->unloadAllStaticallyInitializedInstances(StaticInitialization::COMMAND_LINE_ARGUMENT);
     75        module->unloadAllStaticallyInitializedInstances(StaticInitialization::SCOPED_SINGLETON_WRAPPER);
     76        module->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
     77        module->unloadAllStaticallyInitializedInstances(StaticInitialization::STATIC_INITIALIZATION_HANDLER);
    5778    }
    5879}
  • code/branches/core7/src/libraries/core/CoreStaticInitializationHandler.h

    r10532 r10535  
    3838    class _CoreExport CoreStaticInitializationHandler : public StaticInitializationHandler
    3939    {
     40        friend class Core;
     41
    4042        public:
     43            CoreStaticInitializationHandler() : bInitInstances_(false) {}
     44
    4145            virtual void setupHandler();
    4246            virtual void shutdownHandler();
     
    4448            virtual void loadModule(ModuleInstance* module);
    4549            virtual void unloadModule(ModuleInstance* module);
     50
     51            inline void setInitInstances(bool bInitInstances)
     52                { this->bInitInstances_ = bInitInstances; }
     53
     54        private:
     55            void loadInstances(ModuleInstance* module);
     56            void initInstances(ModuleInstance* module);
     57
     58            bool bInitInstances_;
    4659    };
    4760}
  • code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.h

    r10530 r10535  
    311311        public:
    312312            StaticallyInitializedConsoleCommand(ConsoleCommand* command)
    313                 : StaticallyInitializedInstance(0)
     313                : StaticallyInitializedInstance(StaticInitialization::CONSOLE_COMMAND)
    314314                , command_(command)
    315315            {}
  • code/branches/core7/src/libraries/core/commandline/CommandLineIncludes.h

    r10530 r10535  
    5959        public:
    6060            StaticallyInitializedCommandLineArgument(CommandLineArgument* argument)
    61                 : StaticallyInitializedInstance(0)
     61                : StaticallyInitializedInstance(StaticInitialization::COMMAND_LINE_ARGUMENT)
    6262                , argument_(argument)
    6363            {}
  • code/branches/core7/src/libraries/core/module/ModuleInstance.cc

    r10530 r10535  
    5656    }
    5757
    58     void ModuleInstance::loadAllStaticallyInitializedInstances(StaticallyInitializedInstance::Type type)
     58    void ModuleInstance::loadAllStaticallyInitializedInstances(StaticInitialization::Type type)
    5959    {
    6060        const std::set<StaticallyInitializedInstance*>& instances = this->staticallyInitializedInstancesByType_[type];
     
    6363    }
    6464
    65     void ModuleInstance::unloadAllStaticallyInitializedInstances(StaticallyInitializedInstance::Type type)
     65    void ModuleInstance::unloadAllStaticallyInitializedInstances(StaticInitialization::Type type)
    6666    {
    6767        const std::set<StaticallyInitializedInstance*>& instances = this->staticallyInitializedInstancesByType_[type];
     
    7272    void ModuleInstance::deleteAllStaticallyInitializedInstances()
    7373    {
    74         std::map<StaticallyInitializedInstance::Type, std::set<StaticallyInitializedInstance*> > copy(this->staticallyInitializedInstancesByType_);
     74        std::map<StaticInitialization::Type, std::set<StaticallyInitializedInstance*> > copy(this->staticallyInitializedInstancesByType_);
    7575        this->staticallyInitializedInstancesByType_.clear();
    76         for (std::map<StaticallyInitializedInstance::Type, std::set<StaticallyInitializedInstance*> >::iterator it1 = copy.begin(); it1 != copy.end(); ++it1)
     76        for (std::map<StaticInitialization::Type, std::set<StaticallyInitializedInstance*> >::iterator it1 = copy.begin(); it1 != copy.end(); ++it1)
    7777            for (std::set<StaticallyInitializedInstance*>::iterator it2 = it1->second.begin(); it2 != it1->second.end(); ++it2)
    7878                delete (*it2);
  • code/branches/core7/src/libraries/core/module/ModuleInstance.h

    r10530 r10535  
    4949            void removeStaticallyInitializedInstance(StaticallyInitializedInstance* instance);
    5050
    51             void loadAllStaticallyInitializedInstances(StaticallyInitializedInstance::Type type);
    52             void unloadAllStaticallyInitializedInstances(StaticallyInitializedInstance::Type type);
     51            void loadAllStaticallyInitializedInstances(StaticInitialization::Type type);
     52            void unloadAllStaticallyInitializedInstances(StaticInitialization::Type type);
    5353
    5454            void deleteAllStaticallyInitializedInstances();
     
    6666
    6767        private:
    68             std::map<StaticallyInitializedInstance::Type, std::set<StaticallyInitializedInstance*> > staticallyInitializedInstancesByType_;
     68            std::map<StaticInitialization::Type, std::set<StaticallyInitializedInstance*> > staticallyInitializedInstancesByType_;
    6969            std::string name_;
    7070            DynLib* dynLib_;
  • code/branches/core7/src/libraries/core/module/StaticInitializationHandlerIncludes.h

    r10531 r10535  
    4848        public:
    4949            StaticallyInitializedStaticInitializationHandler(StaticInitializationHandler* handler)
    50                 : StaticallyInitializedInstance(0)
     50                : StaticallyInitializedInstance(StaticInitialization::STATIC_INITIALIZATION_HANDLER)
    5151                , handler_(handler)
    5252            {}
  • code/branches/core7/src/libraries/core/module/StaticInitializationManager.h

    r10532 r10535  
    3838    class _CoreExport StaticInitializationManager
    3939    {
    40         friend class Core;
    41 
    4240        public:
    4341            static StaticInitializationManager& getInstance();
  • code/branches/core7/src/libraries/core/module/StaticallyInitializedInstance.cc

    r10530 r10535  
    3333namespace orxonox
    3434{
    35     StaticallyInitializedInstance::StaticallyInitializedInstance(Type type)
     35    StaticallyInitializedInstance::StaticallyInitializedInstance(StaticInitialization::Type type)
    3636    {
    3737        this->type_ = type;
  • code/branches/core7/src/libraries/core/module/StaticallyInitializedInstance.h

    r10530 r10535  
    3737    {
    3838        public:
    39             typedef int Type;
    4039
    41             StaticallyInitializedInstance(Type type);
     40            StaticallyInitializedInstance(StaticInitialization::Type type);
    4241            virtual ~StaticallyInitializedInstance();
    4342
     
    4544            virtual void unload() = 0;
    4645
    47             inline Type getType() const
     46            inline StaticInitialization::Type getType() const
    4847                { return this->type_; }
    4948
    5049        private:
    5150            ModuleInstance* module_;
    52             Type type_;
     51            StaticInitialization::Type type_;
    5352    };
    5453}
  • code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.h

    r10530 r10535  
    8181        public:
    8282            StaticallyInitializedScopedSingletonWrapper(ScopedSingletonWrapper* wrapper, ScopeID::Value scope)
    83                 : StaticallyInitializedInstance(0)
     83                : StaticallyInitializedInstance(StaticInitialization::SCOPED_SINGLETON_WRAPPER)
    8484                , wrapper_(wrapper)
    8585                , scope_(scope)
  • code/branches/core7/src/libraries/network/CMakeLists.txt

    r10478 r10535  
    3636  NetworkFunctionIncludes.cc
    3737  NetworkFunctionManager.cc
     38  NetworkStaticInitializationHandler.cc
    3839  Host.cc
    3940  Server.cc
  • code/branches/core7/src/libraries/network/NetworkFunctionIncludes.cc

    r10478 r10535  
    3030#include "NetworkFunctionManager.h"
    3131
     32#include "core/module/StaticInitializationHandlerIncludes.h"
     33#include "NetworkStaticInitializationHandler.h"
     34
    3235namespace orxonox
    3336{
     37    RegisterStaticInitializationHandler(NetworkStaticInitializationHandler);
     38
    3439    void StaticallyInitializedNetworkFunction::load()
    3540    {
  • code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h

    r10530 r10535  
    5252        public:
    5353            StaticallyInitializedNetworkFunction(NetworkFunctionBase* function)
    54                 : StaticallyInitializedInstance(0)
     54                : StaticallyInitializedInstance(StaticInitialization::NETWORK_FUNCTION)
    5555                , function_(function)
    5656            {}
  • code/branches/core7/src/libraries/network/NetworkPrereqs.h

    r8858 r10535  
    9797    }
    9898  }
     99
     100  namespace StaticInitialization
     101  {
     102    typedef int Type;
     103    static const Type NETWORK_FUNCTION = 6;
     104  }
    99105}
    100106
Note: See TracChangeset for help on using the changeset viewer.