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