Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1792 for code/trunk


Ignore:
Timestamp:
Sep 16, 2008, 8:45:13 PM (16 years ago)
Author:
rgrieder
Message:

Changed initialisation of TclThreadManager, TclBind and Shell to match the simple singleton concept (runtime assert in the c'tor).
That simplifies things a lot. The instances now 'belong' to GSRoot.

Location:
code/trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/IRC.cc

    r1784 r1792  
    2727 */
    2828
     29#include "IRC.h"
     30
    2931#include <boost/thread/thread.hpp>
    30 
    31 #include "IRC.h"
    3232#include "ConsoleCommand.h"
    3333#include "TclThreadManager.h"
  • code/trunk/src/core/Shell.cc

    r1755 r1792  
    5050    SetConsoleCommandShortcut(OutputHandler, debug);
    5151
     52    Shell* Shell::singletonRef_s = 0;
     53
    5254    Shell::Shell()
    5355    {
     56        assert(singletonRef_s == 0);
     57        singletonRef_s = this;
     58
     59        int level = Core::getSoftDebugLevel(OutputHandler::LD_Shell);
     60        Core::setSoftDebugLevel(OutputHandler::LD_Shell, -1);
     61
    5462        RegisterRootObject(Shell);
    5563
     
    7078
    7179        this->setConfigValues();
     80
     81        Core::setSoftDebugLevel(OutputHandler::LD_Shell, level);
    7282    }
    7383
     
    7686        if (this->inputBuffer_)
    7787            delete this->inputBuffer_;
    78     }
    79 
    80     Shell& Shell::createShell()
    81     {
    82         int level = Core::getSoftDebugLevel(OutputHandler::LD_Shell);
    83         Core::setSoftDebugLevel(OutputHandler::LD_Shell, -1);
    84         static Shell instance;
    85         Core::setSoftDebugLevel(OutputHandler::LD_Shell, level);
    86         return instance;
    87     }
    88 
    89     Shell& Shell::getInstance()
    90     {
    91         static Shell& instance = createShell();
    92         return instance;
     88        singletonRef_s = 0;
    9389    }
    9490
  • code/trunk/src/core/Shell.h

    r1755 r1792  
    3030#define _Shell_H__
    3131
     32#include "CorePrereqs.h"
     33
    3234#include <list>
    3335#include <vector>
    34 
    35 #include "CorePrereqs.h"
    3636
    3737#include "OrxonoxClass.h"
     
    6060    {
    6161        public:
    62             static Shell& getInstance();
    63             static Shell& createShell();
     62            Shell();
     63            virtual ~Shell();
     64
     65            static Shell& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    6466
    6567            static void clearShell();
     
    104106
    105107        private:
    106             Shell();
    107108            Shell(const Shell& other);
    108             virtual ~Shell();
    109109
    110110            void configureInputBuffer();
     
    142142            unsigned int historyOffset_;
    143143            bool bAddOutputLevel_;
     144
     145            static Shell* singletonRef_s;
    144146    };
    145147}
  • code/trunk/src/core/TclBind.cc

    r1747 r1792  
    2727 */
    2828
     29#include "TclBind.h"
     30
    2931#include <iostream>
    3032#include <string>
    31 
    3233#include "ConsoleCommand.h"
    3334#include "CommandExecutor.h"
    3435#include "TclThreadManager.h"
    35 #include "TclBind.h"
    3636#include "util/Debug.h"
    3737#include "util/String.h"
     
    4242    SetConsoleCommandShortcut(TclBind, bgerror);
    4343
    44     TclBind::TclBind()
     44    TclBind* TclBind::singletonRef_s = 0;
     45
     46    TclBind::TclBind(const std::string& datapath)
    4547    {
     48        assert(singletonRef_s == 0);
     49        singletonRef_s = this;
    4650        this->interpreter_ = 0;
    4751        this->bSetTclLibPath_ = false;
     52        this->setDataPath(datapath);
    4853    }
    4954
     
    5257        if (this->interpreter_)
    5358            delete this->interpreter_;
    54     }
    55 
    56     TclBind& TclBind::getInstance()
    57     {
    58         static TclBind instance;
    59         return instance;
     59        singletonRef_s = 0;
    6060    }
    6161
  • code/trunk/src/core/TclBind.h

    r1505 r1792  
    3939    {
    4040        public:
    41             static TclBind& getInstance();
     41            TclBind(const std::string& datapath);
     42            ~TclBind();
     43
     44            static TclBind& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    4245
    4346            static std::string tcl(const std::string& tclcode);
     
    5659
    5760        private:
    58             TclBind();
    5961            TclBind(const TclBind& other);
    60             ~TclBind();
    6162
    6263            Tcl::interpreter* interpreter_;
    6364            std::string tclLibPath_;
    6465            bool bSetTclLibPath_;
     66
     67            static TclBind* singletonRef_s;
    6568    };
    6669}
  • code/trunk/src/core/TclThreadManager.cc

    r1786 r1792  
    2727 */
    2828
     29#include "TclThreadManager.h"
     30
    2931#include <iostream>
    3032#include <string>
    31 
    3233#include <boost/thread/thread.hpp>
    3334#include <boost/bind.hpp>
    34 
    3535#include <OgreTimer.h>
    3636
     
    3939#include "CommandExecutor.h"
    4040#include "TclBind.h"
    41 #include "TclThreadManager.h"
    4241#include "util/Debug.h"
    4342#include "util/Convert.h"
     
    5958    SetConsoleCommand(TclThreadManager, flush,   false).argumentCompleter(0, autocompletion::tclthreads());
    6059
    61     TclThreadManager::TclThreadManager()
     60    TclThreadManager* TclThreadManager::singletonRef_s = 0;
     61
     62    TclThreadManager::TclThreadManager(Tcl::interpreter* interpreter)
    6263    {
    6364        RegisterRootObject(TclThreadManager);
     65
     66        assert(singletonRef_s == 0);
     67        singletonRef_s = this;
    6468
    6569        this->threadCounter_ = 0;
    6670        this->orxonoxInterpreterBundle_.id_ = 0;
    67         this->orxonoxInterpreterBundle_.interpreter_ = TclBind::getInstance().getTclInterpreter();
     71        this->orxonoxInterpreterBundle_.interpreter_ = interpreter;
    6872#if (BOOST_VERSION >= 103500)
    6973        this->threadID_ = boost::this_thread::get_id();
     
    8488        }
    8589        this->destroy(threadID);
    86     }
    87 
    88     TclThreadManager& TclThreadManager::getInstance()
    89     {
    90         static TclThreadManager instance;
    91         return instance;
     90
     91        singletonRef_s = 0;
    9292    }
    9393
  • code/trunk/src/core/TclThreadManager.h

    r1747 r1792  
    7373
    7474        public:
    75             static TclThreadManager& getInstance();
     75            TclThreadManager(Tcl::interpreter* interpreter);
     76            ~TclThreadManager();
     77
     78            static TclThreadManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    7679
    7780            static unsigned int create();
     
    9295
    9396        private:
    94             TclThreadManager();
    9597            TclThreadManager(const TclThreadManager& other);
    96             ~TclThreadManager();
    9798
    9899            static void tcl_execute(Tcl::object const &args);
     
    130131            boost::thread threadID_;
    131132#endif
     133
     134            static TclThreadManager* singletonRef_s;
    132135    };
    133136
  • code/trunk/src/orxonox/gamestates/GSRoot.cc

    r1764 r1792  
    3333#include <OgreRoot.h>
    3434
    35 //#include "util/SubString.h"
    3635#include "util/Exception.h"
    3736#include "util/Debug.h"
     
    4241#include "core/ConsoleCommand.h"
    4342#include "core/CommandLine.h"
     43#include "core/Shell.h"
    4444#include "core/TclBind.h"
    4545#include "core/TclThreadManager.h"
     
    7373        , ogreLogger_(0)
    7474        , graphicsEngine_(0)
     75        , tclBind_(0)
     76        , tclThreadManager_(0)
     77        , shell_(0)
    7578    {
    7679        RegisterRootObject(GSRoot);
     
    120123
    121124        // initialise TCL
    122         TclBind::getInstance().setDataPath(Settings::getDataPath());
    123         TclThreadManager::getInstance();
     125        this->tclBind_ = new TclBind(Settings::getDataPath());
     126        this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());
     127
     128        // create a shell
     129        this->shell_ = new Shell();
    124130
    125131        setupOgre();
     
    149155    void GSRoot::leave()
    150156    {
     157        // TODO: remove and destroy console commands
     158
    151159        delete graphicsEngine_;
    152160
     
    160168#endif
    161169
     170        delete this->shell_;
     171        delete this->tclThreadManager_;
     172        delete this->tclBind_;
     173
    162174        delete settings_;
    163175
    164         // TODO: remove and destroy console commands
    165176    }
    166177
  • code/trunk/src/orxonox/gamestates/GSRoot.h

    r1755 r1792  
    6565        Ogre::LogManager*     ogreLogger_;
    6666        GraphicsEngine*       graphicsEngine_;   //!< Interface to Ogre
     67        TclBind*              tclBind_;
     68        TclThreadManager*     tclThreadManager_;
     69        Shell*                shell_;
    6770
    6871        std::string           ogreConfigFile_;        //!< ogre config file name
Note: See TracChangeset for help on using the changeset viewer.