The Micro C++ Library
|
A Service is a background task, that usually does not require any user interaction. More...
#include <micxx.hxx>
Inherits micxx::traits::NonCopyable.
Public Member Functions | |
Service (const std::wstring &serviceName=L"undefined") | |
Creates a Service. | |
virtual | ~Service (void) |
virtual void | addDependency (const std::wstring &dependency) |
Adds dependency to the dependencies of this service. | |
virtual void | clear () |
Clears the service properties. | |
virtual bool | getAutoStart () const |
Returns the value of the autoStart flag of this service. | |
virtual const std::wstring & | getCommandLine () const |
Returns the command line of this service. | |
virtual DWORD | getControlsAccepted () const |
Returns the accepted controls of this service. | |
virtual const std::set < std::wstring > & | getDependencies () const |
Returns the dependencies of this service. | |
virtual const std::wstring & | getDescription () const |
Returns the description of this service. | |
virtual bool | getDisabled () const |
Returns the value of the disbaled flag of this service. | |
virtual const std::wstring & | getDisplayName () const |
Returns the displayName of this service. | |
virtual bool | getInteractive () const |
Returns the value of the interactive flag of this service. | |
virtual const std::wstring & | getPassword () const |
Returns the password of this service. | |
virtual const std::wstring & | getPath () const |
Returns the path of this service. | |
virtual const std::wstring & | getServiceName () const |
Returns the name of this service. | |
virtual const std::wstring & | getUser () const |
Returns the associated user account for this service. | |
virtual void | install () |
Installs this Service. | |
void | main () |
Enter into the service mode. | |
virtual void | run (std::list< std::wstring > &wargs)=0 |
The service's run method. | |
virtual void | setAutoStart (bool autoStart) |
Sets the value of the autoStart flag of this service. | |
virtual void | setCommandLine (const std::wstring &commandLine) |
Sets the command line of this service. | |
virtual void | setControlsAccepted (DWORD controlsAccepted) |
Sets the accepted controls of this service. | |
virtual void | setDescription (const std::wstring &description) |
Sets the description of this service. | |
virtual void | setDisabled (bool disabled) |
Sets the value of the disbaled flag of this service. | |
virtual void | setDisplayName (const std::wstring &displayName) |
Sets the displayName of this service. | |
virtual void | setInteractive (bool interactive) |
Sets the value of the interactive flag of this service. | |
virtual void | setPassword (const std::wstring &path) |
Sets the service path. | |
virtual void | setPath (const std::wstring &path) |
Sets the service path. | |
virtual void | setServiceName (const std::wstring &serviceName) |
Sets the service name. | |
virtual void | setUser (const std::wstring &user) |
Sets the service associated user account. | |
virtual bool | start () |
Starts this Service. | |
virtual bool | stop () |
Stops this Service. | |
virtual void | uninstall () |
Uninstalls this Service. | |
Protected Member Functions | |
virtual void | run (SERVICE_STATUS_HANDLE hServiceStatus, DWORD argc, LPWSTR *wargs) |
The service's run method. | |
virtual DWORD | serviceCtrlHandler (DWORD control, DWORD eventType, LPVOID eventData) |
This is the instance specific function that is called by the class specific serviceCtrlHandlerEx(DWORD, DWORD, LPVOID, LPVOID). | |
virtual void | serviceStop () |
A stop request has been received and should be handled. |
A Service is a background task, that usually does not require any user interaction.
A service application conforms to the interface rules of the Service Control Manager (SCM). It can be started automatically at system boot, by a user through the Services control panel applet, or by an application that uses the service functions. Services can execute even when no user is logged on to the system.
A Service is installed once. After installation a Service could be started, stopped or paused and resumed and finally it could be uninstalled. Depending on the current state, a Service could also be started automatically at boot-time.
micxx::Service::Service | ( | const std::wstring & | serviceName = L"undefined" | ) |
Creates a Service.
virtual micxx::Service::~Service | ( | void | ) | [virtual] |
virtual void micxx::Service::addDependency | ( | const std::wstring & | dependency | ) | [virtual] |
Adds dependency to the dependencies of this service.
virtual void micxx::Service::clear | ( | ) | [virtual] |
Clears the service properties.
virtual bool micxx::Service::getAutoStart | ( | ) | const [virtual] |
Returns the value of the autoStart flag of this service.
virtual const std::wstring& micxx::Service::getCommandLine | ( | ) | const [virtual] |
Returns the command line of this service.
virtual DWORD micxx::Service::getControlsAccepted | ( | ) | const [virtual] |
Returns the accepted controls of this service.
virtual const std::set<std::wstring>& micxx::Service::getDependencies | ( | ) | const [virtual] |
Returns the dependencies of this service.
virtual const std::wstring& micxx::Service::getDescription | ( | ) | const [virtual] |
Returns the description of this service.
virtual bool micxx::Service::getDisabled | ( | ) | const [virtual] |
Returns the value of the disbaled flag of this service.
virtual const std::wstring& micxx::Service::getDisplayName | ( | ) | const [virtual] |
Returns the displayName of this service.
virtual bool micxx::Service::getInteractive | ( | ) | const [virtual] |
Returns the value of the interactive flag of this service.
virtual const std::wstring& micxx::Service::getPassword | ( | ) | const [virtual] |
Returns the password of this service.
virtual const std::wstring& micxx::Service::getPath | ( | ) | const [virtual] |
Returns the path of this service.
virtual const std::wstring& micxx::Service::getServiceName | ( | ) | const [virtual] |
Returns the name of this service.
virtual const std::wstring& micxx::Service::getUser | ( | ) | const [virtual] |
Returns the associated user account for this service.
The name of the account under which the service should run. Use an account name in the form DomainName\UserName. The service process will be logged on as this user. If the account belongs to the built-in domain, you can specify .\UserName. If this parameter is 0
, the LocalSystem account is used. If interactive is true
, the service must run in the LocalSystem account. If this parameter is NT AUTHORITY\LocalService, the LocalService account is used. If the parameter is NT AUTHORITY\NetworkService, the NetworkService account is used.
virtual void micxx::Service::install | ( | ) | [virtual] |
Installs this Service.
void micxx::Service::main | ( | ) |
Enter into the service mode.
This method should be called in the main function of the service executable to enter the service loop. This method won't return until the service is stopped.
virtual void micxx::Service::run | ( | SERVICE_STATUS_HANDLE | hServiceStatus, |
DWORD | argc, | ||
LPWSTR * | wargs | ||
) | [protected, virtual] |
The service's run method.
This method is called from Service::serviceMain(DWORD, LPWSTR) after this service instance has been successfully started by the Service Control Mananger (SCM) and after RegisterServiceCtrlHandlerEx has been successfully called and returned a valid SERVICE_STATUS_HANDLE.
virtual void micxx::Service::run | ( | std::list< std::wstring > & | wargs | ) | [pure virtual] |
The service's run method.
This method is called from run(SERVICE_STATUS_HANDLE, DWORD, LPWSTR). A derived service class should override this method to implement the service.
virtual DWORD micxx::Service::serviceCtrlHandler | ( | DWORD | control, |
DWORD | eventType, | ||
LPVOID | eventData | ||
) | [protected, virtual] |
This is the instance specific function that is called by the class specific serviceCtrlHandlerEx(DWORD, DWORD, LPVOID, LPVOID).
control | The control code. This parameter can be one of the following values:
|
eventType | The type of event that has occurred. If control is SERVICE_CONTROL_DEVICEEVENT , this paramater can have the following values:
|
eventData | Additional device information, if required. The format of this data depends on the value of the control and eventType parameters. If eventType is SERVICE_CONTROL_DEVICEEVENT , this data corresponds to the lParam parameter that applications receive as part of a WM_DEVICECHANGE message. If eventType is SERVICE_CONTROL_POWEREVENT , this data is a pointer to a POWERBROADCAST_SETTING structure. If eventType is SERVICE_CONTROL_SESSIONCHANGE , this parameter is a pointer to a WTSSESSION_NOTIFICATION structure. |
ERROR_CALL_NOT_IMPLEMENTED
. However, your service should return NO_ERROR
for the following events even if your service does not handle them: SERVICE_CONTROL_INTERROGATE
.SERVICE_CONTROL_DEVICEEVENT
, SERVICE_CONTROL_HARDWAREPROFILECHANGE
or SERVICE_CONTROL_POWEREVENT
, return NO_ERROR
to grant the request and an error code to deny the request. For all other control codes your service handles, return NO_ERROR. virtual void micxx::Service::serviceStop | ( | ) | [protected, virtual] |
A stop request has been received and should be handled.
virtual void micxx::Service::setAutoStart | ( | bool | autoStart | ) | [virtual] |
Sets the value of the autoStart flag of this service.
virtual void micxx::Service::setCommandLine | ( | const std::wstring & | commandLine | ) | [virtual] |
Sets the command line of this service.
virtual void micxx::Service::setControlsAccepted | ( | DWORD | controlsAccepted | ) | [virtual] |
Sets the accepted controls of this service.
virtual void micxx::Service::setDescription | ( | const std::wstring & | description | ) | [virtual] |
Sets the description of this service.
virtual void micxx::Service::setDisabled | ( | bool | disabled | ) | [virtual] |
Sets the value of the disbaled flag of this service.
virtual void micxx::Service::setDisplayName | ( | const std::wstring & | displayName | ) | [virtual] |
Sets the displayName of this service.
virtual void micxx::Service::setInteractive | ( | bool | interactive | ) | [virtual] |
Sets the value of the interactive flag of this service.
virtual void micxx::Service::setPassword | ( | const std::wstring & | path | ) | [virtual] |
Sets the service path.
virtual void micxx::Service::setPath | ( | const std::wstring & | path | ) | [virtual] |
Sets the service path.
virtual void micxx::Service::setServiceName | ( | const std::wstring & | serviceName | ) | [virtual] |
Sets the service name.
virtual void micxx::Service::setUser | ( | const std::wstring & | user | ) | [virtual] |
Sets the service associated user account.
virtual bool micxx::Service::start | ( | ) | [virtual] |
Starts this Service.
true
, if the service has been started successfully, or false
, if the service was already running. virtual bool micxx::Service::stop | ( | ) | [virtual] |
Stops this Service.
true
, if the service has been stopped successfully, or false
, if the service was already stopped. virtual void micxx::Service::uninstall | ( | ) | [virtual] |
Uninstalls this Service.