Line data Source code
1 :
2 : /* Copyright (c) 2008-2012, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2010, Cedric Stalder <cedric.stalder@gmail.com>
4 : * 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
5 : *
6 : * This library is free software; you can redistribute it and/or modify it under
7 : * the terms of the GNU Lesser General Public License version 2.1 as published
8 : * by the Free Software Foundation.
9 : *
10 : * This library is distributed in the hope that it will be useful, but WITHOUT
11 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 : * details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public License
16 : * along with this library; if not, write to the Free Software Foundation, Inc.,
17 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #include "init.h"
21 :
22 : #include "atomic.h"
23 : #include "rng.h"
24 : #include "thread.h"
25 :
26 : #include <stdlib.h>
27 : #include <time.h>
28 :
29 : namespace lunchbox
30 : {
31 : namespace
32 : {
33 29 : static a_int32_t _initialized;
34 : }
35 :
36 5 : bool init( const int argc, char** argv )
37 : {
38 : #ifndef NDEBUG
39 5 : LBVERB << "Options: ";
40 5 : for( int i = 1; i < argc; ++i )
41 0 : LBVERB << argv[i] << ", ";
42 5 : LBVERB << std::endl;
43 : #endif
44 :
45 5 : for( int i = 1; i < argc; ++i )
46 : {
47 : // verbose options
48 0 : if( std::string( argv[i] ) == "-vv" )
49 0 : Log::level = LOG_VERB;
50 0 : else if( std::string( argv[i] ) == "-v" )
51 0 : Log::level = LOG_INFO;
52 : }
53 :
54 5 : if( ++_initialized > 1 ) // not first
55 0 : return true;
56 :
57 5 : Log::instance().setThreadName( "Main" );
58 :
59 5 : const time_t now = ::time(0);
60 : #ifdef _WIN32
61 : char* gmtString = ::ctime( &now );
62 : #else
63 : char gmtString[32];
64 5 : ::ctime_r( &now, gmtString );
65 :
66 5 : setenv( "AVAHI_COMPAT_NOWARN", "1", 0 ); // get rid of annoying avahi warning
67 : #endif
68 :
69 15 : LBINFO << "Log level " << Log::getLogLevelString() << " topics "
70 15 : << Log::topics << " date " << gmtString << std::flush;
71 :
72 5 : if( !RNG::_init( ))
73 : {
74 0 : LBERROR << "Failed to initialize random number generator" << std::endl;
75 0 : return false;
76 : }
77 :
78 5 : Thread::pinCurrentThread();
79 5 : return true;
80 : }
81 :
82 5 : bool exit()
83 : {
84 5 : if( --_initialized > 0 ) // not last
85 0 : return true;
86 5 : LBASSERT( _initialized == 0 );
87 :
88 5 : Log::reset();
89 5 : return true;
90 : }
91 :
92 87 : }
|