The Micro C++ Library
micxx::Service Class Reference

A Service is a background task, that usually does not require any user interaction. More...

#include <micxx.hxx>

Inherits micxx::traits::NonCopyable.

List of all members.

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::wstringgetCommandLine () 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::wstringgetDescription () const
 Returns the description of this service.
virtual bool getDisabled () const
 Returns the value of the disbaled flag of this service.
virtual const std::wstringgetDisplayName () const
 Returns the displayName of this service.
virtual bool getInteractive () const
 Returns the value of the interactive flag of this service.
virtual const std::wstringgetPassword () const
 Returns the password of this service.
virtual const std::wstringgetPath () const
 Returns the path of this service.
virtual const std::wstringgetServiceName () const
 Returns the name of this service.
virtual const std::wstringgetUser () 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.

Detailed Description

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.


Constructor & Destructor Documentation

micxx::Service::Service ( const std::wstring serviceName = L"undefined")

Creates a Service.

virtual micxx::Service::~Service ( void  ) [virtual]

Member Function Documentation

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).

Parameters:
controlThe control code. This parameter can be one of the following values:
  • SERVICE_CONTROL_CONTINUE
  • SERVICE_CONTROL_INTERROGATE
  • SERVICE_CONTROL_NETBINDADD
  • SERVICE_CONTROL_NETBINDDISABLE
  • SERVICE_CONTROL_NETBINDENABLE
  • SERVICE_CONTROL_NETBINDREMOVE
  • SERVICE_CONTROL_PARAMCHANGE
  • SERVICE_CONTROL_PAUSE
  • SERVICE_CONTROL_PRESHUTDOWN
  • SERVICE_CONTROL_SHUTDOWN
  • SERVICE_CONTROL_STOP
  • SERVICE_CONTROL_DEVICEEVENT
  • SERVICE_CONTROL_HARDWAREPROFILECHANGE
  • SERVICE_CONTROL_POWEREVENT
  • SERVICE_CONTROL_SESSIONCHANGE
eventTypeThe type of event that has occurred. If control is SERVICE_CONTROL_DEVICEEVENT, this paramater can have the following values:
  • DBT_DEVICEARRIVAL
  • DBT_DEVICEREMOVECOMPLETE
  • DBT_DEVICEQUERYREMOVE
  • DBT_DEVICEQUERYREMOVEFAILED
  • DBT_DEVICEREMOVEPENDING
  • DBT_CUSTOMEVENT If control is SERVICE_CONTROL_HARDWAREPROFILECHANGE, this parameter can have the following values:
  • DBT_CONFIGCHANGED
  • DBT_QUERYCHANGECONFIG
  • DBT_CONFIGCHANGECANCELED If control is SERVICE_CONTROL_POWEREVENT, this parameter can have the following values:
  • PBT_POWERSETTINGCHANGE If control is SERVICE_CONTROL_SESSIONCHANGE, this parameter can be one of the values specified in the wParam parameter of the WM_WTSSESSION_CHANGE message.
eventDataAdditional 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.
Returns:
The following list identifies the rules for this return value:
  • In general, if your service does not handle the control, return 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.
  • If your service handles 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.

Returns:
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.

Returns:
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.


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