Equalizer 1.0
|
00001 /* 00002 * Copyright (c) 2009, Philippe Robert <philippe.robert@gmail.com> 00003 * 2010, Stefan Eilemann <eile@eyescale.ch> 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * - Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * - Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * - Neither the name of Eyescale Software GmbH nor the names of its 00014 * contributors may be used to endorse or promote products derived from this 00015 * software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 #include "client.h" 00031 00032 #include "config.h" 00033 #include "initData.h" 00034 00035 #include <stdlib.h> 00036 00037 namespace eqNbody 00038 { 00039 00040 Client::Client( const InitData& initData ) 00041 : _initData( initData ) 00042 , _config( 0 ) 00043 {} 00044 00045 int Client::init() 00046 { 00047 EQASSERT( !_config ); 00048 00049 // 1. connect to server 00050 _server = new eq::Server; 00051 if( !connectServer( _server )) 00052 { 00053 EQERROR << "Can't open server" << std::endl; 00054 return EXIT_FAILURE; 00055 } 00056 00057 // 2. choose config 00058 eq::ConfigParams configParams; 00059 _config = static_cast<Config*>(_server->chooseConfig( configParams )); 00060 00061 if( !_config ) 00062 { 00063 EQERROR << "No matching config on server" << std::endl; 00064 disconnectServer( _server ); 00065 return EXIT_FAILURE; 00066 } 00067 00068 // 3. init config 00069 _config->setInitData( _initData ); 00070 if( !_config->init() ) 00071 { 00072 _server->releaseConfig( _config ); 00073 disconnectServer( _server ); 00074 return EXIT_FAILURE; 00075 } 00076 else if( _config->getError( )) 00077 EQWARN << "Error during initialization: " << _config->getError() 00078 << std::endl; 00079 00080 return EXIT_SUCCESS; 00081 } 00082 00083 int Client::exit() 00084 { 00085 EQASSERT( _config ); 00086 00087 // Exit config 00088 _config->exit(); 00089 00090 // Cleanup 00091 _server->releaseConfig( _config ); 00092 if( !disconnectServer( _server )) { 00093 EQERROR << "Client::disconnectServer failed" << std::endl; 00094 return EXIT_FAILURE; 00095 } 00096 00097 _server = 0; 00098 return EXIT_SUCCESS; 00099 } 00100 00101 void Client::run() 00102 { 00103 // Run main loop 00104 while( _config->isRunning( ) ) 00105 { 00106 _config->startFrame(); 00107 _config->finishFrame(); 00108 00109 if( !_config->needsRedraw()) { 00110 _config->finishAllFrames(); 00111 } 00112 00113 _config->handleEvents(); // process all pending events 00114 } 00115 } 00116 }