MySQL 9.0.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
60 void SetShutdownEvent(HANDLE hEvent) noexcept { hShutdownEvent = hEvent; }
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 protected:
100 SERVICE_STATUS_HANDLE hServiceStatusHandle;
101 BOOL bPause;
106
107 void PauseService();
108 void ResumeService();
109 void StopService();
110 BOOL StartService();
111
112 static void ServiceMain(DWORD argc, LPTSTR *argv);
113 static void ServiceCtrlHandler(DWORD ctrlCode);
114
115 void Exit(DWORD error);
116 BOOL SetStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode,
117 DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint,
118 DWORD dwWaitHint);
119};
120/* ------------------------- the end -------------------------------------- */
121
122#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:105
BOOL Remove(LPCSTR szInternName)
Removes the service.
Definition: nt_servc.cc:147
THREAD_FC fpServiceThread
Definition: nt_servc.h:104
HANDLE hExitEvent
Definition: nt_servc.h:99
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:102
SERVICE_STATUS_HANDLE hServiceStatusHandle
Definition: nt_servc.h:100
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:98
HANDLE hThreadHandle
Definition: nt_servc.h:103
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:101
int nPauseTimeOut
Definition: nt_servc.h:43
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:498
void(* THREAD_FC)(void *)
Definition: nt_servc.h:21
#define HANDLE
Definition: violite.h:159