LCOV - code coverage report
Current view: top level - lunchbox - init.cpp (source / functions) Hit Total Coverage
Test: Lunchbox Lines: 25 31 80.6 %
Date: 2018-10-03 05:33:11 Functions: 4 4 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2008-2016, 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 "file.h"
      24             : #include "thread.h"
      25             : 
      26             : #include <fstream>
      27             : #include <stdlib.h>
      28             : #include <time.h>
      29             : 
      30             : namespace lunchbox
      31             : {
      32             : namespace
      33             : {
      34          25 : static a_int32_t _initialized;
      35             : }
      36             : 
      37           5 : bool init(const int argc, char** argv)
      38             : {
      39          13 :     for (int i = 1; i < argc; ++i)
      40             :     {
      41             :         // verbose options
      42           8 :         if (std::string(argv[i]) == "-vv")
      43           0 :             Log::level += 2;
      44           8 :         else if (std::string(argv[i]) == "-v")
      45           0 :             ++Log::level;
      46           8 :         else if (std::string(argv[i]) == "--lb-logfile")
      47             :         {
      48           0 :             std::string logfile = getFilename(argv[0]) + ".log";
      49           0 :             if (i + 1 < argc)
      50           0 :                 logfile = argv[++i];
      51           0 :             Log::setOutput(logfile);
      52             :         }
      53             :     }
      54             : 
      55           5 :     if (++_initialized > 1) // not first
      56           1 :         return true;
      57             : 
      58           4 :     Log::instance().setThreadName("Main");
      59             : 
      60           4 :     const time_t now = ::time(0);
      61             : #ifdef _WIN32
      62             :     char* gmtString = ::ctime(&now);
      63             : #else
      64             :     char gmtString[32];
      65           4 :     ::ctime_r(&now, gmtString);
      66             : 
      67           4 :     setenv("AVAHI_COMPAT_NOWARN", "1", 0); // get rid of annoying avahi warning
      68             : #endif
      69             : 
      70          12 :     LBDEBUG << "Log level " << Log::getLogLevelString() << " topics "
      71          12 :             << Log::topics << " date " << gmtString << std::flush;
      72           4 :     return true;
      73             : }
      74             : 
      75           6 : bool exit()
      76             : {
      77           6 :     if (--_initialized > 0) // not last
      78           1 :         return true;
      79             : 
      80           5 :     Log::reset();
      81             : 
      82           5 :     if (_initialized < 0)
      83             :     {
      84           1 :         LBERROR << "init/exit call mismatch" << std::endl;
      85           1 :         _initialized = 0;
      86           1 :         return false;
      87             :     }
      88           4 :     return true;
      89             : }
      90          75 : }

Generated by: LCOV version 1.11