client/init.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 "init.h"
00019 
00020 #include "client.h"
00021 #include "config.h"
00022 #include "configParams.h"
00023 #include "global.h"
00024 #include "node.h"
00025 #include "nodeFactory.h"
00026 #include "pluginRegistry.h"
00027 #include "server.h"
00028 #include "version.h"
00029 
00030 #include <eq/net/init.h>
00031 
00032 #ifdef EQ_USE_PARACOMP
00033 #  include <pcapi.h>
00034 #endif
00035 
00036 using namespace std;
00037 
00038 namespace eq
00039 {
00040 
00041 EQ_EXPORT bool init( const int argc, char** argv, NodeFactory* nodeFactory )
00042 {
00043     EQINFO << "Equalizer v" << Version::getString() << " initializing" << endl;
00044 
00045 #ifdef AGL
00046     ProcessSerialNumber selfProcess = { 0, kCurrentProcess };
00047     SetFrontProcess( &selfProcess );
00048     GetCurrentEventQueue();
00049 #endif
00050 
00051 #ifdef EQ_USE_PARACOMP
00052     EQINFO << "Initializing Paracomp library" << endl;
00053     PCerr err = pcSystemInitialize( 0 );
00054     if( err != PC_NO_ERROR )
00055     {
00056         EQERROR << "Paracomp initialization failed: " << err << endl;
00057         return false;
00058     }
00059 #endif
00060 
00061     // We do not use getopt_long because of:
00062     // - reordering of arguments
00063     // - different behaviour of GNU and BSD implementations
00064     // - incomplete man pages
00065 
00066     for( int i=1; i<argc; ++i )
00067     {
00068         if( strcmp( "--eq-server", argv[i] ) == 0 )
00069         {
00070             ++i;
00071             if( i<argc )
00072                 Global::setServer( argv[i] );
00073         }
00074         else if( strcmp( "--eq-config", argv[i] ) == 0 )
00075         {
00076             ++i;
00077             if( i<argc )
00078                 Global::setConfigFile( argv[i] );
00079         }
00080     }
00081     
00082     EQASSERT( nodeFactory );
00083     Global::_nodeFactory = nodeFactory;
00084 
00085     // init all available plugins
00086     PluginRegistry& pluginRegistry = Global::getPluginRegistry();
00087     pluginRegistry.init(); 
00088 
00089     return net::init( argc, argv );
00090 }
00091 
00092 EQ_EXPORT bool exit()
00093 {
00094 #ifdef EQ_USE_PARACOMP
00095     pcSystemFinalize();
00096 #endif
00097 
00098     // de-initialize registered plugins
00099     PluginRegistry& pluginRegistry = Global::getPluginRegistry();
00100     pluginRegistry.exit(); 
00101 
00102     Global::_nodeFactory = 0;
00103     return net::exit();
00104 }
00105 
00106 EQ_EXPORT Config* getConfig( const int argc, char** argv )
00107 {
00108     // 1. initialization of a local client node
00109     ClientPtr client = new Client;
00110     if( client->initLocal( argc, argv ))
00111     {
00112         // 2. connect to server
00113         ServerPtr server = new Server;
00114         if( client->connectServer( server ))
00115         {
00116             // 3. choose configuration
00117             ConfigParams configParams;
00118             Config* config = server->chooseConfig( configParams );
00119             if( config )
00120                 return config;
00121 
00122             EQERROR << "No matching config on server" << endl;
00123 
00124             // -2. disconnect server
00125             client->disconnectServer( server );
00126         }
00127         else
00128             EQERROR << "Can't open server" << endl;
00129         
00130         // -1. exit local client node
00131         client->exitLocal();
00132     }
00133     else
00134         EQERROR << "Can't init local client node" << endl;
00135 
00136     return 0;
00137 }
00138 
00139 EQ_EXPORT void releaseConfig( Config* config )
00140 {
00141     if( !config )
00142         return;
00143 
00144     ServerPtr server = config->getServer();
00145     EQASSERT( server.isValid( ));
00146     server->releaseConfig( config );
00147 
00148     ClientPtr client = server->getClient();
00149     EQASSERT( client.isValid( ));
00150     client->disconnectServer( server );
00151 
00152     client->exitLocal();
00153 
00154     EQASSERTINFO( client->getRefCount() == 1, client->getRefCount( ));
00155     EQASSERTINFO( server->getRefCount() == 1, server->getRefCount( ));
00156 }
00157 
00158 }
Generated on Mon Aug 10 18:58:39 2009 for Equalizer 0.9 by  doxygen 1.5.8