server/global.cpp

00001 
00002 /* Copyright (c) 2006-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 "global.h"
00019 
00020 #include "colorMask.h"
00021 
00022 namespace eq
00023 {
00024 namespace server
00025 {
00026 
00027 static Global *_instance = 0;
00028 
00029 Global* Global::instance()
00030 {
00031     if( !_instance ) 
00032         _instance = new Global();
00033 
00034     return _instance;
00035 }
00036 
00037 void Global::clear()
00038 {
00039     delete _instance;
00040     _instance = 0;
00041 }
00042 
00043 Global::Global()
00044 {
00045     _setupDefaults();
00046     _readEnvironment();
00047 }
00048 
00049 void Global::_setupDefaults()
00050 {
00051     // connection
00052     for( uint32_t i=0; i<ConnectionDescription::IATTR_ALL; ++i )
00053         _connectionIAttributes[i] = eq::UNDEFINED;
00054     for( uint32_t i=0; i<ConnectionDescription::CATTR_ALL; ++i )
00055         _connectionCAttributes[i] = '\0';
00056 
00057     _connectionIAttributes[ConnectionDescription::IATTR_TYPE] = 
00058         net::CONNECTIONTYPE_TCPIP;
00059     _connectionIAttributes[ConnectionDescription::IATTR_TCPIP_PORT]     = 0;
00060     _connectionIAttributes[ConnectionDescription::IATTR_BANDWIDTH]      = 0;
00061     _connectionIAttributes[ConnectionDescription::IATTR_LAUNCH_TIMEOUT] = 
00062         60000; // ms
00063     
00064     _connectionSAttributes[ConnectionDescription::SATTR_HOSTNAME] = "localhost";
00065 #ifdef WIN32
00066     _connectionSAttributes[ConnectionDescription::SATTR_LAUNCH_COMMAND] = 
00067         "ssh -n %h %c";
00068     _connectionCAttributes[ConnectionDescription::CATTR_LAUNCH_COMMAND_QUOTE] =
00069         '\"';
00070 #else
00071     _connectionSAttributes[ConnectionDescription::SATTR_LAUNCH_COMMAND] = 
00072         "ssh -n %h %c >& %h.%n.log";
00073     _connectionCAttributes[ConnectionDescription::CATTR_LAUNCH_COMMAND_QUOTE] =
00074         '\'';
00075 #endif
00076 
00077     // config
00078     for( uint32_t i=0; i<Config::FATTR_ALL; ++i )
00079         _configFAttributes[i] = 0.f;
00080 
00081     _configFAttributes[Config::FATTR_EYE_BASE]         = 0.05f;
00082 
00083     // node
00084     for( uint32_t i=0; i < eq::Node::IATTR_ALL; ++i )
00085         _nodeIAttributes[i] = eq::UNDEFINED;
00086 
00087     // pipe
00088     for( uint32_t i=0; i<Pipe::IATTR_ALL; ++i )
00089         _pipeIAttributes[i] = eq::UNDEFINED;
00090 
00091     _pipeIAttributes[Pipe::IATTR_HINT_THREAD] = eq::ON;
00092 
00093     // window
00094     for( uint32_t i=0; i<eq::Window::IATTR_ALL; ++i )
00095         _windowIAttributes[i] = eq::UNDEFINED;
00096 
00097     _windowIAttributes[eq::Window::IATTR_HINT_STEREO]       = eq::AUTO;
00098     _windowIAttributes[eq::Window::IATTR_HINT_DOUBLEBUFFER] = eq::AUTO;
00099     _windowIAttributes[eq::Window::IATTR_HINT_FULLSCREEN]   = eq::OFF;
00100     _windowIAttributes[eq::Window::IATTR_HINT_DECORATION]   = eq::ON;
00101     _windowIAttributes[eq::Window::IATTR_HINT_DRAWABLE]     = eq::WINDOW;
00102     _windowIAttributes[eq::Window::IATTR_HINT_SCREENSAVER]  = eq::AUTO;
00103     _windowIAttributes[eq::Window::IATTR_PLANES_COLOR]      = eq::AUTO;
00104     _windowIAttributes[eq::Window::IATTR_PLANES_DEPTH]      = eq::AUTO;
00105     _windowIAttributes[eq::Window::IATTR_PLANES_STENCIL]    = eq::AUTO;
00106 #ifdef NDEBUG
00107     _windowIAttributes[eq::Window::IATTR_HINT_STATISTICS]   = eq::FASTEST;
00108 #else
00109     _windowIAttributes[eq::Window::IATTR_HINT_STATISTICS]   = eq::NICEST;
00110 #endif
00111     
00112     // channel
00113     for( uint32_t i=0; i<eq::Channel::IATTR_ALL; ++i )
00114         _channelIAttributes[i] = eq::UNDEFINED;
00115 
00116 #ifdef NDEBUG
00117     _channelIAttributes[eq::Channel::IATTR_HINT_STATISTICS] = eq::FASTEST;
00118 #else
00119     _channelIAttributes[eq::Channel::IATTR_HINT_STATISTICS] = eq::NICEST;
00120 #endif
00121     _channelIAttributes[eq::Channel::IATTR_HINT_SENDTOKEN] = eq::OFF;
00122 
00123     // compound
00124     for( uint32_t i=0; i<Compound::IATTR_ALL; ++i )
00125         _compoundIAttributes[i] = eq::UNDEFINED;
00126 }
00127 
00128 void Global::_readEnvironment()
00129 {
00130     for( uint32_t i=0; i<ConnectionDescription::SATTR_ALL; ++i )
00131     {
00132         const std::string& name = ConnectionDescription::getSAttributeString(
00133             (ConnectionDescription::SAttribute)i);
00134         const char*   envValue = getenv( name.c_str( ));
00135         
00136         if( envValue )
00137             _connectionSAttributes[i] = envValue;
00138     }
00139     for( uint32_t i=0; i<ConnectionDescription::CATTR_ALL; ++i )
00140     {
00141         const std::string& name = ConnectionDescription::getCAttributeString(
00142             (ConnectionDescription::CAttribute)i);
00143         const char*   envValue = getenv( name.c_str( ));
00144         
00145         if( envValue )
00146             _connectionCAttributes[i] = envValue[0];
00147     }
00148     for( uint32_t i=0; i<ConnectionDescription::IATTR_ALL; ++i )
00149     {
00150         const std::string& name = ConnectionDescription::getIAttributeString(
00151             (ConnectionDescription::IAttribute)i);
00152         const char*   envValue = getenv( name.c_str( ));
00153         
00154         if( envValue )
00155             _connectionIAttributes[i] = atol( envValue );
00156     }
00157     for( uint32_t i=0; i<Config::FATTR_ALL; ++i )
00158     {
00159         const std::string& name     = Config::getFAttributeString(
00160             (Config::FAttribute)i);
00161         const char*   envValue = getenv( name.c_str( ));
00162         
00163         if( envValue )
00164             _configFAttributes[i] = atof( envValue );
00165     }
00166 
00167     for( uint32_t i=0; i<eq::Node::IATTR_ALL; ++i )
00168     {
00169         const std::string& name     = eq::Node::getIAttributeString(
00170             (eq::Node::IAttribute)i);
00171         const char*   envValue = getenv( name.c_str( ));
00172         
00173         if( envValue )
00174             _nodeIAttributes[i] = atol( envValue );
00175     }
00176     for( uint32_t i=0; i<Pipe::IATTR_ALL; ++i )
00177     {
00178         const std::string& name     = Pipe::getIAttributeString(
00179             (Pipe::IAttribute)i);
00180         const char*   envValue = getenv( name.c_str( ));
00181         
00182         if( envValue )
00183             _pipeIAttributes[i] = atol( envValue );
00184     }
00185     for( uint32_t i=0; i<eq::Window::IATTR_ALL; ++i )
00186     {
00187         const std::string& name     = eq::Window::getIAttributeString(
00188             (eq::Window::IAttribute)i);
00189         const char*   envValue = getenv( name.c_str( ));
00190         
00191         if( envValue )
00192             _windowIAttributes[i] = atol( envValue );
00193     }
00194     for( uint32_t i=0; i<eq::Channel::IATTR_ALL; ++i )
00195     {
00196         const std::string& name     = eq::Channel::getIAttributeString(
00197             (eq::Channel::IAttribute)i);
00198         const char*   envValue = getenv( name.c_str( ));
00199         
00200         if( envValue )
00201             _channelIAttributes[i] = atol( envValue );
00202     }
00203     for( uint32_t i=0; i<Compound::IATTR_ALL; ++i )
00204     {
00205         const std::string& name     = Compound::getIAttributeString(
00206             (Compound::IAttribute)i);
00207         const char*   envValue = getenv( name.c_str( ));
00208         
00209         if( envValue )
00210             _compoundIAttributes[i] = atol( envValue );
00211     }
00212 }
00213 
00214 #define GLOBAL_ATTR_LENGTH 50
00215 
00216 std::ostream& operator << ( std::ostream& os, const Global* global )
00217 {
00218     Global reference;
00219     reference._setupDefaults(); // ignore environment variables
00220 
00221     os << base::disableFlush << base::disableHeader
00222        << "#Equalizer " << global->getConfigFAttribute( Config::FATTR_VERSION )
00223        << " ascii" << std::endl << std::endl
00224        << "global" << std::endl
00225        << '{' << base::indent << std::endl;
00226 
00227     for( uint32_t i=0; i<ConnectionDescription::IATTR_ALL; ++i )
00228     {
00229         const int value = global->_connectionIAttributes[i];
00230         if( value == reference._connectionIAttributes[i] )
00231             continue;
00232 
00233         const std::string& name = ConnectionDescription::getIAttributeString( 
00234             static_cast<ConnectionDescription::IAttribute>( i ));
00235         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' );
00236                 
00237         switch( i )
00238         { 
00239             case ConnectionDescription::IATTR_TYPE:
00240                 os << ( value == net::CONNECTIONTYPE_TCPIP ? "TCPIP" : 
00241                         value == net::CONNECTIONTYPE_SDP   ? "SDP" : 
00242                         value == net::CONNECTIONTYPE_NAMEDPIPE   ? "PIPE" :
00243                         "PIPE" );
00244                 break;
00245             case ConnectionDescription::IATTR_LAUNCH_TIMEOUT:
00246                 os << value;// << " ms";
00247                 break;
00248             default:
00249                 os << value;
00250         }
00251         os << std::endl;
00252     }
00253 
00254     for( uint32_t i=0; i<ConnectionDescription::SATTR_ALL; ++i )
00255     {
00256         const std::string& value = global->_connectionSAttributes[i];
00257         if( value == reference._connectionSAttributes[i] )
00258             continue;
00259 
00260         const std::string& name = ConnectionDescription::getSAttributeString( 
00261             static_cast<ConnectionDescription::SAttribute>( i ));
00262         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
00263            << "\"" << value << "\"" << std::endl;
00264     }
00265 
00266     for( uint32_t i=0; i<ConnectionDescription::CATTR_ALL; ++i )
00267     {
00268         const char value = global->_connectionCAttributes[i];
00269         if( value == reference._connectionCAttributes[i] )
00270             continue;
00271 
00272         const std::string& name = ConnectionDescription::getCAttributeString( 
00273             static_cast<ConnectionDescription::CAttribute>( i ));
00274         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
00275            << "'" << value << "'" << std::endl;
00276     }
00277 
00278     for( uint32_t i=0; i<Config::FATTR_ALL; ++i )
00279     {
00280         if( i == Config::FATTR_VERSION )
00281             continue;
00282 
00283         const float value = global->_configFAttributes[i];
00284         if( value == reference._configFAttributes[i] )
00285             continue;
00286 
00287         const std::string& name = Config::getFAttributeString( 
00288             static_cast<Config::FAttribute>( i ));
00289         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
00290            << value << std::endl;
00291     }
00292 
00293     for( uint32_t i=0; i < eq::Node::IATTR_ALL; ++i )
00294     {
00295         const int32_t value = global->_nodeIAttributes[i];
00296         if( value == reference._nodeIAttributes[i] )
00297             continue;
00298 
00299         const std::string& name = eq::Node::getIAttributeString( 
00300             static_cast<eq::Node::IAttribute>( i ));
00301         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
00302            << static_cast<eq::IAttrValue>( value ) << std::endl;
00303     }
00304 
00305     for( uint32_t i=0; i<Pipe::IATTR_ALL; ++i )
00306     {
00307         const int value = global->_pipeIAttributes[i];
00308         if( value == reference._pipeIAttributes[i] )
00309             continue;
00310 
00311         const std::string& name = Pipe::getIAttributeString( 
00312             static_cast<Pipe::IAttribute>( i ));
00313         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
00314            << static_cast<eq::IAttrValue>( value ) << std::endl;
00315     }
00316 
00317     for( uint32_t i=0; i<eq::Window::IATTR_ALL; ++i )
00318     {
00319         const int value = global->_windowIAttributes[i];
00320         if( value == reference._windowIAttributes[i] )
00321             continue;
00322 
00323         const std::string& name = eq::Window::getIAttributeString( 
00324             static_cast<eq::Window::IAttribute>( i ));
00325         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
00326            << static_cast<eq::IAttrValue>( value ) << std::endl;
00327     }
00328 
00329     for( uint32_t i=0; i<eq::Channel::IATTR_ALL; ++i )
00330     {
00331         const int value = global->_channelIAttributes[i];
00332         if( value == reference._channelIAttributes[i] )
00333             continue;
00334 
00335         const std::string& name = eq::Channel::getIAttributeString(
00336             static_cast<eq::Channel::IAttribute>( i ));
00337         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
00338            << static_cast<eq::IAttrValue>( value ) << std::endl;
00339     }
00340 
00341     for( uint32_t i=0; i<Compound::IATTR_ALL; ++i )
00342     {
00343         const int value = global->_compoundIAttributes[i];
00344         if( value == reference._compoundIAttributes[i] )
00345             continue;
00346 
00347         const std::string& name = Compound::getIAttributeString(
00348             static_cast<Compound::IAttribute>( i ));
00349         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' );
00350 
00351         switch( i )
00352         {
00353             case Compound::IATTR_STEREO_MODE:
00354                 os << static_cast<eq::IAttrValue>( value ) << std::endl;
00355                 break;
00356 
00357             case Compound::IATTR_STEREO_ANAGLYPH_LEFT_MASK:
00358             case Compound::IATTR_STEREO_ANAGLYPH_RIGHT_MASK:
00359                 os << ColorMask( value ) << std::endl;
00360                 break;
00361 
00362             default:
00363                 EQASSERTINFO( 0, "unimplemented" );
00364         }
00365     }
00366 
00367     os << base::exdent << '}' << std::endl
00368        << base::enableHeader << base::enableFlush;
00369     return os;
00370 }
00371 
00372 }
00373 }
Generated on Mon Aug 10 18:58:39 2009 for Equalizer 0.9 by  doxygen 1.5.8