OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WBatchLoader.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <string>
26 #include <vector>
27 
28 #include "WModule.h"
29 #include "WDataModule.h"
30 #include "WModuleContainer.h"
31 #include "WModuleFactory.h"
32 
33 #include "WBatchLoader.h"
34 
35 WBatchLoader::WBatchLoader( std::vector< std::string > fileNames, boost::shared_ptr< WModuleContainer > targetContainer ):
38  m_fileNamesToLoad( fileNames ),
39  m_targetContainer( targetContainer )
40 {
41  // initialize members
42 }
43 
45 {
46  // cleanup
47 }
48 
50 {
51  // the module needs to be added here, as it else could be freed before the thread finishes ( remember: it is a shared_ptr).
52  m_targetContainer->addPendingThread( shared_from_this() );
53 
54  // actually run
56 }
57 
59 {
60  // add a new data module for each file to load
61  for( std::vector< std::string >::iterator iter = m_fileNamesToLoad.begin(); iter != m_fileNamesToLoad.end(); ++iter )
62  {
63  boost::shared_ptr< WModule > mod = WModuleFactory::getModuleFactory()->create(
64  WModuleFactory::getModuleFactory()->getPrototypeByName( "Data Module" )
65  );
66 
67  // set the filename
68  boost::shared_static_cast< WDataModule >( mod )->setFilename( *iter );
69 
70  m_targetContainer->add( mod );
71  // serialize loading of a couple of data sets
72  // ignore the case where isCrashed is true
73  mod->isReadyOrCrashed().wait();
74  }
75 
76  m_targetContainer->finishedPendingThread( shared_from_this() );
77 }
78