Commit 2aafc85f authored by reichenbach's avatar reichenbach
Browse files

[ADD] a new branch where modules are now build as shared libraries; works under linux atm

parent 685f3e79
......@@ -51,8 +51,8 @@
#include "../../kernel/WModuleCombiner.h"
#include "../../kernel/WModuleCombinerTypes.h"
#include "../../kernel/WProjectFile.h"
#include "../../modules/data/WMData.h"
#include "../../modules/navSlices/WMNavSlices.h"
#include "../../kernel/modules/data/WMData.h"
#include "../../kernel/modules/navSlices/WMNavSlices.h"
#include "../icons/WIcons.h"
#include "datasetbrowser/WPropertyBoolWidget.h"
#include "events/WEventTypes.h"
......
......@@ -31,7 +31,7 @@
#include <boost/program_options.hpp>
#include "../../kernel/WModule.h"
#include "../../modules/fiberDisplay/WRMROIRepresentation.h"
#include "../../kernel/modules/fiberDisplay/WRMROIRepresentation.h"
#include "../WGUI.h"
class WMainWindow;
......
......@@ -29,8 +29,8 @@
#include <QtGui/QProgressBar>
#include <QtGui/QTreeWidgetItem>
#include "../../../modules/fiberDisplay/WRMBranch.h"
#include "../../../modules/fiberDisplay/WRMROIRepresentation.h"
#include "../../../kernel/modules/fiberDisplay/WRMBranch.h"
#include "../../../kernel/modules/fiberDisplay/WRMROIRepresentation.h"
#include "WQtTreeItem.h"
class WQtRoiTreeItem;
......
......@@ -41,7 +41,7 @@
#include "../../../kernel/WModuleCombiner.h"
#include "../../../kernel/WModuleCombinerTypes.h"
#include "../../../kernel/WModuleFactory.h"
#include "../../../modules/data/WMData.h"
#include "../../../kernel/modules/data/WMData.h"
#include "../events/WEventTypes.h"
#include "../events/WModuleAssocEvent.h"
#include "../events/WModuleDeleteEvent.h"
......
......@@ -36,7 +36,7 @@
#include "../../../dataHandler/WDataSet.h"
#include "../../../graphicsEngine/WROI.h"
#include "../../../modules/fiberDisplay/WRMROIRepresentation.h"
#include "../../../kernel/modules/fiberDisplay/WRMROIRepresentation.h"
#include "../WQtCombinerToolbar.h"
#include "WQtDSBWidget.h"
#include "WQtModuleHeaderTreeItem.h"
......
......@@ -30,7 +30,7 @@
#include <QtGui/QTreeWidgetItem>
#include "../../../graphicsEngine/WROI.h"
#include "../../../modules/fiberDisplay/WRMROIRepresentation.h"
#include "../../../kernel/modules/fiberDisplay/WRMROIRepresentation.h"
#include "WQtTreeItem.h"
/**
......
......@@ -30,7 +30,7 @@
#include <QtCore/QEvent>
#include "../../../graphicsEngine/WROI.h"
#include "../../../modules/fiberDisplay/WRMROIRepresentation.h"
#include "../../../kernel/modules/fiberDisplay/WRMROIRepresentation.h"
/**
* Event signalling a new roi has been associated with the roi manager in the kernel.
......
......@@ -30,7 +30,7 @@
#include <QtCore/QEvent>
#include "../../../graphicsEngine/WROI.h"
#include "../../../modules/fiberDisplay/WRMROIRepresentation.h"
#include "../../../kernel/modules/fiberDisplay/WRMROIRepresentation.h"
/**
......
FILE( GLOB KERNEL_SRC "*.cpp" "*.h" )
FILE( GLOB_RECURSE MODULES_SRC "../modules/*.cpp" "../modules/*.h" )
FILE( GLOB_RECURSE MODULES_SRC "modules/*.cpp" "modules/*.h" )
FILE( GLOB KERNEL_EXCEPTIONS_SRC "exceptions/*.cpp" "exceptions/*.h" )
FILE( GLOB KERNEL_COMBINER_SRC "combiner/*.cpp" "combiner/*.h" )
ADD_LIBRARY( kernel ${KERNEL_SRC} ${MODULES_SRC} ${KERNEL_EXCEPTIONS_SRC} ${KERNEL_COMBINER_SRC} )
TARGET_LINK_LIBRARIES( kernel common dataHandler ge ${OPENSCENEGRAPH_LIBRARIES} )
TARGET_LINK_LIBRARIES( kernel common dataHandler ge ${OPENSCENEGRAPH_LIBRARIES} ${CMAKE_DL_LIBS} )
# Unit tests
......
......@@ -36,7 +36,7 @@
#include "../common/WLogger.h"
#include "../graphicsEngine/WGraphicsEngine.h"
#include "../gui/WGUI.h"
#include "../modules/fiberDisplay/WROIManagerFibers.h"
#include "modules/fiberDisplay/WROIManagerFibers.h"
#include "WSelectionManager.h"
#include "WModule.h"
#include "WModuleContainer.h"
......
......@@ -569,6 +569,15 @@ private:
t_ModuleErrorSignalType signal_error;
};
/**
* The following macro is used by modules so the factory can aquire a prototype instance.
*/
#define W_SHARED_LIB_ENTRY( MODULECLASS ) \
extern "C" boost::shared_ptr< WModule > createModuleInstance() \
{\
return boost::shared_ptr< WModule >( new MODULECLASS );\
}\
/**
* \defgroup modules Modules
*
......
......@@ -44,7 +44,7 @@
#include "exceptions/WModuleAlreadyAssociated.h"
#include "exceptions/WModuleSignalSubscriptionFailed.h"
#include "exceptions/WModuleUninitialized.h"
#include "../modules/data/WMData.h"
#include "modules/data/WMData.h"
#include "WModuleContainer.h"
......
......@@ -32,41 +32,6 @@
#include "WModule.h"
#include "WModuleCombiner.h"
#include "../common/WLogger.h"
#include "../modules/applyMask/WMApplyMask.h"
#include "../modules/arbitraryRois/WMArbitraryRois.h"
#include "../modules/boundingBox/WMBoundingBox.h"
#include "../modules/clusterParamDisplay/WMClusterParamDisplay.h"
#include "../modules/clusterSlicer/WMClusterSlicer.h"
#include "../modules/coordinateSystem/WMCoordinateSystem.h"
#include "../modules/dataTypeConversion/WMDataTypeConversion.h"
#include "../modules/deterministicFTMori/WMDeterministicFTMori.h"
#include "../modules/isosurfaceRaytracer/WMIsosurfaceRaytracer.h"
#include "../modules/distanceMap/WMDistanceMap.h"
#include "../modules/distanceMap/WMDistanceMapIsosurface.h"
#include "../modules/eegView/WMEEGView.h"
#include "../modules/detTractClustering/WMDetTractClustering.h"
#include "../modules/detTractCulling/WMDetTractCulling.h"
#include "../modules/fiberDisplay/WMFiberDisplay.h"
#include "../modules/fiberSelection/WMFiberSelection.h"
#include "../modules/fiberTransform/WMFiberTransform.h"
#include "../modules/gaussFiltering/WMGaussFiltering.h"
#include "../modules/imageExtractor/WMImageExtractor.h"
#include "../modules/hud/WMHud.h"
#include "../modules/lic/WMLIC.h"
#include "../modules/marchingCubes/WMMarchingCubes.h"
#include "../modules/meshReader/WMMeshReader.h"
#include "../modules/navSlices/WMNavSlices.h"
#include "../modules/probTractDisplay/WMProbTractDisplay.h"
#include "../modules/scalarSegmentation/WMScalarSegmentation.h"
#include "../modules/superquadricGlyphs/WMSuperquadricGlyphs.h"
#include "../modules/template/WMTemplate.h"
#include "../modules/triangleMeshRenderer/WMTriangleMeshRenderer.h"
#include "../modules/vectorPlot/WMVectorPlot.h"
#include "../modules/voxelizer/WMVoxelizer.h"
#include "../modules/writeNIfTI/WMWriteNIfTI.h"
#include "../modules/writeTracts/WMWriteTracts.h"
#include "../modules/splineSurface/WMSplineSurface.h"
#include "../modules/atlasSurfaces/WMAtlasSurfaces.h"
#include "combiner/WApplyCombiner.h"
#include "exceptions/WPrototypeNotUnique.h"
#include "exceptions/WPrototypeUnknown.h"
......@@ -76,7 +41,8 @@
boost::shared_ptr< WModuleFactory > WModuleFactory::m_instance = boost::shared_ptr< WModuleFactory >();
WModuleFactory::WModuleFactory():
m_prototypes()
m_prototypes(),
m_moduleLoader( "modules/" )
{
// initialize members
}
......@@ -94,43 +60,12 @@ void WModuleFactory::load()
// operation must be exclusive
PrototypeSharedContainerType::WriteTicket m_prototypeAccess = m_prototypes.getWriteTicket();
// currently the prototypes are added by hand. This will be done automatically later.
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMApplyMask() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMArbitraryRois() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMBoundingBox() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMClusterParamDisplay() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMClusterSlicer() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMCoordinateSystem() ) );
// These modules need to be added by hand. They are special, obviously.
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMData() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMDataTypeConversion() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMDeterministicFTMori() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMIsosurfaceRaytracer() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMDistanceMap() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMDistanceMapIsosurface() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMEEGView() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMDetTractClustering() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMDetTractCulling() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMFiberDisplay() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMFiberSelection() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMFiberTransform() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMGaussFiltering() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMHud() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMImageExtractor() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMLIC() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMMarchingCubes() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMMeshReader() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMNavSlices() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMProbTractDisplay() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMScalarSegmentation() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMSuperquadricGlyphs() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMTemplate() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMTriangleMeshRenderer() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMVectorPlot() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMVoxelizer() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMWriteNIfTI() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMWriteTracts() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMSplineSurface() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMAtlasSurfaces() ) );
m_moduleLoader.load( m_prototypeAccess );
// unlock as read lock is sufficient for the further steps
m_prototypeAccess.reset();
......
......@@ -33,10 +33,13 @@
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include "../modules/data/WMData.h" // this is the ONLY module with a special meaning. Every one knowing the factory also knows this
#include "modules/data/WMData.h" // this is the ONLY module with a special meaning. Every one knowing the factory also knows this
#include "modules/fiberDisplay/WMFiberDisplay.h"
#include "modules/navSlices/WMNavSlices.h"
#include "../common/WSharedAssociativeContainer.h"
#include "WModuleCombinerTypes.h"
#include "WModule.h"
#include "WModuleLoader.h"
/**
* Class able to create a new copy of an arbitrary module. It uses the Factory and Prototype design pattern.
......@@ -194,6 +197,9 @@ protected:
private:
//! Keeps handles to shared libraries and destroys them on destruction.
WModuleLoader m_moduleLoader;
/**
* Singleton instance of WModuleFactory.
*/
......
//---------------------------------------------------------------------------
//
// 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 "../common/WIOTools.h"
#include "WModuleLoader.h"
WModuleLoader::WModuleLoader( const boost::filesystem::path& relPath )
: m_path( relPath )
{
}
WModuleLoader::~WModuleLoader()
{
for( std::vector< void* >::iterator it = m_handles.begin(); it != m_handles.end(); ++it )
{
if( dlclose( *it ) != 0 )
{
WLogger::getLogger()->addLogMessage( "Couldn't close shared object handle!", "Module Loader", LL_ERROR );
}
}
m_handles.clear();
}
void WModuleLoader::load( WSharedAssociativeContainer< std::set< boost::shared_ptr< WModule > > >::WriteTicket ticket )
{
// iterate module directory, look for .so files
WAssert( boost::filesystem::exists( m_path ), "" );
for( boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator( m_path ); i != boost::filesystem::directory_iterator(); ++i )
{
if( !boost::filesystem::is_directory( *i ) && wiotools::getSuffix( i->leaf() ) == ".so" ) // linux!
{
void* handle = dlopen( i->path().native_file_string().c_str(), RTLD_NOW );
if( !handle )
{
WLogger::getLogger()->addLogMessage( "Couldn't load shared object: " + i->path().native_file_string(), "Module Loader", LL_ERROR );
WLogger::getLogger()->addLogMessage( std::string( dlerror() ), "Module Loader", LL_ERROR );
continue;
}
// try to get module prototype instance
typedef boost::shared_ptr< WModule > ( *createInstanceFunc )( void );
createInstanceFunc createInstance = reinterpret_cast< createInstanceFunc >( dlsym( handle, "createModuleInstance" ) );
if( !createInstance )
{
WLogger::getLogger()->addLogMessage( "Couldn't load prototype creator from " + i->path().native_file_string(), "Module Loader", LL_ERROR );
WLogger::getLogger()->addLogMessage( std::string( dlerror() ), "Module Loader", LL_ERROR );
continue;
}
boost::shared_ptr< WModule > m = createInstance();
if( !m )
{
WLogger::getLogger()->addLogMessage( "Couldn't aquire prototype of module from " + i->path().native_file_string(), "Module Loader", LL_ERROR );
WLogger::getLogger()->addLogMessage( std::string( dlerror() ), "Module Loader", LL_ERROR );
continue;
}
else
{
WLogger::getLogger()->addLogMessage( "Successfully loaded " + i->path().native_file_string(), "Module Loader", LL_INFO );
ticket->get().insert( m );
m_handles.push_back( handle );
}
}
}
}
//---------------------------------------------------------------------------
//
// 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 WMODULELOADER_H
#define WMODULELOADER_H
#include <dlfcn.h>
#include <string>
#include <set>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include "../common/WSharedAssociativeContainer.h"
#include "../common/WLogger.h"
#include "WModule.h"
/**
* \class WModuleLoader
*
* Loads module prototypes from shared objects in a given directory.
*/
class WModuleLoader
{
public:
/**
* Constructor.
*
* \param relPath The relative path of the module lib directory.
*/
WModuleLoader( const boost::filesystem::path& relPath );
/**
* Destructor, closes all handles to shared libraries.
*/
~WModuleLoader();
/**
* Load the module prototypes from the shared libraries.
*
* \param ticket A write ticket to a shared container.
*/
void load( WSharedAssociativeContainer< std::set< boost::shared_ptr< WModule > > >::WriteTicket ticket );
private:
//! the handles to the shared objects ( linux! )
std::vector< void* > m_handles;
//! the module path
const boost::filesystem::path m_path;
};
#endif // WMODULELOADER_H
......@@ -30,7 +30,7 @@
#include "WKernel.h"
#include "combiner/WModuleProjectFileCombiner.h"
#include "../modules/fiberDisplay/WRoiProjectFileIO.h"
#include "modules/fiberDisplay/WRoiProjectFileIO.h"
#include "../graphicsEngine/WGEProjectFileIO.h"
#include "../common/exceptions/WFileNotFound.h"
#include "../common/exceptions/WFileOpenFailed.h"
......
......@@ -25,24 +25,24 @@
#include <string>
#include <vector>
#include "../../common/WAssert.h"
#include "../../common/WIOTools.h"
#include "../../common/WPropertyHelper.h"
#include "../../dataHandler/WDataSet.h"
#include "../../dataHandler/WDataSetSingle.h"
#include "../../dataHandler/WDataSetScalar.h"
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WDataTexture3D.h"
#include "../../dataHandler/WEEG2.h"
#include "../../dataHandler/exceptions/WDHException.h"
#include "../../dataHandler/io/WLoaderBiosig.h"
#include "../../dataHandler/io/WLoaderEEGASCII.h"
#include "../../dataHandler/io/WLoaderLibeep.h"
#include "../../dataHandler/io/WLoaderNIfTI.h"
#include "../../dataHandler/io/WPagerEEGLibeep.h"
#include "../../dataHandler/io/WReaderELC.h"
#include "../../dataHandler/io/WReaderFiberVTK.h"
#include "../../../common/WAssert.h"
#include "../../../common/WIOTools.h"
#include "../../../common/WPropertyHelper.h"
#include "../../../dataHandler/WDataSet.h"
#include "../../../dataHandler/WDataSetSingle.h"
#include "../../../dataHandler/WDataSetScalar.h"
#include "../../../dataHandler/WSubject.h"
#include "../../../dataHandler/WDataHandler.h"
#include "../../../dataHandler/WDataTexture3D.h"
#include "../../../dataHandler/WEEG2.h"
#include "../../../dataHandler/exceptions/WDHException.h"
#include "../../../dataHandler/io/WLoaderBiosig.h"
#include "../../../dataHandler/io/WLoaderEEGASCII.h"
#include "../../../dataHandler/io/WLoaderLibeep.h"
#include "../../../dataHandler/io/WLoaderNIfTI.h"
#include "../../../dataHandler/io/WPagerEEGLibeep.h"
#include "../../../dataHandler/io/WReaderELC.h"
#include "../../../dataHandler/io/WReaderFiberVTK.h"
#include "WMData.h"
#include "data.xpm"
......
......@@ -30,13 +30,13 @@
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include "../../kernel/WKernel.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleConnector.h"
#include "../../kernel/WModuleOutputData.h"
#include "../../WKernel.h"
#include "../../WModule.h"
#include "../../WModuleConnector.h"
#include "../../WModuleOutputData.h"
#include "../../dataHandler/WDataSet.h"
#include "../../dataHandler/WDataSetSingle.h"
#include "../../../dataHandler/WDataSet.h"
#include "../../../dataHandler/WDataSetSingle.h"
/**
* Module for encapsulating WDataSets. It can encapsulate almost everything, but is intended to be used with WDataSets and its
......
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