LCOV - code coverage report
Current view: top level - eq/server - global.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 211 228 92.5 %
Date: 2014-06-18 Functions: 8 8 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2006-2013, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *               2011-2014, Daniel Nachbaur <danielnachbaur@gmail.com>
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or modify it under
       6             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       7             :  * by the Free Software Foundation.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      11             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      12             :  * details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public License
      15             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #include "global.h"
      20             : 
      21             : #include "colorMask.h"
      22             : 
      23             : namespace eq
      24             : {
      25             : namespace server
      26             : {
      27             : 
      28             : static Global *_instance = 0;
      29             : 
      30       30368 : Global* Global::instance()
      31             : {
      32       30368 :     if( !_instance )
      33         221 :         _instance = new Global();
      34             : 
      35       30368 :     return _instance;
      36             : }
      37             : 
      38         220 : void Global::clear()
      39             : {
      40         220 :     delete _instance;
      41         220 :     _instance = 0;
      42         220 : }
      43             : 
      44         355 : Global::Global()
      45             : {
      46         355 :     _setupDefaults();
      47         355 :     _readEnvironment();
      48         355 : }
      49             : 
      50         489 : void Global::_setupDefaults()
      51             : {
      52             :     // connection
      53        2934 :     for( uint32_t i=0; i<ConnectionDescription::IATTR_ALL; ++i )
      54        2445 :         _connectionIAttributes[i] = fabric::UNDEFINED;
      55             : 
      56             :     _connectionIAttributes[ ConnectionDescription::IATTR_TYPE ] =
      57         489 :         co::CONNECTIONTYPE_TCPIP;
      58         489 :     _connectionIAttributes[ ConnectionDescription::IATTR_PORT ] = 0;
      59         489 :     _connectionIAttributes[ ConnectionDescription::IATTR_BANDWIDTH ] = 0;
      60         489 :     _connectionSAttributes[ ConnectionDescription::SATTR_FILENAME ] = "default";
      61             : 
      62             :     // config
      63        3912 :     for( uint32_t i=0; i<Config::FATTR_ALL; ++i )
      64        3423 :         _configFAttributes[i] = 0.f;
      65        3423 :     for( uint32_t i=0; i<Config::IATTR_ALL; ++i )
      66        2934 :         _configIAttributes[i] = fabric::UNDEFINED;
      67             : 
      68         489 :     _configFAttributes[Config::FATTR_EYE_BASE]         = 0.05f;
      69         489 :     _configIAttributes[Config::IATTR_ROBUSTNESS]       = fabric::AUTO;
      70             : 
      71             :     // node
      72        3423 :     for( uint32_t i=0; i < Node::CATTR_ALL; ++i )
      73        2934 :         _nodeCAttributes[i] = 0;
      74        4401 :     for( uint32_t i=0; i < Node::IATTR_ALL; ++i )
      75        3912 :         _nodeIAttributes[i] = fabric::UNDEFINED;
      76             : 
      77         489 :     _nodeIAttributes[Node::IATTR_LAUNCH_TIMEOUT] = 60000; // ms
      78         489 :     _nodeIAttributes[Node::IATTR_HINT_AFFINITY] = AUTO;
      79         489 :     _nodeSAttributes[Node::SATTR_LAUNCH_COMMAND] =
      80         489 :         "ssh -n %h %c --eq-logfile %q%d/%h.%n.log%q";
      81             : #ifdef WIN32
      82             :     _nodeCAttributes[Node::CATTR_LAUNCH_COMMAND_QUOTE] = '\"';
      83             : #else
      84         489 :     _nodeCAttributes[Node::CATTR_LAUNCH_COMMAND_QUOTE] = '\'';
      85             : #endif
      86             : 
      87             :     // pipe
      88        4401 :     for( uint32_t i=0; i<Pipe::IATTR_ALL; ++i )
      89        3912 :         _pipeIAttributes[i] = fabric::UNDEFINED;
      90             : 
      91         489 :     _pipeIAttributes[Pipe::IATTR_HINT_THREAD] = fabric::ON;
      92         489 :     _pipeIAttributes[Pipe::IATTR_HINT_CUDA_GL_INTEROP] = fabric::OFF;
      93         489 :     _pipeIAttributes[Pipe::IATTR_HINT_AFFINITY] = AUTO;
      94             : 
      95             :     // window
      96        9291 :     for( uint32_t i=0; i<WindowSettings::IATTR_ALL; ++i )
      97        8802 :         _windowIAttributes[i] = fabric::UNDEFINED;
      98             : 
      99         489 :     _windowIAttributes[WindowSettings::IATTR_HINT_STEREO]       = fabric::AUTO;
     100         489 :     _windowIAttributes[WindowSettings::IATTR_HINT_DOUBLEBUFFER] = fabric::AUTO;
     101         489 :     _windowIAttributes[WindowSettings::IATTR_HINT_FULLSCREEN]   = fabric::OFF;
     102         489 :     _windowIAttributes[WindowSettings::IATTR_HINT_DECORATION]   = fabric::AUTO;
     103         489 :     _windowIAttributes[WindowSettings::IATTR_HINT_DRAWABLE]     = fabric::WINDOW;
     104         489 :     _windowIAttributes[WindowSettings::IATTR_HINT_SCREENSAVER]  = fabric::AUTO;
     105         489 :     _windowIAttributes[WindowSettings::IATTR_HINT_GRAB_POINTER] = fabric::ON;
     106         489 :     _windowIAttributes[WindowSettings::IATTR_PLANES_COLOR]      = fabric::AUTO;
     107         489 :     _windowIAttributes[WindowSettings::IATTR_PLANES_DEPTH]      = fabric::AUTO;
     108         489 :     _windowIAttributes[WindowSettings::IATTR_PLANES_STENCIL]    = fabric::AUTO;
     109             : #ifdef NDEBUG
     110             :     _windowIAttributes[WindowSettings::IATTR_HINT_STATISTICS]   = fabric::FASTEST;
     111             : #else
     112         489 :     _windowIAttributes[WindowSettings::IATTR_HINT_STATISTICS]   = fabric::NICEST;
     113             : #endif
     114             : 
     115             :     // channel
     116        3912 :     for( uint32_t i=0; i<Channel::IATTR_ALL; ++i )
     117        3423 :         _channelIAttributes[i] = fabric::UNDEFINED;
     118             : 
     119             : #ifdef NDEBUG
     120             :     _channelIAttributes[Channel::IATTR_HINT_STATISTICS] = fabric::FASTEST;
     121             : #else
     122         489 :     _channelIAttributes[Channel::IATTR_HINT_STATISTICS] = fabric::NICEST;
     123             : #endif
     124         489 :     _channelIAttributes[Channel::IATTR_HINT_SENDTOKEN] = fabric::OFF;
     125             : 
     126             :     // compound
     127        2934 :     for( uint32_t i=0; i<Compound::IATTR_ALL; ++i )
     128        2445 :         _compoundIAttributes[i] = fabric::UNDEFINED;
     129         489 : }
     130             : 
     131         355 : void Global::_readEnvironment()
     132             : {
     133        1775 :     for( uint32_t i=0; i<ConnectionDescription::SATTR_ALL; ++i )
     134             :     {
     135             :         const std::string& name = ConnectionDescription::getSAttributeString(
     136        1420 :             (ConnectionDescription::SAttribute)i);
     137        1420 :         const char*   envValue = getenv( name.c_str( ));
     138             : 
     139        1420 :         if( envValue )
     140           0 :             _connectionSAttributes[i] = envValue;
     141             :     }
     142        2130 :     for( uint32_t i=0; i<ConnectionDescription::IATTR_ALL; ++i )
     143             :     {
     144             :         const std::string& name = ConnectionDescription::getIAttributeString(
     145        1775 :             (ConnectionDescription::IAttribute)i);
     146        1775 :         const char*   envValue = getenv( name.c_str( ));
     147             : 
     148        1775 :         if( envValue )
     149           0 :             _connectionIAttributes[i] = atol( envValue );
     150             :     }
     151             : 
     152        1065 :     for( uint32_t i=0; i < Config::FATTR_LAST; ++i )
     153             :     {
     154             :         const std::string& name = Config::getFAttributeString(
     155         710 :             (Config::FAttribute)i);
     156         710 :         const char*   envValue = getenv( name.c_str( ));
     157             : 
     158         710 :         if( envValue )
     159           0 :             _configFAttributes[i] = atof( envValue );
     160             :     }
     161         710 :     for( uint32_t i=0; i < Config::IATTR_LAST; ++i )
     162             :     {
     163             :         const std::string& name = Config::getIAttributeString(
     164         355 :             (Config::IAttribute)i);
     165         355 :         const char*   envValue = getenv( name.c_str( ));
     166             : 
     167         355 :         if( envValue )
     168           4 :             _configIAttributes[i] = atol( envValue );
     169             :     }
     170             : 
     171         710 :     for( uint32_t i=0; i < Node::SATTR_LAST; ++i )
     172             :     {
     173             :         const std::string& name = Node::getSAttributeString(
     174         355 :             (Node::SAttribute)i);
     175         355 :         const char*   envValue = getenv( name.c_str( ));
     176             : 
     177         355 :         if( envValue )
     178           0 :             _nodeSAttributes[i] = envValue;
     179             :     }
     180         710 :     for( uint32_t i=0; i < Node::CATTR_LAST; ++i )
     181             :     {
     182             :         const std::string& name = Node::getCAttributeString(
     183         355 :             (Node::CAttribute)i);
     184         355 :         const char*   envValue = getenv( name.c_str( ));
     185             : 
     186         355 :         if( envValue )
     187           0 :             _nodeCAttributes[i] = envValue[0];
     188             :     }
     189        1420 :     for( uint32_t i=0; i < Node::IATTR_LAST; ++i )
     190             :     {
     191             :         const std::string& name     = Node::getIAttributeString(
     192        1065 :             (Node::IAttribute)i);
     193        1065 :         const char*   envValue = getenv( name.c_str( ));
     194             : 
     195        1065 :         if( envValue )
     196           0 :             _nodeIAttributes[i] = atol( envValue );
     197             :     }
     198        1420 :     for( uint32_t i=0; i<Pipe::IATTR_LAST; ++i )
     199             :     {
     200             :         const std::string& name     = Pipe::getIAttributeString(
     201        1065 :             (Pipe::IAttribute)i);
     202        1065 :         const char*   envValue = getenv( name.c_str( ));
     203             : 
     204        1065 :         if( envValue )
     205           0 :             _pipeIAttributes[i] = atol( envValue );
     206             :     }
     207        6745 :     for( uint32_t i=0; i < WindowSettings::IATTR_LAST; ++i )
     208             :     {
     209             :         const std::string& name     = Window::getIAttributeString(
     210        6390 :             (WindowSettings::IAttribute)i);
     211        6390 :         const char*   envValue = getenv( name.c_str( ));
     212             : 
     213        6390 :         if( envValue )
     214          16 :             _windowIAttributes[i] = atol( envValue );
     215             :     }
     216        1065 :     for( uint32_t i=0; i < Channel::IATTR_LAST; ++i )
     217             :     {
     218             :         const std::string& name = Channel::getIAttributeString(
     219         710 :             (Channel::IAttribute)i);
     220         710 :         const char*   envValue = getenv( name.c_str( ));
     221             : 
     222         710 :         if( envValue )
     223           0 :             _channelIAttributes[i] = atol( envValue );
     224             :     }
     225         710 :     for( uint32_t i=0; i < Channel::SATTR_LAST; ++i )
     226             :     {
     227             :         const std::string& name = Channel::getSAttributeString(
     228         355 :             (Channel::SAttribute)i);
     229         355 :         const char*   envValue = getenv( name.c_str( ));
     230             : 
     231         355 :         if( envValue )
     232           4 :             _channelSAttributes[i] = envValue;
     233             :     }
     234        2130 :     for( uint32_t i=0; i<Compound::IATTR_ALL; ++i )
     235             :     {
     236             :         const std::string& name     = Compound::getIAttributeString(
     237        1775 :             (Compound::IAttribute)i);
     238        1775 :         const char*   envValue = getenv( name.c_str( ));
     239             : 
     240        1775 :         if( envValue )
     241           0 :             _compoundIAttributes[i] = atol( envValue );
     242             :     }
     243         355 : }
     244             : 
     245             : #define GLOBAL_ATTR_LENGTH 50
     246             : 
     247         134 : std::ostream& operator << ( std::ostream& os, const Global* global )
     248             : {
     249         134 :     Global reference;
     250         134 :     reference._setupDefaults(); // ignore environment variables
     251             : 
     252         134 :     os << lunchbox::disableFlush << lunchbox::disableHeader
     253         268 :        << "#Equalizer " << global->getConfigFAttribute( Config::FATTR_VERSION )
     254         134 :        << " ascii" << std::endl << std::endl
     255         134 :        << "global" << std::endl
     256         134 :        << '{' << lunchbox::indent << std::endl;
     257             : 
     258         804 :     for( uint32_t i=0; i<ConnectionDescription::IATTR_ALL; ++i )
     259             :     {
     260         670 :         const int value = global->_connectionIAttributes[i];
     261         670 :         if( value == reference._connectionIAttributes[i] )
     262         670 :             continue;
     263             : 
     264             :         const std::string& name = ConnectionDescription::getIAttributeString(
     265           0 :             static_cast<ConnectionDescription::IAttribute>( i ));
     266           0 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' );
     267             : 
     268           0 :         switch( i )
     269             :         {
     270             :             case ConnectionDescription::IATTR_TYPE:
     271           0 :                 os << static_cast< co::ConnectionType >( value );
     272           0 :                 break;
     273             :             default:
     274           0 :                 os << value;
     275             :         }
     276           0 :         os << std::endl;
     277             :     }
     278             : 
     279         670 :     for( uint32_t i=0; i<ConnectionDescription::SATTR_ALL; ++i )
     280             :     {
     281         536 :         const std::string& value = global->_connectionSAttributes[i];
     282         536 :         if( value == reference._connectionSAttributes[i] )
     283         534 :             continue;
     284             : 
     285             :         const std::string& name = ConnectionDescription::getSAttributeString(
     286           2 :             static_cast<ConnectionDescription::SAttribute>( i ));
     287           4 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     288           2 :            << "\"" << value << "\"" << std::endl;
     289             :     }
     290             : 
     291        1072 :     for( uint32_t i=0; i<Config::FATTR_ALL; ++i )
     292             :     {
     293         938 :         if( i == Config::FATTR_VERSION )
     294         134 :             continue;
     295             : 
     296         804 :         const float value = global->_configFAttributes[i];
     297         804 :         if( value == reference._configFAttributes[i] )
     298         802 :             continue;
     299             : 
     300             :         const std::string& name = Config::getFAttributeString(
     301           2 :             static_cast<Config::FAttribute>( i ));
     302           4 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     303           2 :            << value << std::endl;
     304             :     }
     305             : 
     306         938 :     for( uint32_t i=0; i<Config::IATTR_ALL; ++i )
     307             :     {
     308         804 :         const int32_t value = global->_configIAttributes[i];
     309         804 :         if( value == reference._configIAttributes[i] )
     310         799 :             continue;
     311             : 
     312             :         const std::string& name = Config::getIAttributeString(
     313           5 :             static_cast<Config::IAttribute>( i ));
     314          10 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     315           5 :            << static_cast< fabric::IAttribute >( value ) << std::endl;
     316             :     }
     317             : 
     318         938 :     for( uint32_t i=0; i<Node::SATTR_ALL; ++i )
     319             :     {
     320         804 :         const std::string& value = global->_nodeSAttributes[i];
     321         804 :         if( value == reference._nodeSAttributes[i] )
     322         803 :             continue;
     323             : 
     324             :         const std::string& name = Node::getSAttributeString(
     325           1 :             static_cast<Node::SAttribute>( i ));
     326           2 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     327           1 :            << "\"" << value << "\"" << std::endl;
     328             :     }
     329             : 
     330         938 :     for( uint32_t i=0; i<Node::CATTR_ALL; ++i )
     331             :     {
     332         804 :         const char value = global->_nodeCAttributes[i];
     333         804 :         if( value == reference._nodeCAttributes[i] )
     334         803 :             continue;
     335             : 
     336             :         const std::string& name = Node::getCAttributeString(
     337           1 :             static_cast<Node::CAttribute>( i ));
     338           2 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     339           2 :            << "'" << value << "'" << std::endl;
     340             :     }
     341             : 
     342        1206 :     for( uint32_t i=0; i < Node::IATTR_ALL; ++i )
     343             :     {
     344        1072 :         const int32_t value = global->_nodeIAttributes[i];
     345        1072 :         if( value == reference._nodeIAttributes[i] )
     346        1070 :             continue;
     347             : 
     348             :         const std::string& name = Node::getIAttributeString(
     349           2 :             static_cast<Node::IAttribute>( i ));
     350           4 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     351           2 :            << static_cast< fabric::IAttribute >( value ) << std::endl;
     352             :     }
     353             : 
     354        1206 :     for( uint32_t i=0; i<Pipe::IATTR_ALL; ++i )
     355             :     {
     356        1072 :         const int value = global->_pipeIAttributes[i];
     357        1072 :         if( value == reference._pipeIAttributes[i] )
     358        1071 :             continue;
     359             : 
     360             :         const std::string& name = Pipe::getIAttributeString(
     361           1 :             static_cast<Pipe::IAttribute>( i ));
     362           2 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     363           1 :            << static_cast< fabric::IAttribute >( value ) << std::endl;
     364             :     }
     365             : 
     366        2546 :     for( uint32_t i=0; i<WindowSettings::IATTR_ALL; ++i )
     367             :     {
     368        2412 :         const int value = global->_windowIAttributes[i];
     369        2412 :         if( value == reference._windowIAttributes[i] )
     370        2321 :             continue;
     371             : 
     372             :         const std::string& name = Window::getIAttributeString(
     373          91 :             static_cast<WindowSettings::IAttribute>( i ));
     374         182 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     375          91 :            << static_cast< fabric::IAttribute >( value ) << std::endl;
     376             :     }
     377             : 
     378        1072 :     for( uint32_t i=0; i<Channel::IATTR_ALL; ++i )
     379             :     {
     380         938 :         const int value = global->_channelIAttributes[i];
     381         938 :         if( value == reference._channelIAttributes[i] )
     382         937 :             continue;
     383             : 
     384             :         const std::string& name = Channel::getIAttributeString(
     385           1 :             static_cast<Channel::IAttribute>( i ));
     386           2 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     387           1 :            << static_cast< fabric::IAttribute >( value ) << std::endl;
     388             :     }
     389             : 
     390         938 :     for( uint32_t i=0; i<Channel::SATTR_ALL; ++i )
     391             :     {
     392         804 :         const std::string& value = global->_channelSAttributes[i];
     393         804 :         if( value == reference._channelSAttributes[i] )
     394         803 :             continue;
     395             : 
     396             :         const std::string& name = Channel::getSAttributeString(
     397           1 :             static_cast<Channel::SAttribute>( i ));
     398           2 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     399           1 :            << "\"" << value << "\"" << std::endl;
     400             :     }
     401             : 
     402         804 :     for( uint32_t i=0; i<Compound::IATTR_ALL; ++i )
     403             :     {
     404         670 :         const int value = global->_compoundIAttributes[i];
     405         670 :         if( value == reference._compoundIAttributes[i] )
     406         665 :             continue;
     407             : 
     408             :         const std::string& name = Compound::getIAttributeString(
     409           5 :             static_cast<Compound::IAttribute>( i ));
     410           5 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' );
     411             : 
     412           5 :         switch( i )
     413             :         {
     414             :             case Compound::IATTR_STEREO_MODE:
     415           3 :                 os << static_cast< fabric::IAttribute >( value ) << std::endl;
     416           3 :                 break;
     417             : 
     418             :             case Compound::IATTR_STEREO_ANAGLYPH_LEFT_MASK:
     419             :             case Compound::IATTR_STEREO_ANAGLYPH_RIGHT_MASK:
     420           2 :                 os << ColorMask( value ) << std::endl;
     421           2 :                 break;
     422             : 
     423             :             default:
     424           0 :                 LBASSERTINFO( 0, "unimplemented" );
     425             :         }
     426             :     }
     427             : 
     428         134 :     os << lunchbox::exdent << '}' << std::endl
     429         134 :        << lunchbox::enableHeader << lunchbox::enableFlush;
     430         134 :     return os;
     431             : }
     432             : 
     433             : }
     434          27 : }

Generated by: LCOV version 1.10