Commit 46e2d31a authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - threadMain now moduleMain

[ADD] - proper exception handly in module threads
parent 0a8b5fbe
......@@ -56,6 +56,17 @@ WException::WException( const std::string& msg ): exception()
}
}
WException::WException( const std::exception& e ): exception( e )
{
m_msg = e.what();
// print stacktrace and message
// no backtrace?
if ( !noBacktrace )
{
std::cerr << "Exception thrown! Callstack's backtrace:" << std::endl << getBacktrace() << std::endl;
}
}
WException::~WException() throw()
{
......
......@@ -48,6 +48,13 @@ public:
*/
explicit WException( const std::string& msg = std::string() );
/**
* Copy a std::exception and encapsulate it.
*
* \param e the exception.
*/
WException( const std::exception& e );
/**
* Destructor.
*/
......
......@@ -36,6 +36,7 @@
#include "exceptions/WModuleSignalSubscriptionFailed.h"
#include "exceptions/WModuleConnectorInitFailed.h"
#include "exceptions/WModuleUninitialized.h"
#include "../common/WException.h"
#include "WModule.h"
......@@ -240,3 +241,23 @@ void WModule::connectToGui()
{
}
void WModule::threadMain()
{
try
{
// call main thread function
moduleMain();
}
catch ( WException& e )
{
// ensure proper exception propagation
signal_error( shared_from_this(), e );
}
catch ( std::exception& e )
{
// convert these exceptions to WException
WException ce = WException( e );
signal_error( shared_from_this(), ce );
}
}
......@@ -165,7 +165,12 @@ protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void threadMain() = 0;
virtual void moduleMain() = 0;
/**
* Thread entry point. Calls moduleMain and sends error notification if needed.
*/
void threadMain();
/**
* Sets the container this module is associated with.
......
......@@ -108,7 +108,7 @@ protected:
std::string n;
// required since pure virtual
virtual void threadMain()
virtual void moduleMain()
{
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
......
......@@ -47,7 +47,7 @@ boost::shared_ptr< WModule > WMCoordinateSystem::factory() const
return boost::shared_ptr< WMCoordinateSystem >( new WMCoordinateSystem() );
}
void WMCoordinateSystem::threadMain()
void WMCoordinateSystem::moduleMain()
{
createGeometry();
......
......@@ -88,7 +88,7 @@ protected:
* \par Description
* Entry point after loading the module. Runs in separate thread.
*/
virtual void threadMain();
virtual void moduleMain();
private:
/**
......
......@@ -124,7 +124,7 @@ std::string getSuffix( std::string name )
return p.extension();
}
void WMData::threadMain()
void WMData::moduleMain()
{
std::string fileName = m_properties->getValue< std::string >( "filename" );
......
......@@ -90,7 +90,7 @@ protected:
* \par Description
* Entry point after loading the module. Runs in separate thread.
*/
virtual void threadMain();
virtual void moduleMain();
/**
* Initialize connectors in this function. This function must not be called multiple times for one module instance.
......
......@@ -104,7 +104,7 @@ void drawChannel( boost::shared_ptr< const WEEG > eegData, size_t channelId, osg
sceneDataGeode->addDrawable( textOne );
}
void WMEEGTest::threadMain()
void WMEEGTest::moduleMain()
{
// load the sample scene.
//osg::Geode* sceneDataGeode = new osg::Geode();
......
......@@ -72,7 +72,7 @@ protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void threadMain();
virtual void moduleMain();
private:
};
......
......@@ -62,7 +62,7 @@ boost::shared_ptr< WModule > WMFiberClustering::factory() const
return boost::shared_ptr< WModule >( new WMFiberClustering() );
}
void WMFiberClustering::threadMain()
void WMFiberClustering::moduleMain()
{
boost::shared_ptr< WDataHandler > dataHandler;
// TODO(math): fix this hack when possible by using an input connector.
......
......@@ -79,7 +79,7 @@ protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void threadMain();
virtual void moduleMain();
private:
/**
......
......@@ -58,7 +58,7 @@ boost::shared_ptr< WModule > WMFiberCulling::factory() const
return boost::shared_ptr< WModule >( new WMFiberCulling() );
}
void WMFiberCulling::threadMain()
void WMFiberCulling::moduleMain()
{
boost::shared_ptr< WDataHandler > dataHandler;
// TODO(math): fix this hack when possible by using an input connector.
......
......@@ -76,7 +76,7 @@ protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void threadMain();
virtual void moduleMain();
/**
* Detect and removes fibers that have a short distance in terms of the
......
......@@ -97,7 +97,7 @@ osg::ref_ptr< osg::Geode > WMFiberDisplay::genFiberGeode( const wmath::WFiber &f
return geode;
}
void WMFiberDisplay::threadMain()
void WMFiberDisplay::moduleMain()
{
boost::shared_ptr< WDataHandler > dataHandler;
// TODO(math): fix this hack when possible by using an input connector.
......
......@@ -73,7 +73,7 @@ protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void threadMain();
virtual void moduleMain();
/**
* Generates an OSG geometry for the given fiber.
......
......@@ -83,7 +83,7 @@ const std::string WMMarchingCubes::getDescription() const
}
void WMMarchingCubes::threadMain()
void WMMarchingCubes::moduleMain()
{
// TODO(wiebel): MC fix this hack when possible by using an input connector.
while ( !WKernel::getRunningKernel() )
......
......@@ -122,7 +122,7 @@ protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void threadMain();
virtual void moduleMain();
/**
* Initialize the connectors this module is using.
......
......@@ -124,7 +124,7 @@ void WMNavSlices::notifyDataChange( boost::shared_ptr<WModuleConnector> input,
// in this case input==m_input
}
void WMNavSlices::threadMain()
void WMNavSlices::moduleMain()
{
createGeometry();
......
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