eVolve.cpp

00001 
00002 /* Copyright (c) 2005-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "eVolve.h"
00019 
00020 #include "config.h"
00021 #include "localInitData.h"
00022 
00023 #include <stdlib.h>
00024 
00025 using namespace std;
00026 
00027 namespace eVolve
00028 {
00029 
00030 EVolve::EVolve( const LocalInitData& initData )
00031         : _initData( initData )
00032 {}
00033 
00034 int EVolve::run()
00035 {
00036     // 1. connect to server
00037     eq::ServerPtr server = new eq::Server;
00038     if( !connectServer( server ))
00039     {
00040         EQERROR << "Can't open server" << endl;
00041         return EXIT_FAILURE;
00042     }
00043 
00044     // 2. choose config
00045     eq::ConfigParams configParams;
00046     Config* config = static_cast<Config*>(server->chooseConfig( configParams ));
00047 
00048     if( !config )
00049     {
00050         EQERROR << "No matching config on server" << endl;
00051         disconnectServer( server );
00052         return EXIT_FAILURE;
00053     }
00054 
00055     // 3. init config
00056     eq::base::Clock clock;
00057 
00058     config->setInitData( _initData );
00059     if( !config->init( ))
00060     {
00061         EQERROR << "Config initialization failed: " 
00062                 << config->getErrorMessage() << endl;
00063         server->releaseConfig( config );
00064         disconnectServer( server );
00065         return EXIT_FAILURE;
00066     }
00067 
00068     EQLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms"
00069                        << endl;
00070 
00071     // 4. run main loop
00072     uint32_t maxFrames = _initData.getMaxFrames();
00073     
00074     clock.reset();
00075     while( config->isRunning( ) && maxFrames-- )
00076     {
00077         config->startFrame();
00078         config->finishFrame();
00079     }
00080     const uint32_t frame = config->finishAllFrames();
00081     const float    time  = clock.getTimef();
00082     EQLOG( LOG_STATS ) << "Rendering took " << time << " ms (" << frame
00083                        << " frames @ " << ( frame / time * 1000.f) << " FPS)"
00084                        << endl;
00085 
00086     // 5. exit config
00087     clock.reset();
00088     config->exit();
00089     EQLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<endl;
00090 
00091     // 6. cleanup and exit
00092     server->releaseConfig( config );
00093     if( !disconnectServer( server ))
00094         EQERROR << "Client::disconnectServer failed" << endl;
00095     server = 0;
00096 
00097     return EXIT_SUCCESS;
00098 }
00099 
00100 bool EVolve::clientLoop()
00101 {
00102     if( !_initData.isResident( )) // execute only one config run
00103         return eq::Client::clientLoop();
00104 
00105     // else execute client loops 'forever'
00106     while( true ) // TODO: implement SIGHUP handler to exit?
00107     {
00108         if( !eq::Client::clientLoop( ))
00109             return false;
00110         EQINFO << "One configuration run successfully executed" << endl;
00111     }
00112     return true;
00113 }
00114 }
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8