Commit 5079d5bf authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - WQt4Gui now posts QT events for crashed modules

parent 00282618
......@@ -379,7 +379,7 @@ void WMainWindow::projectLoad()
fd.setFileMode( QFileDialog::ExistingFiles );
QStringList filters;
filters << "Simple Project File (*.prj)"
filters << "Simple Project File (*.owproj)"
<< "Any files (*)";
fd.setNameFilters( filters );
fd.setViewMode( QFileDialog::Detail );
......
......@@ -32,17 +32,20 @@
#include <QtGui/QApplication>
#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
#include "WMainWindow.h" // this has to be included before any other includes
#include "../../common/WConditionOneShot.h"
#include "../../common/WIOTools.h"
#include "../../graphicsEngine/WGraphicsEngine.h"
#include "../../kernel/WKernel.h"
#include "../../kernel/WModuleProjectFileCombiner.h"
#include "WOpenCustomDockWidgetEvent.h"
#include "WQt4Gui.h"
#include "events/WModuleAssocEvent.h"
#include "events/WRoiAssocEvent.h"
#include "events/WModuleReadyEvent.h"
#include "events/WModuleCrashEvent.h"
WQt4Gui::WQt4Gui( int argc, char** argv )
: WGUI( argc, argv )
......@@ -67,6 +70,7 @@ bool WQt4Gui::parseOptions()
// TODO(wiebel): this does not link on windows at the moment. But it should!
desc.add_options()
( "help,h", "Prints this help message" )
( "project,p", po::value< std::string >(), "Project file to be loaded on startup." )
( "input,i", po::value< std::vector< std::string > >(), "Input data files that should be loaded automatically" )
( "timed-output,t", "Flag indicating if all log strings should have a time string preceding" );
//#endif
......@@ -99,6 +103,11 @@ bool WQt4Gui::parseOptions()
return true;
}
void WQt4Gui::moduleError( boost::shared_ptr< WModule > module, const WException& exception )
{
QCoreApplication::postEvent( m_mainWindow, new WModuleCrashEvent( module, exception.what() ) );
}
int WQt4Gui::run()
{
bool parsingSuccessful = parseOptions();
......@@ -125,6 +134,9 @@ int WQt4Gui::run()
// and startup kernel
m_kernel = boost::shared_ptr< WKernel >( new WKernel( 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 );
// create the window
m_mainWindow = new WMainWindow();
m_mainWindow->show();
......@@ -155,6 +167,21 @@ int WQt4Gui::run()
m_kernel->loadDataSets( m_optionsMap["input"].as< std::vector< std::string > >() );
}
// Load project file
if( m_optionsMap.count("project") )
{
try
{
WModuleProjectFileCombiner proj = WModuleProjectFileCombiner( m_optionsMap["project"].as< std::string >() );
proj.apply();
}
catch ( const WException& e )
{
wlog::error( "GUI" ) << "Project file \"" << m_optionsMap["project"].as< std::string >() << "\" could not be loaded. Message: " <<
e.what();
}
}
// run
int qtRetCode = appl.exec();
......
......@@ -122,6 +122,14 @@ public:
protected:
/**
* Called whenever a module crashes.
*
* \param module the module which has thrown the exception
* \param exception the exception the module has thrown
*/
void moduleError( boost::shared_ptr< WModule > module, const WException& exception );
private:
/**
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WEventTypes.h"
#include "WModuleCrashEvent.h"
WModuleCrashEvent::WModuleCrashEvent( boost::shared_ptr< WModule > module, std::string message )
: QEvent( static_cast< QEvent::Type >( WQT_READY_EVENT ) ),
m_module( module ),
m_message( message )
{
// initialize members
}
WModuleCrashEvent::~WModuleCrashEvent()
{
// cleanup
}
boost::shared_ptr< WModule > WModuleCrashEvent::getModule()
{
return m_module;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMODULECRASHEVENT_H
#define WMODULECRASHEVENT_H
#include <string>
#include <boost/shared_ptr.hpp>
#include <QtCore/QEvent>
#include "../../../kernel/WModule.h"
/**
* Event signalling a new module has been associated with the root container in the kernel. Please note that it is possible that
* the module is already marked as "ready" while processing this event due to the multithreading.
*/
class WModuleCrashEvent: public QEvent
{
public:
/**
* Creates a new event instance denoting that the specified module got associated in the root container.
*
* \param module the module that switched its state.
* \param message the crash message.
*/
WModuleCrashEvent( boost::shared_ptr< WModule > module, std::string message );
/**
* Destructor.
*/
virtual ~WModuleCrashEvent();
/**
* Getter for the module that got associated.
*
* \return the module.
*/
boost::shared_ptr< WModule > getModule();
protected:
/**
* The module that got associated.
*/
boost::shared_ptr< WModule > m_module;
/**
* The crash message.
*/
std::string m_message;
private:
};
#endif // WMODULECRASHEVENT_H
......@@ -245,7 +245,7 @@ boost::signals2::connection WModule::subscribeSignal( MODULE_SIGNAL signal, t_Mo
switch (signal)
{
case WM_ERROR:
signal_error.connect( notifier );
return signal_error.connect( notifier );
default:
std::ostringstream s;
s << "Could not subscribe to unknown signal.";
......
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