File: ntservice.hh

package info (click to toggle)
pdns-recursor 3.2-4+deb6u1
  • links: PTS
  • area: main
  • in suites: squeeze-lts
  • size: 1,220 kB
  • ctags: 2,721
  • sloc: cpp: 12,564; ansic: 2,587; sh: 510; makefile: 133
file content (102 lines) | stat: -rw-r--r-- 2,541 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
    PowerDNS Versatile Database Driven Nameserver
    Copyright (C) 2002  PowerDNS.COM BV

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 2
    as published by the Free Software Foundation
    

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/*!
\file ntservice.hh
\brief This file contains the NTService class specification.
*/

#ifndef NTSERVICE_HH
#define NTSERVICE_HH
#include "utility.hh"

#include <string>
#include "singleton.hh"


//! The NTService class is responsible for giving the program NT Service characteristics.
class NTService : public Singleton< NTService >
{
private:
  //! Is the program running as a NT Service?
  bool m_runningAsService;
  
  //! Service status handle.
  SERVICE_STATUS_HANDLE m_serviceStatusHandle;
  
protected:
  //! Status code.
  DWORD m_statusCode;

  //! Error code.
  DWORD m_errorCode;

  //! Main function.
  virtual int main( int argc, char *argv[] )
  {
    return 0;
  }

  //! Control handler.
  virtual void ctrlHandler( DWORD controlCode )
  {
  }

  //! Sets the service's status and error codes.
  void setStatus( DWORD status, DWORD error = 0 );
  
public:
  //! Default constructor.
  NTService( void );

  //! Destructor.
  virtual ~NTService( void );

  //! Starts the service.
  int start( int argc, char *argv[], bool asService = true );

  //! Control handler (calls NTService::ctrlHandler()).
  static void WINAPI s_ctrlHandler( DWORD controlCode );
  
  //! Service main (calls NTService::main()).
  static void WINAPI s_serviceMain( DWORD argc, LPTSTR *argv );
  
  //! Returns the name of the service.
  virtual std::string getServiceName( void )
  {
    return "NTService";
  }

  //! Returns whether the program is running as a service or not.
  bool isRunningAsService( void );
  
  //! Registers the service with the system.
  bool registerService( const std::string & description, bool registerLog = true );

  //! Unregisters the service.
  bool unregisterService( void );
  
  //! Stops the service.
  bool stop( void );

};


#endif // NTSERVICE_H