FreeRDP-WebConnect WebSockets gateway  1.0.0.167
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
wsgate::NTService Class Reference

A class for implementing a Windows service. More...

#include <NTService.hpp>

List of all members.

Public Types

enum  { SERVICE_CONTROL_USER = 128 }

Public Member Functions

 NTService (const std::string &displayName, const std::string &serviceName="")
 Constructor.
bool IsServiceInstalled () const
 Retrieve installation status.
void Start () const
 Starts the service.
void Stop () const
 Stops the service.
void InstallService () const
 Installs the service.
void UninstallService () const
 Uninstalls the service.
bool Execute () const
 Attempts to start the service control dispatcher.
uint32_t ServiceExitCode () const
 Retrieves the exit code of the service.

Protected Member Functions

virtual bool OnServiceInit (uint32_t argc, char **argv)
 Perform initialization using the service arguments.
virtual void RunService ()
 Runs the service main loop.
virtual bool OnServiceStop ()
 Notifies the service to be stopped.
virtual bool OnServiceInterrogate ()
 Notifies the service to be queried.
virtual bool OnServicePause ()
 Notifies the service to be paused.
virtual bool OnServiceContinue ()
 Notifies the service to resume.
virtual bool OnServiceShutdown ()
 Notifies the service about a system shutdown.
virtual bool OnServiceParamChange ()
 Notifies the service about a parameter change.
virtual bool OnServiceDeviceEvent ()
 Notifies the service about a device event.
virtual bool OnServiceHardwareProfileChange ()
 Notifies the service about a changed hardware profile.
virtual bool OnServicePowerEvent ()
 Notifies the service about a power management event.
virtual bool OnServiceSessionChange ()
 Notifies the service about a session change.
virtual bool OnServiceUserControl (uint32_t opcode)
 Notifies the service about a user-defined control message.
std::string StatusString (uint32_t state)
 Converts a service state to a human readable string.
std::string CtrlString (uint32_t ctrl)
 Converts a control code to a human readable string.
void AddDependency (const std::string &s)
 Adds a dependency to the list of prerequisites for this service.
void SetServiceStatus (uint32_t state)
 Changes and reports the service status to the service control manager.
void ReportServiceStatus ()
 Reports the current service status to the service control manager.

Protected Attributes

bool m_bServiceRunning
 Flag: service is running.
uint32_t m_dwServiceStartupType
 The startup type of this service.
SERVICE_STATUS m_ServiceStatus
 The startupt type of this service.
std::string m_sServiceName
 The internal service name.
std::string m_sDisplayName
 The display name.
std::string m_sDescription
 An optional description.
std::string m_sModulePath
 Internal path to our executable.

Detailed Description

A class for implementing a Windows service.

Internally, this class is a singleton, so you can only have one instance in a program. In convert a program into a service, its main() function should be renamed an then being invoked from your derived class Execute() method.

Definition at line 37 of file NTService.hpp.


Constructor & Destructor Documentation

wsgate::NTService::NTService ( const std::string &  displayName,
const std::string &  serviceName = "" 
)

Constructor.

Parameters:
displayNameMandatory display name of the service
serviceNameOptional internal service name

Member Function Documentation

void wsgate::NTService::AddDependency ( const std::string &  s)
protected

Adds a dependency to the list of prerequisites for this service.

Parameters:
sThe name of another service on which this service depends.
std::string wsgate::NTService::CtrlString ( uint32_t  ctrl)
protected

Converts a control code to a human readable string.

Parameters:
ctrlThe control code to convert.
Returns:
The string representation of the provided control code.
bool wsgate::NTService::Execute ( ) const

Attempts to start the service control dispatcher.

Returns:
true, if the dispatcher was successfully started.
Exceptions:
Aninstance of tracing::runtime_error, if the service manager can not be contacted.
void wsgate::NTService::InstallService ( ) const

Installs the service.

Exceptions:
Aninstance of tracing::runtime_error, if the service manager can not be contacted or the service can not be installed.
bool wsgate::NTService::IsServiceInstalled ( ) const

Retrieve installation status.

Returns:
true, if the service is installed.
Exceptions:
Aninstance of tracing::runtime_error, if the service manager can not be contacted.
virtual bool wsgate::NTService::OnServiceContinue ( )
protectedvirtual

Notifies the service to resume.

To be overridden by your derived class. The default implementation just returns true.

Returns:
true on success.
virtual bool wsgate::NTService::OnServiceDeviceEvent ( )
protectedvirtual

Notifies the service about a device event.

To be overridden by your derived class. The default implementation just returns true.

Returns:
true on success.
virtual bool wsgate::NTService::OnServiceHardwareProfileChange ( )
protectedvirtual

Notifies the service about a changed hardware profile.

To be overridden by your derived class. The default implementation just returns true.

Returns:
true on success.
virtual bool wsgate::NTService::OnServiceInit ( uint32_t  argc,
char **  argv 
)
protectedvirtual

Perform initialization using the service arguments.

To be overridden by your derived class. The default implementation just returns true.

Parameters:
argcThe number of arguments.
argvA NULL terminated array of string pointers.
Returns:
true on success.
virtual bool wsgate::NTService::OnServiceInterrogate ( )
protectedvirtual

Notifies the service to be queried.

To be overridden by your derived class. The default implementation just returns true.

Returns:
true on success.
virtual bool wsgate::NTService::OnServiceParamChange ( )
protectedvirtual

Notifies the service about a parameter change.

To be overridden by your derived class. The default implementation just returns true.

Returns:
true on success.
virtual bool wsgate::NTService::OnServicePause ( )
protectedvirtual

Notifies the service to be paused.

To be overridden by your derived class. The default implementation just returns true.

Returns:
true on success.
virtual bool wsgate::NTService::OnServicePowerEvent ( )
protectedvirtual

Notifies the service about a power management event.

To be overridden by your derived class. The default implementation just returns true.

Returns:
true on success.
virtual bool wsgate::NTService::OnServiceSessionChange ( )
protectedvirtual

Notifies the service about a session change.

To be overridden by your derived class. The default implementation just returns true.

Returns:
true on success.
virtual bool wsgate::NTService::OnServiceShutdown ( )
protectedvirtual

Notifies the service about a system shutdown.

To be overridden by your derived class. The default implementation just returns true.

Returns:
true on success.
virtual bool wsgate::NTService::OnServiceStop ( )
protectedvirtual

Notifies the service to be stopped.

To be overridden by your derived class. The default implementation just returns true.

Returns:
true on success.
virtual bool wsgate::NTService::OnServiceUserControl ( uint32_t  opcode)
protectedvirtual

Notifies the service about a user-defined control message.

To be overridden by your derived class. The default implementation just returns true.

Parameters:
opcodeThe user defined control code.
Returns:
true on success.
virtual void wsgate::NTService::RunService ( )
protectedvirtual

Runs the service main loop.

To be overridden by your derived class. The default implementation just loops until the service is stopped.

uint32_t wsgate::NTService::ServiceExitCode ( ) const

Retrieves the exit code of the service.

Returns:
The exit code of the service after stopping the service.
void wsgate::NTService::SetServiceStatus ( uint32_t  state)
protected

Changes and reports the service status to the service control manager.

Parameters:
stateThe new state of this service.
void wsgate::NTService::Start ( ) const

Starts the service.

Exceptions:
Aninstance of tracing::runtime_error, if the service manager can not be contacted or the service can not be started.
std::string wsgate::NTService::StatusString ( uint32_t  state)
protected

Converts a service state to a human readable string.

Parameters:
stateThe state to convert.
Returns:
The string representation of the provided state.
void wsgate::NTService::Stop ( ) const

Stops the service.

Exceptions:
Aninstance of tracing::runtime_error, if the service manager can not be contacted or the service can not be stopped.
void wsgate::NTService::UninstallService ( ) const

Uninstalls the service.

Exceptions:
Aninstance of tracing::runtime_error, if the service manager can not be contacted or the service can not be uninstalled.

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