Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- type HandlerFunction = HANDLE -> SERVICE_CONTROL -> IO Bool
- type ServiceMainFunction = String -> [String] -> HANDLE -> IO ()
- data SERVICE_ACCEPT
- data SERVICE_CONTROL
- data SERVICE_STATE
- data SERVICE_STATUS = SERVICE_STATUS {}
- data SERVICE_TYPE
- nO_ERROR :: ErrCode
- eRROR_SERVICE_SPECIFIC_ERROR :: ErrCode
- queryServiceStatus :: HANDLE -> IO SERVICE_STATUS
- setServiceStatus :: HANDLE -> SERVICE_STATUS -> IO ()
- startServiceCtrlDispatcher :: String -> DWORD -> HandlerFunction -> ServiceMainFunction -> IO ()
Documentation
type HandlerFunction = HANDLE -> SERVICE_CONTROL -> IO Bool Source
A handler function is registered with the service dispatcher thread
from a ServiceMainFunction
. The first argument is a HANDLE
returned
from calling registerServiceCtrlHandler
. The second argument represents
the command this service has been directed to perform.
type ServiceMainFunction = String -> [String] -> HANDLE -> IO () Source
The service dispatcher thread will call each function of this type that you provide. The first argument will be the name of the service. Any additional command-line parameters will appear in the second argument.
Each of these functions should call registerServiceCtrlHandler
to
register a function to handle incoming commands. It should then set
the service's status to START_PENDING
, and specify that no controls
will be accepted. At this point the function may perform any other
initialization steps before setting the service's status to
RUNNING
. All of this should take no more than 100ms.
data SERVICE_ACCEPT Source
The control codes the service accepts and processes in its handler
function (See HandlerFunction
). By default, all services accept the
INTERROGATE
value. To accept the DEVICEEVENT
value, the service must
register to receive device events by using the
registerDeviceNotification
function.
ACCEPT_NETBINDCHANGE | The service is a network component that can accept changes in its
binding without being stopped and restarted. This control code allows
the service to receive |
ACCEPT_PARAMCHANGE | The service can reread its startup parameters without being stopped
and restarted. This control code allows the service to receive
|
ACCEPT_PAUSE_CONTINUE | The service can be paused and continued. This control code allows the
service to receive |
ACCEPT_PRESHUTDOWN | MSDN documentation says that this function is not supported on Windows Server 2003 or Windows XP/2000. The support status on other versions is unknown to me. The service can perform preshutdown tasks. This control code enables
the service to receive |
ACCEPT_SHUTDOWN | The service is notified when system shutdown occurs. This control
code allows the service to receive |
ACCEPT_STOP | The service can be stopped. This control code allows the service to
receive |
data SERVICE_CONTROL Source
A SERVICE_CONTROL is used in Handler functions. All control codes are
defined here, but some can only be used with a HandlerEx
callback.
Use convertSuccess
to translate from a SERVICE_CONTROL
to a DWORD
.
Use convertAttempt
to translate from a DWORD
to a SERVICE_CONTROL
.
data SERVICE_STATE Source
The current state of a service.
data SERVICE_STATUS Source
Contains status information for a service.
SERVICE_STATUS | |
|
data SERVICE_TYPE Source
Win32 defines many types of services, but this binding only supports WIN32_OWN_PROCESS.
FILE_SYSTEM_DRIVER | The service is a file system driver. |
KERNEL_DRIVER | The service is a device driver. |
WIN32_OWN_PROCESS | The service runs in its own process. |
WIN32_SHARE_PROCESS | The service shares a process with other services. |
SERVICE_INTERACTIVE_PROCESS | Do no write your own services of this type. Windows Vista and above prevent service processes from directly interacting with users. A |
:: HANDLE | MSDN documentation: A handle to the service. This handle is returned by the OpenService or the CreateService function, and it must have the SERVICE_QUERY_STATUS access right. For more information, see Service Security and Access Rights. |
-> IO SERVICE_STATUS | This function will raise an exception if the Win32 call returned an error condition. |
Retrieves the current status of the specified service.
:: HANDLE | MSDN documentation: A handle to the status information structure for the current service. This handle is returned by the RegisterServiceCtrlHandlerEx function. |
-> SERVICE_STATUS | MSDN documentation: A pointer to the SERVICE_STATUS structure the contains the latest status information for the calling service. |
-> IO () | This function will raise an exception if the Win32 call returned an error condition. |
Updates the service control manager's status information for the calling service.
startServiceCtrlDispatcher Source
:: String | The name of the service. According to MSDN documentation this argument is unused in WIN32_OWN_PROCESS type services, which is the only type supported by this binding. Even so, it is recommended that the name of the service be used. MSDN description: The name of the service run by the calling thread. This is the service name that the service control program specified in the CreateService function when creating the service. |
-> DWORD |
|
-> HandlerFunction | |
-> ServiceMainFunction | This is a callback function that will be called by the operating system whenever the service is started. It should perform service initialization including the registration of a handler function. MSDN documentation gives conflicting advice as to whether this function should return before the service has entered the stopped state. In the official example the service main function blocks until the service is ready to stop. |
-> IO () | An exception will be raised if the underlying Win32 call returns an error condition. |
Register a callback function to initialize the service, which will be called by the operating system immediately. startServiceCtrlDispatcher will block until the provided callback function returns.
MSDN documentation: Connects the main thread of a service process to the service control manager, which causes the thread to be the service control dispatcher thread for the calling process.