LCOV - code coverage report
Current view: top level - eq/server - global.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 219 243 90.1 %
Date: 2016-09-29 05:02:09 Functions: 8 8 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2006-2015, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                          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       50344 : Global* Global::instance()
      31             : {
      32       50344 :     if( !_instance )
      33         446 :         _instance = new Global();
      34             : 
      35       50344 :     return _instance;
      36             : }
      37             : 
      38         444 : void Global::clear()
      39             : {
      40         444 :     delete _instance;
      41         444 :     _instance = 0;
      42         444 : }
      43             : 
      44         680 : Global::Global()
      45             : {
      46         680 :     _setupDefaults();
      47         680 :     _readEnvironment();
      48         680 : }
      49             : 
      50         914 : void Global::_setupDefaults()
      51             : {
      52             :     // connection
      53        5484 :     for( uint32_t i=0; i<ConnectionDescription::IATTR_ALL; ++i )
      54        4570 :         _connectionIAttributes[i] = fabric::UNDEFINED;
      55             : 
      56             :     _connectionIAttributes[ ConnectionDescription::IATTR_TYPE ] =
      57         914 :         co::CONNECTIONTYPE_TCPIP;
      58         914 :     _connectionIAttributes[ ConnectionDescription::IATTR_PORT ] = 0;
      59         914 :     _connectionIAttributes[ ConnectionDescription::IATTR_BANDWIDTH ] = 0;
      60         914 :     _connectionSAttributes[ ConnectionDescription::SATTR_FILENAME ] = "default";
      61             : 
      62             :     // config
      63        7312 :     for( uint32_t i=0; i<Config::FATTR_ALL; ++i )
      64        6398 :         _configFAttributes[i] = 0.f;
      65        6398 :     for( uint32_t i=0; i<Config::IATTR_ALL; ++i )
      66        5484 :         _configIAttributes[i] = fabric::UNDEFINED;
      67             : 
      68         914 :     _configFAttributes[Config::FATTR_EYE_BASE]         = 0.05f;
      69         914 :     _configIAttributes[Config::IATTR_ROBUSTNESS]       = fabric::AUTO;
      70             : 
      71             :     // node
      72        6398 :     for( uint32_t i=0; i < Node::CATTR_ALL; ++i )
      73        5484 :         _nodeCAttributes[i] = 0;
      74        8226 :     for( uint32_t i=0; i < Node::IATTR_ALL; ++i )
      75        7312 :         _nodeIAttributes[i] = fabric::UNDEFINED;
      76             : 
      77         914 :     _nodeIAttributes[Node::IATTR_LAUNCH_TIMEOUT] = 60000; // ms
      78         914 :     _nodeIAttributes[Node::IATTR_HINT_AFFINITY] = fabric::AUTO;
      79         914 :     _nodeSAttributes[Node::SATTR_LAUNCH_COMMAND] =
      80         914 :         "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         914 :     _nodeCAttributes[Node::CATTR_LAUNCH_COMMAND_QUOTE] = '\'';
      85             : #endif
      86             : 
      87             :     // pipe
      88        7312 :     for( uint32_t i=0; i<Pipe::IATTR_ALL; ++i )
      89        6398 :         _pipeIAttributes[i] = fabric::UNDEFINED;
      90             : 
      91         914 :     _pipeIAttributes[Pipe::IATTR_HINT_THREAD] = fabric::ON;
      92         914 :     _pipeIAttributes[Pipe::IATTR_HINT_AFFINITY] = fabric::AUTO;
      93             : 
      94             :     // window
      95       20108 :     for( uint32_t i=0; i<WindowSettings::IATTR_ALL; ++i )
      96       19194 :         _windowIAttributes[i] = fabric::UNDEFINED;
      97             : 
      98         914 :     _windowIAttributes[WindowSettings::IATTR_HINT_CORE_PROFILE] = fabric::OFF;
      99         914 :     _windowIAttributes[WindowSettings::IATTR_HINT_OPENGL_MAJOR] = fabric::AUTO;
     100         914 :     _windowIAttributes[WindowSettings::IATTR_HINT_OPENGL_MINOR] = fabric::AUTO;
     101         914 :     _windowIAttributes[WindowSettings::IATTR_HINT_STEREO]       = fabric::AUTO;
     102         914 :     _windowIAttributes[WindowSettings::IATTR_HINT_DOUBLEBUFFER] = fabric::AUTO;
     103         914 :     _windowIAttributes[WindowSettings::IATTR_HINT_FULLSCREEN]   = fabric::OFF;
     104         914 :     _windowIAttributes[WindowSettings::IATTR_HINT_DECORATION]   = fabric::AUTO;
     105         914 :     _windowIAttributes[WindowSettings::IATTR_HINT_DRAWABLE]     = fabric::WINDOW;
     106         914 :     _windowIAttributes[WindowSettings::IATTR_HINT_SCREENSAVER]  = fabric::AUTO;
     107         914 :     _windowIAttributes[WindowSettings::IATTR_HINT_GRAB_POINTER] = fabric::ON;
     108         914 :     _windowIAttributes[WindowSettings::IATTR_PLANES_COLOR]      = fabric::AUTO;
     109         914 :     _windowIAttributes[WindowSettings::IATTR_PLANES_DEPTH]      = fabric::AUTO;
     110         914 :     _windowIAttributes[WindowSettings::IATTR_PLANES_STENCIL]    = fabric::AUTO;
     111         914 :     _windowIAttributes[WindowSettings::IATTR_PLANES_SAMPLES]    = fabric::AUTO;
     112             : #ifdef NDEBUG
     113             :     _windowIAttributes[WindowSettings::IATTR_HINT_STATISTICS]   = fabric::FASTEST;
     114             : #else
     115         914 :     _windowIAttributes[WindowSettings::IATTR_HINT_STATISTICS]   = fabric::NICEST;
     116             : #endif
     117             : 
     118             :     // channel
     119        7312 :     for( uint32_t i=0; i<Channel::IATTR_ALL; ++i )
     120        6398 :         _channelIAttributes[i] = fabric::UNDEFINED;
     121             : 
     122             : #ifdef NDEBUG
     123             :     _channelIAttributes[Channel::IATTR_HINT_STATISTICS] = fabric::FASTEST;
     124             : #else
     125         914 :     _channelIAttributes[Channel::IATTR_HINT_STATISTICS] = fabric::NICEST;
     126             : #endif
     127         914 :     _channelIAttributes[Channel::IATTR_HINT_SENDTOKEN] = fabric::OFF;
     128             : 
     129             :     // compound
     130        5484 :     for( uint32_t i=0; i<Compound::IATTR_ALL; ++i )
     131        4570 :         _compoundIAttributes[i] = fabric::UNDEFINED;
     132         914 : }
     133             : 
     134         680 : void Global::_readEnvironment()
     135             : {
     136        3400 :     for( uint32_t i=0; i<ConnectionDescription::SATTR_ALL; ++i )
     137             :     {
     138             :         const std::string& name = ConnectionDescription::getSAttributeString(
     139        2720 :             (ConnectionDescription::SAttribute)i);
     140        2720 :         const char*   envValue = getenv( name.c_str( ));
     141             : 
     142        2720 :         if( envValue )
     143           0 :             _connectionSAttributes[i] = envValue;
     144             :     }
     145        4080 :     for( uint32_t i=0; i<ConnectionDescription::IATTR_ALL; ++i )
     146             :     {
     147             :         const std::string& name = ConnectionDescription::getIAttributeString(
     148        3400 :             (ConnectionDescription::IAttribute)i);
     149        3400 :         const char*   envValue = getenv( name.c_str( ));
     150             : 
     151        3400 :         if( envValue )
     152           0 :             _connectionIAttributes[i] = atol( envValue );
     153             :     }
     154             : 
     155        2040 :     for( uint32_t i=0; i < Config::FATTR_LAST; ++i )
     156             :     {
     157             :         const std::string& name = Config::getFAttributeString(
     158        1360 :             (Config::FAttribute)i);
     159        1360 :         const char*   envValue = getenv( name.c_str( ));
     160             : 
     161        1360 :         if( envValue )
     162           0 :             _configFAttributes[i] = atof( envValue );
     163             :     }
     164        1360 :     for( uint32_t i=0; i < Config::IATTR_LAST; ++i )
     165             :     {
     166             :         const std::string& name = Config::getIAttributeString(
     167         680 :             (Config::IAttribute)i);
     168         680 :         const char*   envValue = getenv( name.c_str( ));
     169             : 
     170         680 :         if( envValue )
     171           0 :             _configIAttributes[i] = atol( envValue );
     172             :     }
     173             : 
     174        1360 :     for( uint32_t i=0; i < Node::SATTR_LAST; ++i )
     175             :     {
     176             :         const std::string& name = Node::getSAttributeString(
     177         680 :             (Node::SAttribute)i);
     178         680 :         const char*   envValue = getenv( name.c_str( ));
     179             : 
     180         680 :         if( envValue )
     181           0 :             _nodeSAttributes[i] = envValue;
     182             :     }
     183        1360 :     for( uint32_t i=0; i < Node::CATTR_LAST; ++i )
     184             :     {
     185             :         const std::string& name = Node::getCAttributeString(
     186         680 :             (Node::CAttribute)i);
     187         680 :         const char*   envValue = getenv( name.c_str( ));
     188             : 
     189         680 :         if( envValue )
     190           0 :             _nodeCAttributes[i] = envValue[0];
     191             :     }
     192        2720 :     for( uint32_t i=0; i < Node::IATTR_LAST; ++i )
     193             :     {
     194             :         const std::string& name     = Node::getIAttributeString(
     195        2040 :             (Node::IAttribute)i);
     196        2040 :         const char*   envValue = getenv( name.c_str( ));
     197             : 
     198        2040 :         if( envValue )
     199           0 :             _nodeIAttributes[i] = atol( envValue );
     200             :     }
     201        2040 :     for( uint32_t i=0; i<Pipe::IATTR_LAST; ++i )
     202             :     {
     203             :         const std::string& name     = Pipe::getIAttributeString(
     204        1360 :             (Pipe::IAttribute)i);
     205        1360 :         const char*   envValue = getenv( name.c_str( ));
     206             : 
     207        1360 :         if( envValue )
     208           0 :             _pipeIAttributes[i] = atol( envValue );
     209             :     }
     210       14960 :     for( uint32_t i=0; i < WindowSettings::IATTR_LAST; ++i )
     211             :     {
     212             :         const std::string& name     = Window::getIAttributeString(
     213       14280 :             (WindowSettings::IAttribute)i);
     214       14280 :         const char*   envValue = getenv( name.c_str( ));
     215             : 
     216       14280 :         if( envValue )
     217           0 :             _windowIAttributes[i] = atol( envValue );
     218             :     }
     219        2040 :     for( uint32_t i=0; i < Channel::IATTR_LAST; ++i )
     220             :     {
     221             :         const std::string& name = Channel::getIAttributeString(
     222        1360 :             (Channel::IAttribute)i);
     223        1360 :         const char*   envValue = getenv( name.c_str( ));
     224             : 
     225        1360 :         if( envValue )
     226           0 :             _channelIAttributes[i] = atol( envValue );
     227             :     }
     228        1360 :     for( uint32_t i=0; i < Channel::SATTR_LAST; ++i )
     229             :     {
     230             :         const std::string& name = Channel::getSAttributeString(
     231         680 :             (Channel::SAttribute)i);
     232         680 :         const char*   envValue = getenv( name.c_str( ));
     233             : 
     234         680 :         if( envValue )
     235           0 :             _channelSAttributes[i] = envValue;
     236             :     }
     237        4080 :     for( uint32_t i=0; i<Compound::IATTR_ALL; ++i )
     238             :     {
     239             :         const std::string& name     = Compound::getIAttributeString(
     240        3400 :             (Compound::IAttribute)i);
     241        3400 :         const char*   envValue = getenv( name.c_str( ));
     242             : 
     243        3400 :         if( envValue )
     244           0 :             _compoundIAttributes[i] = atol( envValue );
     245             :     }
     246        2040 :     for( uint32_t i=0; i < View::SATTR_LAST; ++i )
     247             :     {
     248             :         const std::string& name = View::getSAttributeString(
     249        1360 :             (View::SAttribute)i);
     250        1360 :         const char*   envValue = getenv( name.c_str( ));
     251             : 
     252        1360 :         if( envValue )
     253           0 :             _viewSAttributes[i] = envValue;
     254             :     }
     255         680 : }
     256             : 
     257             : #define GLOBAL_ATTR_LENGTH 50
     258             : 
     259         234 : std::ostream& operator << ( std::ostream& os, const Global* global )
     260             : {
     261         234 :     Global reference;
     262         234 :     reference._setupDefaults(); // ignore environment variables
     263             : 
     264         234 :     os << lunchbox::disableFlush << lunchbox::disableHeader
     265         468 :        << "#Equalizer " << global->getConfigFAttribute( Config::FATTR_VERSION )
     266         234 :        << " ascii" << std::endl << std::endl
     267         234 :        << "global" << std::endl
     268         234 :        << '{' << lunchbox::indent << std::endl;
     269             : 
     270        1404 :     for( uint32_t i=0; i<ConnectionDescription::IATTR_ALL; ++i )
     271             :     {
     272        1170 :         const int value = global->_connectionIAttributes[i];
     273        1170 :         if( value == reference._connectionIAttributes[i] )
     274        1170 :             continue;
     275             : 
     276             :         const std::string& name = ConnectionDescription::getIAttributeString(
     277           0 :             static_cast<ConnectionDescription::IAttribute>( i ));
     278           0 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' );
     279             : 
     280           0 :         switch( i )
     281             :         {
     282             :             case ConnectionDescription::IATTR_TYPE:
     283           0 :                 os << static_cast< co::ConnectionType >( value );
     284           0 :                 break;
     285             :             default:
     286           0 :                 os << value;
     287             :         }
     288           0 :         os << std::endl;
     289             :     }
     290             : 
     291        1170 :     for( uint32_t i=0; i<ConnectionDescription::SATTR_ALL; ++i )
     292             :     {
     293         936 :         const std::string& value = global->_connectionSAttributes[i];
     294         936 :         if( value == reference._connectionSAttributes[i] )
     295         932 :             continue;
     296             : 
     297             :         const std::string& name = ConnectionDescription::getSAttributeString(
     298           4 :             static_cast<ConnectionDescription::SAttribute>( i ));
     299           8 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     300           4 :            << "\"" << value << "\"" << std::endl;
     301             :     }
     302             : 
     303        1872 :     for( uint32_t i=0; i<Config::FATTR_ALL; ++i )
     304             :     {
     305        1638 :         if( i == Config::FATTR_VERSION )
     306         234 :             continue;
     307             : 
     308        1404 :         const float value = global->_configFAttributes[i];
     309        1404 :         if( value == reference._configFAttributes[i] )
     310        1400 :             continue;
     311             : 
     312             :         const std::string& name = Config::getFAttributeString(
     313           4 :             static_cast<Config::FAttribute>( i ));
     314           8 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     315           4 :            << value << std::endl;
     316             :     }
     317             : 
     318        1638 :     for( uint32_t i=0; i<Config::IATTR_ALL; ++i )
     319             :     {
     320        1404 :         const int32_t value = global->_configIAttributes[i];
     321        1404 :         if( value == reference._configIAttributes[i] )
     322        1402 :             continue;
     323             : 
     324             :         const std::string& name = Config::getIAttributeString(
     325           2 :             static_cast<Config::IAttribute>( i ));
     326           4 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     327           2 :            << static_cast< fabric::IAttribute >( value ) << std::endl;
     328             :     }
     329             : 
     330        1638 :     for( uint32_t i=0; i<Node::SATTR_ALL; ++i )
     331             :     {
     332        1404 :         const std::string& value = global->_nodeSAttributes[i];
     333        1404 :         if( value == reference._nodeSAttributes[i] )
     334        1402 :             continue;
     335             : 
     336             :         const std::string& name = Node::getSAttributeString(
     337           2 :             static_cast<Node::SAttribute>( i ));
     338           4 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     339           2 :            << "\"" << value << "\"" << std::endl;
     340             :     }
     341             : 
     342        1638 :     for( uint32_t i=0; i<Node::CATTR_ALL; ++i )
     343             :     {
     344        1404 :         const char value = global->_nodeCAttributes[i];
     345        1404 :         if( value == reference._nodeCAttributes[i] )
     346        1402 :             continue;
     347             : 
     348             :         const std::string& name = Node::getCAttributeString(
     349           2 :             static_cast<Node::CAttribute>( i ));
     350           4 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     351           4 :            << "'" << value << "'" << std::endl;
     352             :     }
     353             : 
     354        2106 :     for( uint32_t i=0; i < Node::IATTR_ALL; ++i )
     355             :     {
     356        1872 :         const int32_t value = global->_nodeIAttributes[i];
     357        1872 :         if( value == reference._nodeIAttributes[i] )
     358        1868 :             continue;
     359             : 
     360             :         const std::string& name = Node::getIAttributeString(
     361           4 :             static_cast<Node::IAttribute>( i ));
     362           8 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     363           4 :            << static_cast< fabric::IAttribute >( value ) << std::endl;
     364             :     }
     365             : 
     366        1872 :     for( uint32_t i=0; i<Pipe::IATTR_ALL; ++i )
     367             :     {
     368        1638 :         const int value = global->_pipeIAttributes[i];
     369        1638 :         if( value == reference._pipeIAttributes[i] )
     370        1636 :             continue;
     371             : 
     372             :         const std::string& name = Pipe::getIAttributeString(
     373           2 :             static_cast<Pipe::IAttribute>( i ));
     374           4 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     375           2 :            << static_cast< fabric::IAttribute >( value ) << std::endl;
     376             :     }
     377             : 
     378        5148 :     for( uint32_t i=0; i<WindowSettings::IATTR_ALL; ++i )
     379             :     {
     380        4914 :         const int value = global->_windowIAttributes[i];
     381        4914 :         if( value == reference._windowIAttributes[i] )
     382        4758 :             continue;
     383             : 
     384             :         const std::string& name = Window::getIAttributeString(
     385         156 :             static_cast<WindowSettings::IAttribute>( i ));
     386         312 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     387         156 :            << static_cast< fabric::IAttribute >( value ) << std::endl;
     388             :     }
     389             : 
     390        1872 :     for( uint32_t i=0; i<Channel::IATTR_ALL; ++i )
     391             :     {
     392        1638 :         const int value = global->_channelIAttributes[i];
     393        1638 :         if( value == reference._channelIAttributes[i] )
     394        1636 :             continue;
     395             : 
     396             :         const std::string& name = Channel::getIAttributeString(
     397           2 :             static_cast<Channel::IAttribute>( i ));
     398           4 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     399           2 :            << static_cast< fabric::IAttribute >( value ) << std::endl;
     400             :     }
     401             : 
     402        1638 :     for( uint32_t i=0; i<Channel::SATTR_ALL; ++i )
     403             :     {
     404        1404 :         const std::string& value = global->_channelSAttributes[i];
     405        1404 :         if( value == reference._channelSAttributes[i] )
     406        1402 :             continue;
     407             : 
     408             :         const std::string& name = Channel::getSAttributeString(
     409           2 :             static_cast<Channel::SAttribute>( i ));
     410           4 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     411           2 :            << "\"" << value << "\"" << std::endl;
     412             :     }
     413             : 
     414        1404 :     for( uint32_t i=0; i<Compound::IATTR_ALL; ++i )
     415             :     {
     416        1170 :         const int value = global->_compoundIAttributes[i];
     417        1170 :         if( value == reference._compoundIAttributes[i] )
     418        1160 :             continue;
     419             : 
     420             :         const std::string& name = Compound::getIAttributeString(
     421          10 :             static_cast<Compound::IAttribute>( i ));
     422          10 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' );
     423             : 
     424          10 :         switch( i )
     425             :         {
     426             :             case Compound::IATTR_STEREO_MODE:
     427           6 :                 os << static_cast< fabric::IAttribute >( value ) << std::endl;
     428           6 :                 break;
     429             : 
     430             :             case Compound::IATTR_STEREO_ANAGLYPH_LEFT_MASK:
     431             :             case Compound::IATTR_STEREO_ANAGLYPH_RIGHT_MASK:
     432           4 :                 os << ColorMask( value ) << std::endl;
     433           4 :                 break;
     434             : 
     435             :             default:
     436           0 :                 LBASSERTINFO( 0, "unimplemented" );
     437             :         }
     438             :     }
     439             : 
     440        1872 :     for( uint32_t i=0; i<View::SATTR_ALL; ++i )
     441             :     {
     442        1638 :         const std::string& value = global->_viewSAttributes[i];
     443        1638 :         if( value == reference._viewSAttributes[i] )
     444        1638 :             continue;
     445             : 
     446             :         const std::string& name = View::getSAttributeString(
     447           0 :             static_cast<View::SAttribute>( i ));
     448           0 :         os << name << std::string( GLOBAL_ATTR_LENGTH - name.length(), ' ' )
     449           0 :            << "\"" << value << "\"" << std::endl;
     450             :     }
     451             : 
     452         234 :     os << lunchbox::exdent << '}' << std::endl
     453         234 :        << lunchbox::enableHeader << lunchbox::enableFlush;
     454         234 :     return os;
     455             : }
     456             : 
     457             : }
     458          84 : }

Generated by: LCOV version 1.11