MySQL 8.3.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/**
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, 2023, Oracle and/or its affiliates.
14 All rights reserved.
15*/
16
17#include <windows.h>
18
19// main application thread
20typedef void (*THREAD_FC)(void *);
21
22class NTService {
23 public:
26
27 // install optinos
28 DWORD dwDesiredAccess;
29 DWORD dwServiceType;
30 DWORD dwStartType;
31 DWORD dwErrorControl;
32
33 LPSTR szLoadOrderGroup;
34 LPDWORD lpdwTagID;
35 LPSTR szDependencies;
36
37 // time-out (in milisec)
38 int nStartTimeOut;
39 int nStopTimeOut;
40 int nPauseTimeOut;
42
43 //
44 DWORD my_argc;
45 LPTSTR *my_argv;
47 int nError;
48 DWORD dwState;
49
50 // init service entry point
51 long Init(LPCSTR szInternName, void *ServiceThread);
52
53 // application shutdown event
54 void SetShutdownEvent(HANDLE hEvent) { hShutdownEvent = hEvent; }
55
56 // service install / un-install
57 BOOL Install(int startType, LPCSTR szInternName, LPCSTR szDisplayName,
58 LPCSTR szFullPath, LPCSTR szAccountName = nullptr,
59 LPCSTR szPassword = nullptr);
60 BOOL SeekStatus(LPCSTR szInternName, int OperationType);
61 BOOL Remove(LPCSTR szInternName);
62 BOOL IsService(LPCSTR ServiceName);
63 BOOL got_service_option(char **argv, const char *service_option);
65
66 /*
67 SetRunning() is to be called by the application
68 when initialization completes and it can accept
69 stop request
70 */
71 void SetRunning(void);
72
73 /**
74 Sets a timeout after which SCM will abort service startup if SetRunning()
75 was not called or the timeout was not extended with another call to
76 SetSlowStarting(). Should be called when static initialization completes,
77 and the variable initialization part begins
78
79 @arg timeout the timeout to pass to the SCM (in milliseconds)
80 */
81 void SetSlowStarting(unsigned long timeout);
82
83 /*
84 Stop() is to be called by the application to stop
85 the service
86 */
87 void Stop(void);
88
89 void SetExitEvent(void);
90
91 protected:
92 LPSTR ServiceName;
94 SERVICE_STATUS_HANDLE hServiceStatusHandle;
95 BOOL bPause;
96 BOOL bRunning;
99
104
105 static void ServiceMain(DWORD argc, LPTSTR *argv);
106 static void ServiceCtrlHandler(DWORD ctrlCode);
107
108 void Exit(DWORD error);
109 BOOL SetStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode,
110 DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint,
111 DWORD dwWaitHint);
112};
113/* ------------------------- the end -------------------------------------- */
114
115#endif /* NT_SERVC_INCLUDED */
Definition: nt_servc.h:23
void SetExitEvent(void)
Definition: nt_servc.cc:184
long Init(LPCSTR szInternName, void *ServiceThread, void(*fpReqAppShutdownCb)()) noexcept
LPDWORD lpdwTagID
Definition: nt_servc.h:36
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
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 Install(int startType, LPCSTR szInternName, LPCSTR szDisplayName, LPCSTR szFullPath, LPCSTR szAccountName=nullptr, LPCSTR szPassword=nullptr)
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()
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)
int nResumeTimeOut
Definition: nt_servc.h:44
void SetShutdownEvent(HANDLE hEvent)
Definition: nt_servc.h:54
static void ServiceMain(DWORD argc, LPTSTR *argv)
DWORD dwStartType
Definition: nt_servc.h:32
BOOL SeekStatus(LPCSTR szInternName, int OperationType)
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:497
void(* THREAD_FC)(void *)
Definition: nt_servc.h:21
#define HANDLE
Definition: violite.h:158