MySQL  8.0.27
Source Code Documentation
nt_servc.h
Go to the documentation of this file.
1 #ifndef NT_SERVC_INCLUDED
2 #define NT_SERVC_INCLUDED
3 
4 /**
5  @file
6 
7  @brief
8  Windows NT Service class library
9 
10  Copyright Abandoned 1998 Irena Pancirov - Irnet Snc
11  This file is public domain and comes with NO WARRANTY of any kind
12 
13  Modifications Copyright (c) 2000, 2021, Oracle and/or its affiliates.
14  All rights reserved.
15 */
16 
17 #include <windows.h>
18 
19 // main application thread
20 typedef void (*THREAD_FC)(void *);
21 
22 class NTService {
23  public:
26 
27  BOOL bOsNT; ///< true if OS is NT, false for Win95
28  // install optinos
29  DWORD dwDesiredAccess;
30  DWORD dwServiceType;
31  DWORD dwStartType;
32  DWORD dwErrorControl;
33 
34  LPSTR szLoadOrderGroup;
35  LPDWORD lpdwTagID;
36  LPSTR szDependencies;
37  OSVERSIONINFO osVer;
38 
39  // time-out (in milisec)
40  int nStartTimeOut;
41  int nStopTimeOut;
42  int nPauseTimeOut;
43  int nResumeTimeOut;
44 
45  //
46  DWORD my_argc;
47  LPTSTR *my_argv;
49  int nError;
50  DWORD dwState;
51 
52  BOOL GetOS(); // returns TRUE if WinNT
53  BOOL IsNT() { return bOsNT; }
54  // init service entry point
55  long Init(LPCSTR szInternName, void *ServiceThread);
56 
57  // application shutdown event
58  void SetShutdownEvent(HANDLE hEvent) { hShutdownEvent = hEvent; }
59 
60  // service install / un-install
61  BOOL Install(int startType, LPCSTR szInternName, LPCSTR szDisplayName,
62  LPCSTR szFullPath, LPCSTR szAccountName = NULL,
63  LPCSTR szPassword = NULL);
64  BOOL SeekStatus(LPCSTR szInternName, int OperationType);
65  BOOL Remove(LPCSTR szInternName);
66  BOOL IsService(LPCSTR ServiceName);
67  BOOL got_service_option(char **argv, const char *service_option);
68  BOOL is_super_user();
69 
70  /*
71  SetRunning() is to be called by the application
72  when initialization completes and it can accept
73  stop request
74  */
75  void SetRunning(void);
76 
77  /**
78  Sets a timeout after which SCM will abort service startup if SetRunning()
79  was not called or the timeout was not extended with another call to
80  SetSlowStarting(). Should be called when static initialization completes,
81  and the variable initialization part begins
82 
83  @arg timeout the timeout to pass to the SCM (in milliseconds)
84  */
85  void SetSlowStarting(unsigned long timeout);
86 
87  /*
88  Stop() is to be called by the application to stop
89  the service
90  */
91  void Stop(void);
92 
93  void SetExitEvent(void);
94 
95  protected:
96  LPSTR ServiceName;
98  SERVICE_STATUS_HANDLE hServiceStatusHandle;
99  BOOL bPause;
100  BOOL bRunning;
103 
104  void PauseService();
106  void StopService();
107  BOOL StartService();
108 
109  static void ServiceMain(DWORD argc, LPTSTR *argv);
110  static void ServiceCtrlHandler(DWORD ctrlCode);
111 
112  void Exit(DWORD error);
113  BOOL SetStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode,
114  DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint,
115  DWORD dwWaitHint);
116 };
117 /* ------------------------- the end -------------------------------------- */
118 
119 #endif /* NT_SERVC_INCLUDED */
Definition: nt_servc.h:23
void SetExitEvent(void)
Definition: nt_servc.cc:195
long Init(LPCSTR szInternName, void *ServiceThread, void(*fpReqAppShutdownCb)()) noexcept
Registers the main service thread with the service manager.
Definition: nt_servc.cc:81
LPDWORD lpdwTagID
Definition: nt_servc.h:36
OSVERSIONINFO osVer
Definition: nt_servc.h:38
BOOL is_super_user()
int nStartTimeOut
Definition: nt_servc.h:41
BOOL Remove(LPCSTR szInternName)
THREAD_FC fpServiceThread
Definition: nt_servc.h:104
HANDLE hExitEvent
Definition: nt_servc.h:99
void Exit(DWORD error)
int nStopTimeOut
Definition: nt_servc.h:42
DWORD dwServiceType
Definition: nt_servc.h:31
BOOL GetOS()
LPTSTR * my_argv
Definition: nt_servc.h:48
BOOL StartService()
void Stop(void)
void SetSlowStarting(unsigned long timeout)
Sets a timeout after which SCM will abort service startup if SetRunning() was not called or the timeo...
void StopService()
void ResumeService()
BOOL bOsNT
true if OS is NT, false for Win95
Definition: nt_servc.h:28
DWORD dwErrorControl
Definition: nt_servc.h:33
HANDLE hShutdownEvent
Definition: nt_servc.h:49
BOOL bRunning
Definition: nt_servc.h:102
SERVICE_STATUS_HANDLE hServiceStatusHandle
Definition: nt_servc.h:100
int nError
Definition: nt_servc.h:50
LPSTR szLoadOrderGroup
Definition: nt_servc.h:35
DWORD my_argc
Definition: nt_servc.h:47
BOOL IsService(LPCSTR ServiceName)
void PauseService()
BOOL Install(int startType, LPCSTR szInternName, LPCSTR szDisplayName, LPCSTR szFullPath, LPCSTR szAccountName=NULL, LPCSTR szPassword=NULL)
static void ServiceCtrlHandler(DWORD ctrlCode)
LPSTR szDependencies
Definition: nt_servc.h:37
LPSTR ServiceName
Definition: nt_servc.h:98
HANDLE hThreadHandle
Definition: nt_servc.h:103
BOOL SetStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint)
DWORD dwDesiredAccess
Definition: nt_servc.h:30
void SetRunning(void)
DWORD dwState
Definition: nt_servc.h:51
BOOL bPause
Definition: nt_servc.h:101
int nPauseTimeOut
Definition: nt_servc.h:43
BOOL got_service_option(char **argv, char *service_option)
Definition: nt_servc.cc:464
int nResumeTimeOut
Definition: nt_servc.h:44
BOOL IsNT()
Definition: nt_servc.h:53
void SetShutdownEvent(HANDLE hEvent)
Definition: nt_servc.h:58
static void ServiceMain(DWORD argc, LPTSTR *argv)
DWORD dwStartType
Definition: nt_servc.h:32
BOOL SeekStatus(LPCSTR szInternName, int OperationType)
char * argv[]
Definition: do_ctype.cc:45
get_options & argc
Definition: do_ctype.cc:51
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:494
void(* THREAD_FC)(void *)
Definition: nt_servc.h:21
#define NULL
Definition: types.h:54
#define HANDLE
Definition: violite.h:158