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 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 += 2;
50 0 : else if( std::string( argv[i] ) == "-v" )
51 0 : ++Log::level;
52 : }
53 :
54 5 : if( ++_initialized > 1 ) // not first
55 1 : return true;
56 :
57 4 : Log::instance().setThreadName( "Main" );
58 :
59 4 : const time_t now = ::time(0);
60 : #ifdef _WIN32
61 : char* gmtString = ::ctime( &now );
62 : #else
63 : char gmtString[32];
64 4 : ::ctime_r( &now, gmtString );
65 :
66 4 : setenv( "AVAHI_COMPAT_NOWARN", "1", 0 ); // get rid of annoying avahi warning
67 : #endif
68 :
69 12 : LBDEBUG << "Log level " << Log::getLogLevelString() << " topics "
70 12 : << Log::topics << " date " << gmtString << std::flush;
71 4 : return true;
72 : }
73 :
74 6 : bool exit()
75 : {
76 6 : if( --_initialized > 0 ) // not last
77 1 : return true;
78 :
79 5 : Log::reset();
80 :
81 5 : if( _initialized < 0 )
82 : {
83 1 : LBERROR << "init/exit call mismatch" << std::endl;
84 1 : _initialized = 0;
85 1 : return false;
86 : }
87 4 : return true;
88 : }
89 :
90 81 : }
|