00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifdef __linux__
00026 #include <unistd.h>
00027 #endif
00028
00029 #if defined(__APPLE__)
00030 #include <mach-o/dyld.h>
00031 #endif
00032
00033 #include <iostream>
00034 #include <list>
00035 #include <string>
00036 #include <vector>
00037
00038
00039 #ifndef BOOST_FILESYSTEM_VERSION
00040 #define BOOST_FILESYSTEM_VERSION 2
00041 #endif
00042 #include <boost/filesystem.hpp>
00043 #include <boost/thread/xtime.hpp>
00044
00045 #include "../common/WStringUtils.h"
00046 #include "../common/WThreadedRunner.h"
00047 #include "../dataHandler/WDataHandler.h"
00048 #include "../gui/WGUI.h"
00049 #include "WKernel.h"
00050 #include "WModule.h"
00051 #include "WModuleContainer.h"
00052 #include "WModuleFactory.h"
00053 #include "WROIManager.h"
00054 #include "WSelectionManager.h"
00055
00056 #include "WVersion.h"
00057
00058
00059
00060
00061 WKernel* WKernel::m_kernel = NULL;
00062
00063 WKernel::WKernel( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui ):
00064 WThreadedRunner()
00065 {
00066 WLogger::getLogger()->addLogMessage( "Initializing Kernel", "Kernel", LL_INFO );
00067 wlog::debug( "Kernel" ) << "Version: " << W_VERSION;
00068
00069
00070 m_kernel = this;
00071
00072
00073 m_gui = gui;
00074 m_graphicsEngine = ge;
00075
00076
00077 init();
00078 }
00079
00080 WKernel::~WKernel()
00081 {
00082
00083 WLogger::getLogger()->addLogMessage( "Shutting down Kernel", "Kernel", LL_INFO );
00084 }
00085
00086 WKernel* WKernel::instance( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui )
00087 {
00088 if( m_kernel == NULL )
00089 {
00090 new WKernel( ge, gui );
00091 }
00092
00093 return m_kernel;
00094 }
00095
00096 void WKernel::init()
00097 {
00098
00099 m_roiManager = boost::shared_ptr< WROIManager >( new WROIManager() );
00100
00101 m_selectionManager = boost::shared_ptr< WSelectionManager >( new WSelectionManager() );
00102
00103
00104 m_moduleFactory = WModuleFactory::getModuleFactory();
00105
00106
00107 WDataHandler::getDataHandler();
00108
00109
00110 m_moduleContainer = boost::shared_ptr< WModuleContainer >( new WModuleContainer( "KernelRootContainer",
00111 "Root module container in Kernel." ) );
00112
00113 m_moduleContainer->setCrashIfModuleCrashes( false );
00114
00115
00116 m_moduleFactory->load();
00117 }
00118
00119 WKernel* WKernel::getRunningKernel()
00120 {
00121 return m_kernel;
00122 }
00123
00124 boost::shared_ptr< WGraphicsEngine > WKernel::getGraphicsEngine() const
00125 {
00126 return m_graphicsEngine;
00127 }
00128
00129 boost::shared_ptr< WModuleContainer > WKernel::getRootContainer() const
00130 {
00131 return m_moduleContainer;
00132 }
00133
00134 boost::shared_ptr< WGUI > WKernel::getGui() const
00135 {
00136 return m_gui;
00137 }
00138
00139 void WKernel::finalize()
00140 {
00141 WLogger::getLogger()->addLogMessage( "Stopping Kernel", "Kernel", LL_INFO );
00142
00143
00144 getRootContainer()->stop();
00145
00146 WLogger::getLogger()->addLogMessage( "Stopping Data Handler", "Kernel", LL_INFO );
00147 WDataHandler::getDataHandler()->clear();
00148 }
00149
00150 void WKernel::threadMain()
00151 {
00152 WLogger::getLogger()->addLogMessage( "Starting Kernel", "Kernel", LL_INFO );
00153
00154
00155 m_gui->isInitialized().wait();
00156
00157
00158 m_graphicsEngine->run();
00159
00160
00161 waitForStop();
00162
00163 WLogger::getLogger()->addLogMessage( "Shutting down Kernel", "Kernel", LL_INFO );
00164 }
00165
00166 const WBoolFlag& WKernel::isFinishRequested() const
00167 {
00168 return m_shutdownFlag;
00169 }
00170
00171 void WKernel::loadDataSets( std::vector< std::string > fileNames )
00172 {
00173 getRootContainer()->loadDataSets( fileNames );
00174 }
00175
00176 void WKernel::loadDataSetsSynchronously( std::vector< std::string > fileNames )
00177 {
00178 getRootContainer()->loadDataSetsSynchronously( fileNames );
00179 }
00180
00181 boost::shared_ptr< WModule > WKernel::applyModule( boost::shared_ptr< WModule > applyOn, boost::shared_ptr< WModule > prototype )
00182 {
00183 return getRootContainer()->applyModule( applyOn, prototype );
00184 }
00185
00186 boost::shared_ptr< WROIManager > WKernel::getRoiManager()
00187 {
00188 return m_roiManager;
00189 }
00190
00191 boost::shared_ptr< WSelectionManager>WKernel::getSelectionManager()
00192 {
00193 return m_selectionManager;
00194 }