MySQL  8.0.27
Source Code Documentation
NTService Class Reference

#include <nt_servc.h>

Public Member Functions

 NTService ()
 
 ~NTService ()
 
BOOL GetOS () noexcept
 
BOOL IsNT ()
 
long Init (LPCSTR szInternName, void *ServiceThread, void(*fpReqAppShutdownCb)()) noexcept
 Registers the main service thread with the service manager. More...
 
void SetShutdownEvent (HANDLE hEvent) noexcept
 
BOOL Install (int startType, LPCSTR szInternName, LPCSTR szDisplayName, LPCSTR szFullPath, LPCSTR szAccountName=NULL, LPCSTR szPassword=NULL) noexcept
 Installs the service with Service manager. More...
 
BOOL SeekStatus (LPCSTR szInternName, int OperationType)
 
BOOL Remove (LPCSTR szInternName)
 Removes the service. More...
 
BOOL is_super_user ()
 
BOOL got_service_option (char **argv, char *service_option)
 
void SetRunning (void)
 
void SetSlowStarting (unsigned long timeout)
 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(). More...
 
void Stop (void)
 this function should be called before the app. More...
 
 NTService ()
 
 ~NTService ()
 
BOOL GetOS ()
 
BOOL IsNT ()
 
long Init (LPCSTR szInternName, void *ServiceThread)
 Registers the main service thread with the service manager. More...
 
void SetShutdownEvent (HANDLE hEvent)
 
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 ()
 
void SetRunning (void)
 
void SetSlowStarting (unsigned long timeout)
 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(). More...
 
void Stop (void)
 
void SetExitEvent (void)
 

Static Public Member Functions

static BOOL IsService (LPCSTR ServiceName) noexcept
 Checks if service named service_name exists. More...
 

Public Attributes

BOOL bOsNT
 true if OS is NT, false for Win95 More...
 
DWORD dwDesiredAccess
 
DWORD dwServiceType
 
DWORD dwStartType
 
DWORD dwErrorControl
 
LPSTR szLoadOrderGroup
 
LPDWORD lpdwTagID
 
LPSTR szDependencies
 
OSVERSIONINFO osVer
 
int nStartTimeOut
 
int nStopTimeOut
 
int nPauseTimeOut
 
int nResumeTimeOut
 
DWORD my_argc
 
LPTSTR * my_argv
 
HANDLE hShutdownEvent
 
int nError
 
DWORD dwState
 

Protected Member Functions

void PauseService ()
 
void ResumeService ()
 
void StopService ()
 
BOOL StartService ()
 
void Exit (DWORD error)
 
BOOL SetStatus (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint)
 
void PauseService ()
 
void ResumeService ()
 
void StopService ()
 
BOOL StartService ()
 
void Exit (DWORD error)
 
BOOL SetStatus (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint)
 

Static Protected Member Functions

static void ServiceMain (DWORD argc, LPTSTR *argv)
 This is the function that is called from the service manager to start the service. More...
 
static void ServiceCtrlHandler (DWORD ctrlCode)
 
static void ServiceMain (DWORD argc, LPTSTR *argv)
 
static void ServiceCtrlHandler (DWORD ctrlCode)
 

Protected Attributes

LPSTR ServiceName
 
HANDLE hExitEvent
 
SERVICE_STATUS_HANDLE hServiceStatusHandle
 
BOOL bPause
 
BOOL bRunning
 
HANDLE hThreadHandle
 
THREAD_FC fpServiceThread
 
void(* fpRequestApplicationShutdownCallback )() = nullptr
 

Constructor & Destructor Documentation

◆ NTService() [1/2]

NTService::NTService ( )

◆ ~NTService() [1/2]

NTService::~NTService ( )

◆ NTService() [2/2]

NTService::NTService ( )

◆ ~NTService() [2/2]

NTService::~NTService ( )

Member Function Documentation

◆ Exit() [1/2]

void NTService::Exit ( DWORD  error)
protected

◆ Exit() [2/2]

void NTService::Exit ( DWORD  error)
protected

◆ GetOS() [1/2]

BOOL NTService::GetOS ( )

◆ GetOS() [2/2]

BOOL NTService::GetOS ( )
noexcept

◆ got_service_option() [1/2]

BOOL NTService::got_service_option ( char **  argv,
char *  service_option 
)

◆ got_service_option() [2/2]

BOOL NTService::got_service_option ( char **  argv,
const char *  service_option 
)

◆ Init() [1/2]

long NTService::Init ( LPCSTR  szInternName,
void *  ServiceThread 
)

Registers the main service thread with the service manager.

Parameters
szInternNameName of service to run in this process.
ServiceThreadpointer to the main programs entry function when the service is started

◆ Init() [2/2]

long NTService::Init ( LPCSTR  szInternName,
void *  ServiceThread,
void(*)()  fpReqAppShutdownCb 
)
noexcept

Registers the main service thread with the service manager.

Parameters
szInternNameName of service to run in this process.
ServiceThreadpointer to the main programs entry function when the service is started
fpReqAppShutdownCbpointer to callback function to call after receiving shutdown signal from Service Controller

◆ Install() [1/2]

BOOL NTService::Install ( int  startType,
LPCSTR  szInternName,
LPCSTR  szDisplayName,
LPCSTR  szFullPath,
LPCSTR  szAccountName = NULL,
LPCSTR  szPassword = NULL 
)

◆ Install() [2/2]

BOOL NTService::Install ( int  startType,
LPCSTR  szInternName,
LPCSTR  szDisplayName,
LPCSTR  szFullPath,
LPCSTR  szAccountName = NULL,
LPCSTR  szPassword = NULL 
)
noexcept

Installs the service with Service manager.

nError values:

  • 0 success
  • 1 Can't open the Service manager
  • 2 Failed to create service.

◆ is_super_user() [1/2]

BOOL NTService::is_super_user ( )

◆ is_super_user() [2/2]

BOOL NTService::is_super_user ( )

◆ IsNT() [1/2]

BOOL NTService::IsNT ( )
inline

◆ IsNT() [2/2]

BOOL NTService::IsNT ( )
inline

◆ IsService() [1/2]

BOOL NTService::IsService ( LPCSTR  ServiceName)

◆ IsService() [2/2]

BOOL NTService::IsService ( LPCSTR  service_name)
staticnoexcept

Checks if service named service_name exists.

Parameters
service_nameName of the service
Returns
true if service exists, false otherwise
Note
It could also return false if opening Service Control Manager failed for some reason.

◆ PauseService() [1/2]

void NTService::PauseService ( )
protected

◆ PauseService() [2/2]

void NTService::PauseService ( )
protected

◆ Remove() [1/2]

BOOL NTService::Remove ( LPCSTR  szInternName)

Removes the service.

nError values:

  • 0 success
  • 1 Can't open the Service manager
  • 2 Failed to locate service
  • 3 Failed to delete service.

◆ Remove() [2/2]

BOOL NTService::Remove ( LPCSTR  szInternName)

◆ ResumeService() [1/2]

void NTService::ResumeService ( )
protected

◆ ResumeService() [2/2]

void NTService::ResumeService ( )
protected

◆ SeekStatus() [1/2]

BOOL NTService::SeekStatus ( LPCSTR  szInternName,
int  OperationType 
)

◆ SeekStatus() [2/2]

BOOL NTService::SeekStatus ( LPCSTR  szInternName,
int  OperationType 
)

◆ ServiceCtrlHandler() [1/2]

void NTService::ServiceCtrlHandler ( DWORD  ctrlCode)
staticprotected

◆ ServiceCtrlHandler() [2/2]

static void NTService::ServiceCtrlHandler ( DWORD  ctrlCode)
staticprotected

◆ ServiceMain() [1/2]

void NTService::ServiceMain ( DWORD  argc,
LPTSTR *  argv 
)
staticprotected

This is the function that is called from the service manager to start the service.

◆ ServiceMain() [2/2]

static void NTService::ServiceMain ( DWORD  argc,
LPTSTR *  argv 
)
staticprotected

◆ SetExitEvent()

void NTService::SetExitEvent ( void  )

◆ SetRunning() [1/2]

void NTService::SetRunning ( void  )

◆ SetRunning() [2/2]

void NTService::SetRunning ( void  )

◆ SetShutdownEvent() [1/2]

void NTService::SetShutdownEvent ( HANDLE  hEvent)
inline

◆ SetShutdownEvent() [2/2]

void NTService::SetShutdownEvent ( HANDLE  hEvent)
inlinenoexcept

◆ SetSlowStarting() [1/2]

void NTService::SetSlowStarting ( unsigned long  timeout)

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

  • timeout the timeout to pass to the SCM (in milliseconds)

◆ SetSlowStarting() [2/2]

void NTService::SetSlowStarting ( unsigned long  timeout)

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

  • timeout the timeout to pass to the SCM (in milliseconds)

◆ SetStatus() [1/2]

BOOL NTService::SetStatus ( DWORD  dwCurrentState,
DWORD  dwWin32ExitCode,
DWORD  dwServiceSpecificExitCode,
DWORD  dwCheckPoint,
DWORD  dwWaitHint 
)
protected

◆ SetStatus() [2/2]

BOOL NTService::SetStatus ( DWORD  dwCurrentState,
DWORD  dwWin32ExitCode,
DWORD  dwServiceSpecificExitCode,
DWORD  dwCheckPoint,
DWORD  dwWaitHint 
)
protected

◆ StartService() [1/2]

BOOL NTService::StartService ( )
protected

◆ StartService() [2/2]

BOOL NTService::StartService ( )
protected

◆ Stop() [1/2]

void NTService::Stop ( void  )

this function should be called before the app.

exits to stop the service

◆ Stop() [2/2]

void NTService::Stop ( void  )

◆ StopService() [1/2]

void NTService::StopService ( )
protected

◆ StopService() [2/2]

void NTService::StopService ( )
protected

Member Data Documentation

◆ bOsNT

BOOL NTService::bOsNT

true if OS is NT, false for Win95

◆ bPause

BOOL NTService::bPause
protected

◆ bRunning

BOOL NTService::bRunning
protected

◆ dwDesiredAccess

DWORD NTService::dwDesiredAccess

◆ dwErrorControl

DWORD NTService::dwErrorControl

◆ dwServiceType

DWORD NTService::dwServiceType

◆ dwStartType

DWORD NTService::dwStartType

◆ dwState

DWORD NTService::dwState

◆ fpRequestApplicationShutdownCallback

void(* NTService::fpRequestApplicationShutdownCallback) () = nullptr
protected

◆ fpServiceThread

THREAD_FC NTService::fpServiceThread
protected

◆ hExitEvent

HANDLE NTService::hExitEvent
protected

◆ hServiceStatusHandle

SERVICE_STATUS_HANDLE NTService::hServiceStatusHandle
protected

◆ hShutdownEvent

HANDLE NTService::hShutdownEvent

◆ hThreadHandle

HANDLE NTService::hThreadHandle
protected

◆ lpdwTagID

LPDWORD NTService::lpdwTagID

◆ my_argc

DWORD NTService::my_argc

◆ my_argv

LPTSTR * NTService::my_argv

◆ nError

int NTService::nError

◆ nPauseTimeOut

int NTService::nPauseTimeOut

◆ nResumeTimeOut

int NTService::nResumeTimeOut

◆ nStartTimeOut

int NTService::nStartTimeOut

◆ nStopTimeOut

int NTService::nStopTimeOut

◆ osVer

OSVERSIONINFO NTService::osVer

◆ ServiceName

LPSTR NTService::ServiceName
protected

◆ szDependencies

LPSTR NTService::szDependencies

◆ szLoadOrderGroup

LPSTR NTService::szLoadOrderGroup

The documentation for this class was generated from the following files: