File: nt_servc.h

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (115 lines) | stat: -rw-r--r-- 2,878 bytes parent folder | download
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
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef NT_SERVC_INCLUDED
#define NT_SERVC_INCLUDED

/**
  @file

  @brief
  Windows NT Service class library

  Copyright Abandoned 1998 Irena Pancirov - Irnet Snc
  This file is public domain and comes with NO WARRANTY of any kind

  Modifications Copyright (c) 2000, 2025, Oracle and/or its affiliates.
  All rights reserved.
*/

#include <windows.h>

// main application thread
typedef void (*THREAD_FC)(void *);

class NTService {
 public:
  NTService();
  ~NTService();

  // install optinos
  DWORD dwDesiredAccess;
  DWORD dwServiceType;
  DWORD dwStartType;
  DWORD dwErrorControl;

  LPSTR szLoadOrderGroup;
  LPDWORD lpdwTagID;
  LPSTR szDependencies;

  // time-out (in milisec)
  int nStartTimeOut;
  int nStopTimeOut;
  int nPauseTimeOut;
  int nResumeTimeOut;

  //
  DWORD my_argc;
  LPTSTR *my_argv;
  HANDLE hShutdownEvent;
  int nError;
  DWORD dwState;

  // init service entry point
  long Init(LPCSTR szInternName, void *ServiceThread);

  // application shutdown event
  void SetShutdownEvent(HANDLE hEvent) { hShutdownEvent = hEvent; }

  // service install / un-install
  BOOL Install(int startType, LPCSTR szInternName, LPCSTR szDisplayName,
               LPCSTR szFullPath, LPCSTR szAccountName = NULL,
               LPCSTR szPassword = NULL);
  BOOL SeekStatus(LPCSTR szInternName, int OperationType);
  BOOL Remove(LPCSTR szInternName);
  BOOL IsService(LPCSTR ServiceName);
  BOOL got_service_option(char **argv, const char *service_option);
  BOOL is_super_user();

  /*
    SetRunning() is to be called by the application
    when initialization completes and it can accept
    stop request
  */
  void SetRunning(void);

  /**
    Sets a timeout after which SCM will abort service startup if SetRunning()
    was not called or the timeout was not extended with another call to
    SetSlowStarting(). Should be called when static initialization completes,
    and the variable initialization part begins

    @arg timeout  the timeout to pass to the SCM (in milliseconds)
  */
  void SetSlowStarting(unsigned long timeout);

  /*
    Stop() is to be called by the application to stop
    the service
  */
  void Stop(void);

  void SetExitEvent(void);

 protected:
  LPSTR ServiceName;
  HANDLE hExitEvent;
  SERVICE_STATUS_HANDLE hServiceStatusHandle;
  BOOL bPause;
  BOOL bRunning;
  HANDLE hThreadHandle;
  THREAD_FC fpServiceThread;

  void PauseService();
  void ResumeService();
  void StopService();
  BOOL StartService();

  static void ServiceMain(DWORD argc, LPTSTR *argv);
  static void ServiceCtrlHandler(DWORD ctrlCode);

  void Exit(DWORD error);
  BOOL SetStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode,
                 DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint,
                 DWORD dwWaitHint);
};
/* ------------------------- the end -------------------------------------- */

#endif /* NT_SERVC_INCLUDED */