MySQL 26.10.0
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#include <windows.h>
5
6#ifdef StartService
7#undef StartService
8#endif
9
10/**
11 @file
12
13 @brief
14 Windows NT Service class library
15
16 Copyright Abandoned 1998 Irena Pancirov - Irnet Snc
17 This file is public domain and comes with NO WARRANTY of any kind
18*/
19
20// main application thread
21typedef void (*THREAD_FC)(void *);
22
23class NTService {
24 public:
25 NTService();
26 ~NTService();
27
28 BOOL bOsNT; ///< true if OS is NT, false for Win95
29 // install optinos
34
36 LPDWORD lpdwTagID;
38 OSVERSIONINFO osVer;
39
40 // time-out (in milisec)
45
46 //
47 DWORD my_argc;
48 LPTSTR *my_argv;
50 int nError;
51 DWORD dwState;
52
53 BOOL GetOS() noexcept; // returns TRUE if WinNT
54 BOOL IsNT() { return bOsNT; }
55 // init service entry point
56 long Init(LPCSTR szInternName, void *ServiceThread,
57 void (*fpReqAppShutdownCb)()) noexcept;
58
59 // application shutdown event
61
62 // service install / un-install
63 BOOL Install(int startType, LPCSTR szInternName, LPCSTR szDisplayName,
64 LPCSTR szFullPath, LPCSTR szAccountName = nullptr,
65 LPCSTR szPassword = nullptr) noexcept;
66 BOOL SeekStatus(LPCSTR szInternName, int OperationType);
67 BOOL Remove(LPCSTR szInternName);
68 BOOL is_super_user();
69
70 // running
71 BOOL got_service_option(char **argv, char *service_option);
72 static BOOL IsService(LPCSTR ServiceName) noexcept;
73
74 /*
75 SetRunning() is to be called by the application
76 when initialization completes and it can accept
77 stop request
78 */
79 void SetRunning(void);
80
81 /**
82 Sets a timeout after which SCM will abort service startup if SetRunning()
83 was not called or the timeout was not extended with another call to
84 SetSlowStarting(). Should be called when static initialization completes,
85 and the variable initialization part begins
86
87 @arg timeout the timeout to pass to the SCM (in milliseconds)
88 */
89 void SetSlowStarting(unsigned long timeout);
90
91 /*
92 Stop() is to be called by the application to stop
93 the service
94 */
95 void Stop(void);
96
97 HANDLE exit_event() const { return hExitEvent; }
99
100 protected:
105 SERVICE_STATUS_HANDLE hServiceStatusHandle;
106 BOOL bPause;
111
112 void PauseService();
113 void ResumeService();
114 void StopService();
115 BOOL StartService();
116
117 static void ServiceMain(DWORD argc, LPTSTR *argv);
118 static void ServiceCtrlHandler(DWORD ctrlCode);
119
120 void Exit(DWORD error);
121 BOOL SetStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode,
122 DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint,
123 DWORD dwWaitHint);
124};
125/* ------------------------- the end -------------------------------------- */
126
127#endif /* NT_SERVC_INCLUDED */
Definition: nt_servc.h:23
long Init(LPCSTR szInternName, void *ServiceThread, void(*fpReqAppShutdownCb)()) noexcept
LPDWORD lpdwTagID
Definition: nt_servc.h:36
OSVERSIONINFO osVer
Definition: nt_servc.h:38
BOOL is_super_user()
Definition: nt_servc.cc:444
int nStartTimeOut
Definition: nt_servc.h:41
void(* fpRequestApplicationShutdownCallback)()
Definition: nt_servc.h:110
BOOL Remove(LPCSTR szInternName)
Removes the service.
Definition: nt_servc.cc:147
THREAD_FC fpServiceThread
Definition: nt_servc.h:109
HANDLE hExitEvent
Definition: nt_servc.h:102
void Exit(DWORD error)
Definition: nt_servc.cc:343
int nStopTimeOut
Definition: nt_servc.h:42
DWORD dwServiceType
Definition: nt_servc.h:31
NTService()
Definition: nt_servc.cc:26
LPTSTR * my_argv
Definition: nt_servc.h:48
BOOL Install(int startType, LPCSTR szInternName, LPCSTR szDisplayName, LPCSTR szFullPath, LPCSTR szAccountName=nullptr, LPCSTR szPassword=nullptr) noexcept
Installs the service with Service manager.
Definition: nt_servc.cc:97
void SetShutdownEvent(HANDLE hEvent) noexcept
Definition: nt_servc.h:60
BOOL StartService()
Definition: nt_servc.cc:245
void Stop(void)
this function should be called before the app.
Definition: nt_servc.cc:178
void SetSlowStarting(unsigned long timeout)
Sets a timeout after which SCM will abort service startup if SetRunning() was not called or the timeo...
Definition: nt_servc.cc:236
void StopService()
Definition: nt_servc.cc:256
~NTService()
Definition: nt_servc.cc:60
void ResumeService()
Definition: nt_servc.cc:271
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:107
SERVICE_STATUS_HANDLE hServiceStatusHandle
Definition: nt_servc.h:105
int nError
Definition: nt_servc.h:50
static void ServiceMain(DWORD argc, LPTSTR *argv)
This is the function that is called from the service manager to start the service.
Definition: nt_servc.cc:191
LPSTR szLoadOrderGroup
Definition: nt_servc.h:35
BOOL GetOS() noexcept
DWORD my_argc
Definition: nt_servc.h:47
void PauseService()
Definition: nt_servc.cc:264
LPSTR szDependencies
Definition: nt_servc.h:37
LPSTR ServiceName
Definition: nt_servc.h:101
HANDLE hThreadHandle
Definition: nt_servc.h:108
HANDLE exit_event() const
Definition: nt_servc.h:97
BOOL SetStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint)
Definition: nt_servc.cc:278
DWORD dwDesiredAccess
Definition: nt_servc.h:30
void SetRunning(void)
Definition: nt_servc.cc:232
DWORD dwState
Definition: nt_servc.h:51
BOOL bPause
Definition: nt_servc.h:106
int nPauseTimeOut
Definition: nt_servc.h:43
HANDLE tls_reload_event() const
Definition: nt_servc.h:98
HANDLE hTlsReloadThread
Definition: nt_servc.h:104
HANDLE hTlsReloadEvent
Definition: nt_servc.h:103
BOOL got_service_option(char **argv, char *service_option)
int nResumeTimeOut
Definition: nt_servc.h:44
BOOL IsNT()
Definition: nt_servc.h:54
static void ServiceCtrlHandler(DWORD ctrlCode)
Definition: nt_servc.cc:316
static BOOL IsService(LPCSTR ServiceName) noexcept
Definition: nt_servc.cc:421
DWORD dwStartType
Definition: nt_servc.h:32
BOOL SeekStatus(LPCSTR szInternName, int OperationType)
Definition: nt_servc.cc:357
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:499
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
void(* THREAD_FC)(void *)
Definition: nt_servc.h:21
#define HANDLE
Definition: violite.h:159