OpenWalnut  1.4.0
WBatchLoader.cpp
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #include <string>
00026 #include <vector>
00027 
00028 #include "WModule.h"
00029 #include "WModuleContainer.h"
00030 #include "WModuleFactory.h"
00031 
00032 #include "WBatchLoader.h"
00033 
00034 WBatchLoader::WBatchLoader( std::vector< std::string > filenames, boost::shared_ptr< WModuleContainer > targetContainer ):
00035     WThreadedRunner(),
00036     boost::enable_shared_from_this< WBatchLoader >(),
00037     m_filenamesToLoad( filenames ),
00038     m_targetContainer( targetContainer ),
00039     m_suppressColormaps( false )
00040 {
00041     // initialize members
00042 }
00043 
00044 WBatchLoader::~WBatchLoader()
00045 {
00046     // cleanup
00047 }
00048 
00049 void WBatchLoader::run()
00050 {
00051     // the module needs to be added here, as it else could be freed before the thread finishes ( remember: it is a shared_ptr).
00052     m_targetContainer->addPendingThread( shared_from_this() );
00053 
00054     // actually run
00055     WThreadedRunner::run();
00056 }
00057 
00058 void WBatchLoader::threadMain()
00059 {
00060     // add a new data module for each file to load
00061     for( std::vector< std::string >::iterator iter = m_filenamesToLoad.begin(); iter != m_filenamesToLoad.end(); ++iter )
00062     {
00063         boost::shared_ptr< WModule > mod = WModuleFactory::getModuleFactory()->create(
00064                 WModuleFactory::getModuleFactory()->getPrototypeByName( "Data Module" )
00065         );
00066         WDataModule::SPtr dmod = boost::static_pointer_cast< WDataModule >( mod );
00067         dmod->setSuppressColormaps( m_suppressColormaps );
00068 
00069         // set the filename
00070         dmod->setFilename( *iter );
00071 
00072         m_targetContainer->add( mod );
00073         // serialize loading of a couple of data sets
00074         // ignore the case where isCrashed is true
00075         mod->isReadyOrCrashed().wait();
00076 
00077         // add module to the list
00078         m_dataModules.push_back( dmod );
00079     }
00080 
00081     m_targetContainer->finishedPendingThread( shared_from_this() );
00082 }
00083 
00084 WBatchLoader::DataModuleList::ReadTicket WBatchLoader::getDataModuleList() const
00085 {
00086     return m_dataModules.getReadTicket();
00087 }
00088 
00089 void WBatchLoader::setSuppressColormaps( bool suppress )
00090 {
00091     m_suppressColormaps = suppress;
00092 }
00093 
00094 bool WBatchLoader::getSuppressColormaps() const
00095 {
00096     return m_suppressColormaps;
00097 }
00098