Commit d69c6d4c authored by Alexander Wiebel's avatar Alexander Wiebel

[FIX #401] mad constructor protected because class is a singleton

parent a47af608
......@@ -150,7 +150,7 @@ int WQt4Gui::run()
m_ge = WGraphicsEngine::getGraphicsEngine();
// and startup kernel
m_kernel = boost::shared_ptr< WKernel >( new WKernel( m_ge, shared_from_this() ) );
m_kernel = boost::shared_ptr< WKernel >( WKernel::instance( m_ge, shared_from_this() ) );
m_kernel->run();
t_ModuleErrorSignalHandlerType func = boost::bind( &WQt4Gui::moduleError, this, _1, _2 );
m_kernel->getRootContainer()->addDefaultNotifier( WM_ERROR, func );
......
......@@ -50,7 +50,7 @@
/**
* Used for program wide access to the kernel.
*/
WKernel* kernel = NULL;
WKernel* WKernel::m_kernel = NULL;
WKernel::WKernel( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui ):
WThreadedRunner()
......@@ -58,7 +58,7 @@ WKernel::WKernel( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WG
WLogger::getLogger()->addLogMessage( "Initializing Kernel", "Kernel", LL_INFO );
// init the singleton
kernel = this;
m_kernel = this;
// initialize members
m_gui = gui;
......@@ -74,6 +74,16 @@ WKernel::~WKernel()
WLogger::getLogger()->addLogMessage( "Shutting down Kernel", "Kernel", LL_INFO );
}
WKernel* WKernel::instance( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui )
{
if( m_kernel == NULL )
{
new WKernel( ge, gui ); // m_kernel will be set in the constructor.
}
return m_kernel;
}
void WKernel::init()
{
// initialize
......@@ -99,7 +109,7 @@ void WKernel::init()
WKernel* WKernel::getRunningKernel()
{
return kernel;
return m_kernel;
}
boost::shared_ptr< WGraphicsEngine > WKernel::getGraphicsEngine() const
......
......@@ -64,12 +64,15 @@ class OWKERNEL_EXPORT WKernel: public WThreadedRunner
public:
/**
* Constructor. Awaits an INITIALIZED graphics engine an gui.
* Returns pointer to the running kernel or a new if no kernel was there.
* If a running kernel exists the function return it and does not check if
* ge and gui of the running kernel are equivalent to the ones given as parameters.
*
* \param ge initialized graphics engine.
* \param gui initialized gui.
* \return the kernel instance.
*/
WKernel( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui );
static WKernel* instance( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui );
/**
* Destructor.
......@@ -155,6 +158,14 @@ public:
boost::shared_ptr< WSelectionManager>getSelectionManager();
protected:
/**
* Constructor is protected because this class is a singleton. Awaits an INITIALIZED graphics engine an gui.
*
* \param ge initialized graphics engine.
* \param gui initialized gui.
*/
WKernel( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui );
/**
* Function that has to be overwritten for execution. It gets executed in a separate thread after run()
......@@ -202,6 +213,11 @@ private:
* Initializes the graphics engine, data handler and so on.
*/
void init();
/**
* Pointer to the unique instance of this singleton class.
*/
static WKernel* m_kernel;
};
#endif // WKERNEL_H
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment