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 : static Global* _instance = 0;
28 :
29 51772 : Global* Global::instance()
30 : {
31 51772 : if (!_instance)
32 404 : _instance = new Global();
33 :
34 51772 : return _instance;
35 : }
36 :
37 402 : void Global::clear()
38 : {
39 402 : delete _instance;
40 402 : _instance = 0;
41 402 : }
42 :
43 610 : Global::Global()
44 : {
45 610 : _setupDefaults();
46 610 : _readEnvironment();
47 610 : }
48 :
49 816 : void Global::_setupDefaults()
50 : {
51 : // connection
52 4896 : for (uint32_t i = 0; i < ConnectionDescription::IATTR_ALL; ++i)
53 4080 : _connectionIAttributes[i] = fabric::UNDEFINED;
54 :
55 816 : _connectionIAttributes[ConnectionDescription::IATTR_TYPE] =
56 : co::CONNECTIONTYPE_TCPIP;
57 816 : _connectionIAttributes[ConnectionDescription::IATTR_PORT] = 0;
58 816 : _connectionIAttributes[ConnectionDescription::IATTR_BANDWIDTH] = 0;
59 816 : _connectionSAttributes[ConnectionDescription::SATTR_FILENAME] = "default";
60 :
61 : // config
62 6528 : for (uint32_t i = 0; i < Config::FATTR_ALL; ++i)
63 5712 : _configFAttributes[i] = 0.f;
64 5712 : for (uint32_t i = 0; i < Config::IATTR_ALL; ++i)
65 4896 : _configIAttributes[i] = fabric::UNDEFINED;
66 :
67 816 : _configFAttributes[Config::FATTR_EYE_BASE] = 0.05f;
68 816 : _configIAttributes[Config::IATTR_ROBUSTNESS] = fabric::AUTO;
69 :
70 : // node
71 5712 : for (uint32_t i = 0; i < Node::CATTR_ALL; ++i)
72 4896 : _nodeCAttributes[i] = 0;
73 7344 : for (uint32_t i = 0; i < Node::IATTR_ALL; ++i)
74 6528 : _nodeIAttributes[i] = fabric::UNDEFINED;
75 :
76 816 : _nodeIAttributes[Node::IATTR_LAUNCH_TIMEOUT] = 60000; // ms
77 816 : _nodeIAttributes[Node::IATTR_HINT_AFFINITY] = fabric::AUTO;
78 : _nodeSAttributes[Node::SATTR_LAUNCH_COMMAND] =
79 816 : "ssh -n %h %c --eq-logfile %q%d/%h.%n.log%q";
80 : #ifdef WIN32
81 : _nodeCAttributes[Node::CATTR_LAUNCH_COMMAND_QUOTE] = '\"';
82 : #else
83 816 : _nodeCAttributes[Node::CATTR_LAUNCH_COMMAND_QUOTE] = '\'';
84 : #endif
85 :
86 : // pipe
87 6528 : for (uint32_t i = 0; i < Pipe::IATTR_ALL; ++i)
88 5712 : _pipeIAttributes[i] = fabric::UNDEFINED;
89 :
90 816 : _pipeIAttributes[Pipe::IATTR_HINT_THREAD] = fabric::ON;
91 816 : _pipeIAttributes[Pipe::IATTR_HINT_AFFINITY] = fabric::AUTO;
92 :
93 : // window
94 17952 : for (uint32_t i = 0; i < WindowSettings::IATTR_ALL; ++i)
95 17136 : _windowIAttributes[i] = fabric::UNDEFINED;
96 :
97 816 : _windowIAttributes[WindowSettings::IATTR_HINT_CORE_PROFILE] = fabric::OFF;
98 816 : _windowIAttributes[WindowSettings::IATTR_HINT_OPENGL_MAJOR] = fabric::AUTO;
99 816 : _windowIAttributes[WindowSettings::IATTR_HINT_OPENGL_MINOR] = fabric::AUTO;
100 816 : _windowIAttributes[WindowSettings::IATTR_HINT_STEREO] = fabric::AUTO;
101 816 : _windowIAttributes[WindowSettings::IATTR_HINT_DOUBLEBUFFER] = fabric::AUTO;
102 816 : _windowIAttributes[WindowSettings::IATTR_HINT_FULLSCREEN] = fabric::OFF;
103 816 : _windowIAttributes[WindowSettings::IATTR_HINT_DECORATION] = fabric::AUTO;
104 816 : _windowIAttributes[WindowSettings::IATTR_HINT_DRAWABLE] = fabric::WINDOW;
105 816 : _windowIAttributes[WindowSettings::IATTR_HINT_SCREENSAVER] = fabric::AUTO;
106 816 : _windowIAttributes[WindowSettings::IATTR_HINT_GRAB_POINTER] = fabric::ON;
107 816 : _windowIAttributes[WindowSettings::IATTR_PLANES_COLOR] = fabric::AUTO;
108 816 : _windowIAttributes[WindowSettings::IATTR_PLANES_DEPTH] = fabric::AUTO;
109 816 : _windowIAttributes[WindowSettings::IATTR_PLANES_STENCIL] = fabric::AUTO;
110 816 : _windowIAttributes[WindowSettings::IATTR_PLANES_SAMPLES] = fabric::AUTO;
111 : #ifdef NDEBUG
112 : _windowIAttributes[WindowSettings::IATTR_HINT_STATISTICS] = fabric::FASTEST;
113 : #else
114 816 : _windowIAttributes[WindowSettings::IATTR_HINT_STATISTICS] = fabric::NICEST;
115 : #endif
116 :
117 : // channel
118 6528 : for (uint32_t i = 0; i < Channel::IATTR_ALL; ++i)
119 5712 : _channelIAttributes[i] = fabric::UNDEFINED;
120 :
121 : #ifdef NDEBUG
122 : _channelIAttributes[Channel::IATTR_HINT_STATISTICS] = fabric::FASTEST;
123 : #else
124 816 : _channelIAttributes[Channel::IATTR_HINT_STATISTICS] = fabric::NICEST;
125 : #endif
126 816 : _channelIAttributes[Channel::IATTR_HINT_SENDTOKEN] = fabric::OFF;
127 :
128 : // compound
129 4896 : for (uint32_t i = 0; i < Compound::IATTR_ALL; ++i)
130 4080 : _compoundIAttributes[i] = fabric::UNDEFINED;
131 816 : }
132 :
133 610 : void Global::_readEnvironment()
134 : {
135 3050 : for (uint32_t i = 0; i < ConnectionDescription::SATTR_ALL; ++i)
136 : {
137 : const std::string& name = ConnectionDescription::getSAttributeString(
138 2440 : (ConnectionDescription::SAttribute)i);
139 2440 : const char* envValue = getenv(name.c_str());
140 :
141 2440 : if (envValue)
142 0 : _connectionSAttributes[i] = envValue;
143 : }
144 3660 : for (uint32_t i = 0; i < ConnectionDescription::IATTR_ALL; ++i)
145 : {
146 : const std::string& name = ConnectionDescription::getIAttributeString(
147 3050 : (ConnectionDescription::IAttribute)i);
148 3050 : const char* envValue = getenv(name.c_str());
149 :
150 3050 : if (envValue)
151 0 : _connectionIAttributes[i] = atol(envValue);
152 : }
153 :
154 1830 : for (uint32_t i = 0; i < Config::FATTR_LAST; ++i)
155 : {
156 : const std::string& name =
157 1220 : Config::getFAttributeString((Config::FAttribute)i);
158 1220 : const char* envValue = getenv(name.c_str());
159 :
160 1220 : if (envValue)
161 0 : _configFAttributes[i] = atof(envValue);
162 : }
163 1220 : for (uint32_t i = 0; i < Config::IATTR_LAST; ++i)
164 : {
165 : const std::string& name =
166 610 : Config::getIAttributeString((Config::IAttribute)i);
167 610 : const char* envValue = getenv(name.c_str());
168 :
169 610 : if (envValue)
170 8 : _configIAttributes[i] = atol(envValue);
171 : }
172 :
173 1220 : for (uint32_t i = 0; i < Node::SATTR_LAST; ++i)
174 : {
175 : const std::string& name =
176 610 : Node::getSAttributeString((Node::SAttribute)i);
177 610 : const char* envValue = getenv(name.c_str());
178 :
179 610 : if (envValue)
180 0 : _nodeSAttributes[i] = envValue;
181 : }
182 1220 : for (uint32_t i = 0; i < Node::CATTR_LAST; ++i)
183 : {
184 : const std::string& name =
185 610 : Node::getCAttributeString((Node::CAttribute)i);
186 610 : const char* envValue = getenv(name.c_str());
187 :
188 610 : if (envValue)
189 0 : _nodeCAttributes[i] = envValue[0];
190 : }
191 2440 : for (uint32_t i = 0; i < Node::IATTR_LAST; ++i)
192 : {
193 : const std::string& name =
194 1830 : Node::getIAttributeString((Node::IAttribute)i);
195 1830 : const char* envValue = getenv(name.c_str());
196 :
197 1830 : if (envValue)
198 0 : _nodeIAttributes[i] = atol(envValue);
199 : }
200 1830 : for (uint32_t i = 0; i < Pipe::IATTR_LAST; ++i)
201 : {
202 : const std::string& name =
203 1220 : Pipe::getIAttributeString((Pipe::IAttribute)i);
204 1220 : const char* envValue = getenv(name.c_str());
205 :
206 1220 : if (envValue)
207 0 : _pipeIAttributes[i] = atol(envValue);
208 : }
209 13420 : for (uint32_t i = 0; i < WindowSettings::IATTR_LAST; ++i)
210 : {
211 : const std::string& name =
212 12810 : Window::getIAttributeString((WindowSettings::IAttribute)i);
213 12810 : const char* envValue = getenv(name.c_str());
214 :
215 12810 : if (envValue)
216 0 : _windowIAttributes[i] = atol(envValue);
217 : }
218 1830 : for (uint32_t i = 0; i < Channel::IATTR_LAST; ++i)
219 : {
220 : const std::string& name =
221 1220 : Channel::getIAttributeString((Channel::IAttribute)i);
222 1220 : const char* envValue = getenv(name.c_str());
223 :
224 1220 : if (envValue)
225 0 : _channelIAttributes[i] = atol(envValue);
226 : }
227 1220 : for (uint32_t i = 0; i < Channel::SATTR_LAST; ++i)
228 : {
229 : const std::string& name =
230 610 : Channel::getSAttributeString((Channel::SAttribute)i);
231 610 : const char* envValue = getenv(name.c_str());
232 :
233 610 : if (envValue)
234 0 : _channelSAttributes[i] = envValue;
235 : }
236 3660 : for (uint32_t i = 0; i < Compound::IATTR_ALL; ++i)
237 : {
238 : const std::string& name =
239 3050 : Compound::getIAttributeString((Compound::IAttribute)i);
240 3050 : const char* envValue = getenv(name.c_str());
241 :
242 3050 : if (envValue)
243 0 : _compoundIAttributes[i] = atol(envValue);
244 : }
245 1830 : for (uint32_t i = 0; i < View::SATTR_LAST; ++i)
246 : {
247 : const std::string& name =
248 1220 : View::getSAttributeString((View::SAttribute)i);
249 1220 : const char* envValue = getenv(name.c_str());
250 :
251 1220 : if (envValue)
252 0 : _viewSAttributes[i] = envValue;
253 : }
254 610 : }
255 :
256 : #define GLOBAL_ATTR_LENGTH 50
257 :
258 206 : std::ostream& operator<<(std::ostream& os, const Global* global)
259 : {
260 412 : Global reference;
261 206 : reference._setupDefaults(); // ignore environment variables
262 :
263 206 : os << lunchbox::disableFlush << lunchbox::disableHeader << "#Equalizer "
264 412 : << global->getConfigFAttribute(Config::FATTR_VERSION) << " ascii"
265 206 : << std::endl
266 206 : << std::endl
267 206 : << "global" << std::endl
268 206 : << '{' << lunchbox::indent << std::endl;
269 :
270 1236 : for (uint32_t i = 0; i < ConnectionDescription::IATTR_ALL; ++i)
271 : {
272 1030 : const int value = global->_connectionIAttributes[i];
273 1030 : if (value == reference._connectionIAttributes[i])
274 1030 : 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 1030 : for (uint32_t i = 0; i < ConnectionDescription::SATTR_ALL; ++i)
292 : {
293 824 : const std::string& value = global->_connectionSAttributes[i];
294 824 : if (value == reference._connectionSAttributes[i])
295 820 : 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 1648 : for (uint32_t i = 0; i < Config::FATTR_ALL; ++i)
304 : {
305 1442 : if (i == Config::FATTR_VERSION)
306 206 : continue;
307 :
308 1236 : const float value = global->_configFAttributes[i];
309 1236 : if (value == reference._configFAttributes[i])
310 1232 : continue;
311 :
312 : const std::string& name =
313 4 : Config::getFAttributeString(static_cast<Config::FAttribute>(i));
314 8 : os << name << std::string(GLOBAL_ATTR_LENGTH - name.length(), ' ')
315 4 : << value << std::endl;
316 : }
317 :
318 1442 : for (uint32_t i = 0; i < Config::IATTR_ALL; ++i)
319 : {
320 1236 : const int32_t value = global->_configIAttributes[i];
321 1236 : if (value == reference._configIAttributes[i])
322 1228 : continue;
323 :
324 : const std::string& name =
325 8 : Config::getIAttributeString(static_cast<Config::IAttribute>(i));
326 16 : os << name << std::string(GLOBAL_ATTR_LENGTH - name.length(), ' ')
327 8 : << static_cast<fabric::IAttribute>(value) << std::endl;
328 : }
329 :
330 1442 : for (uint32_t i = 0; i < Node::SATTR_ALL; ++i)
331 : {
332 1236 : const std::string& value = global->_nodeSAttributes[i];
333 1236 : if (value == reference._nodeSAttributes[i])
334 1234 : continue;
335 :
336 : const std::string& name =
337 2 : Node::getSAttributeString(static_cast<Node::SAttribute>(i));
338 4 : os << name << std::string(GLOBAL_ATTR_LENGTH - name.length(), ' ')
339 2 : << "\"" << value << "\"" << std::endl;
340 : }
341 :
342 1442 : for (uint32_t i = 0; i < Node::CATTR_ALL; ++i)
343 : {
344 1236 : const char value = global->_nodeCAttributes[i];
345 1236 : if (value == reference._nodeCAttributes[i])
346 1234 : continue;
347 :
348 : const std::string& name =
349 2 : Node::getCAttributeString(static_cast<Node::CAttribute>(i));
350 4 : os << name << std::string(GLOBAL_ATTR_LENGTH - name.length(), ' ')
351 4 : << "'" << value << "'" << std::endl;
352 : }
353 :
354 1854 : for (uint32_t i = 0; i < Node::IATTR_ALL; ++i)
355 : {
356 1648 : const int32_t value = global->_nodeIAttributes[i];
357 1648 : if (value == reference._nodeIAttributes[i])
358 1644 : continue;
359 :
360 : const std::string& name =
361 4 : Node::getIAttributeString(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 1648 : for (uint32_t i = 0; i < Pipe::IATTR_ALL; ++i)
367 : {
368 1442 : const int value = global->_pipeIAttributes[i];
369 1442 : if (value == reference._pipeIAttributes[i])
370 1440 : continue;
371 :
372 : const std::string& name =
373 2 : Pipe::getIAttributeString(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 4532 : for (uint32_t i = 0; i < WindowSettings::IATTR_ALL; ++i)
379 : {
380 4326 : const int value = global->_windowIAttributes[i];
381 4326 : if (value == reference._windowIAttributes[i])
382 4170 : 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 1648 : for (uint32_t i = 0; i < Channel::IATTR_ALL; ++i)
391 : {
392 1442 : const int value = global->_channelIAttributes[i];
393 1442 : if (value == reference._channelIAttributes[i])
394 1440 : continue;
395 :
396 : const std::string& name =
397 2 : Channel::getIAttributeString(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 1442 : for (uint32_t i = 0; i < Channel::SATTR_ALL; ++i)
403 : {
404 1236 : const std::string& value = global->_channelSAttributes[i];
405 1236 : if (value == reference._channelSAttributes[i])
406 1234 : continue;
407 :
408 : const std::string& name =
409 2 : Channel::getSAttributeString(static_cast<Channel::SAttribute>(i));
410 4 : os << name << std::string(GLOBAL_ATTR_LENGTH - name.length(), ' ')
411 2 : << "\"" << value << "\"" << std::endl;
412 : }
413 :
414 1236 : for (uint32_t i = 0; i < Compound::IATTR_ALL; ++i)
415 : {
416 1030 : const int value = global->_compoundIAttributes[i];
417 1030 : if (value == reference._compoundIAttributes[i])
418 1020 : continue;
419 :
420 : const std::string& name =
421 10 : Compound::getIAttributeString(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 1648 : for (uint32_t i = 0; i < View::SATTR_ALL; ++i)
441 : {
442 1442 : const std::string& value = global->_viewSAttributes[i];
443 1442 : if (value == reference._viewSAttributes[i])
444 1442 : continue;
445 :
446 : const std::string& name =
447 0 : View::getSAttributeString(static_cast<View::SAttribute>(i));
448 0 : os << name << std::string(GLOBAL_ATTR_LENGTH - name.length(), ' ')
449 0 : << "\"" << value << "\"" << std::endl;
450 : }
451 :
452 206 : os << lunchbox::exdent << '}' << std::endl
453 206 : << lunchbox::enableHeader << lunchbox::enableFlush;
454 412 : return os;
455 : }
456 : }
457 60 : }
|