VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gvstartup.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gvstartup.h
19 ///
20 
21 #ifndef GV_STARTUP__H
22 #define GV_STARTUP__H
23 
24 #include "gdef.h"
25 #include "glogoutput.h"
26 #include "gpidfile.h"
27 #include "ggetopt.h"
28 
29 namespace Gv
30 {
31  class Startup ;
32 }
33 
34 /// \class Gv::Startup
35 /// A handy synthesis of G::LogOutput, G::GetOpt, G::Root, G::Daemon and
36 /// G::PidFile, used to initialise a server process.
37 ///
39 {
40 public:
41  Startup( const G::GetOpt & , const std::string & args_help , bool argc_ok ,
42  const std::string & extra_help = std::string() ) ;
43  ///< Constructor, typically used very early in main(). Parses the
44  ///< command-line and processes "--help" and "--version". Assumes
45  ///< there are options for "daemon", "user", "verbose", "debug",
46  ///< "log-time", "syslog" and "pid-file". Throws Gv::Exit for
47  ///< an immediate exit.
48 
49  void start() ;
50  ///< Called just before the event loop. This should be used after all
51  ///< non-event-driven initialisation has completed. The process forks and exits
52  ///< the parent, if required.
53 
54  void report( const std::string & prefix , std::exception & e ) ;
55  ///< Reports an error if start()ed and "daemon" or "syslog" are in effect.
56  ///< This is useful for errors that would otherwise only go to stderr
57  ///< since stderr might be closed.
58 
59  void report( const std::string & prefix , const std::string & what ) ;
60  ///< Reports an error if start()ed and "daemon" or "syslog" are in effect.
61 
62  static void sanitise( int argc , char * argv [] ) ;
63  ///< Removes sensitive information from the command-line, if possible.
64 
65 private:
66  Startup( const Startup & ) ;
67  void operator=( const Startup & ) ;
68  static void onSignal( int ) ;
69 
70 private:
71  bool m_debug ;
72  G::LogOutput m_log_output ;
73  bool m_daemon ;
74  bool m_syslog ;
75  bool m_verbose ;
76  G::PidFile m_pid_file ;
77  std::string m_user ;
78  bool m_started ;
79 } ;
80 
81 #endif
void report(const std::string &prefix, std::exception &e)
Reports an error if start()ed and "daemon" or "syslog" are in effect.
Definition: gvstartup.cpp:189
A command line option parser.
Definition: ggetopt.h:55
Startup(const G::GetOpt &, const std::string &args_help, bool argc_ok, const std::string &extra_help=std::string())
Constructor, typically used very early in main().
Definition: gvstartup.cpp:77
static void sanitise(int argc, char *argv[])
Removes sensitive information from the command-line, if possible.
Definition: gvstartup.cpp:206
Controls and implements low-level logging output, as used by the Log interface.
Definition: glogoutput.h:41
A handy synthesis of G::LogOutput, G::GetOpt, G::Root, G::Daemon and G::PidFile, used to initialise a...
Definition: gvstartup.h:38
A class for creating pid files.
Definition: gpidfile.h:55
void start()
Called just before the event loop.
Definition: gvstartup.cpp:160