Line data Source code
1 :
2 : /* Copyright (c) 2008-2015, Stefan Eilemann <eile@equalizergraphics.com>
3 : * Cedric Stalder <cedric.stalder@gmail.com>
4 : * 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 27 : static a_int32_t _initialized;
34 : }
35 :
36 2 : bool init( const int argc, char** argv )
37 : {
38 : #ifndef NDEBUG
39 2 : LBVERB << "Options: ";
40 2 : for( int i = 1; i < argc; ++i )
41 0 : LBVERB << argv[i] << ", ";
42 2 : LBVERB << std::endl;
43 : #endif
44 :
45 2 : for( int i = 1; i < argc; ++i )
46 : {
47 : // verbose options
48 0 : if( std::string( argv[i] ) == "-vv" )
49 0 : Log::level += 2;
50 0 : else if( std::string( argv[i] ) == "-v" )
51 0 : ++Log::level;
52 : }
53 :
54 2 : if( ++_initialized > 1 ) // not first
55 0 : return true;
56 :
57 2 : Log::instance().setThreadName( "Main" );
58 :
59 2 : const time_t now = ::time(0);
60 : #ifdef _WIN32
61 : char* gmtString = ::ctime( &now );
62 : #else
63 : char gmtString[32];
64 2 : ::ctime_r( &now, gmtString );
65 :
66 2 : setenv( "AVAHI_COMPAT_NOWARN", "1", 0 ); // get rid of annoying avahi warning
67 : #endif
68 :
69 6 : LBDEBUG << "Log level " << Log::getLogLevelString() << " topics "
70 6 : << Log::topics << " date " << gmtString << std::flush;
71 2 : return true;
72 : }
73 :
74 2 : bool exit()
75 : {
76 2 : if( --_initialized > 0 ) // not last
77 0 : return true;
78 2 : LBASSERT( _initialized == 0 );
79 :
80 2 : Log::reset();
81 2 : return true;
82 : }
83 :
84 81 : }
|