mirror of
https://github.com/pocoproject/poco.git
synced 2025-07-04 01:27:11 +02:00
Windows specific: added registerServiceDeviceNotification() and handleDeviceEvent() to handle SERVICE_CONTROL_DEVICEEVENT events
This commit is contained in:
parent
e6b4c12ad2
commit
e1694c3e68
@ -168,6 +168,16 @@ protected:
|
|||||||
void defineOptions(OptionSet& options);
|
void defineOptions(OptionSet& options);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||||
|
static HDEVNOTIFY registerServiceDeviceNotification(LPVOID filter, DWORD flags);
|
||||||
|
/// Registers the ServerApplication to receive SERVICE_CONTROL_DEVICEEVENT
|
||||||
|
/// events.
|
||||||
|
|
||||||
|
virtual DWORD handleDeviceEvent(DWORD event_type, LPVOID event_data);
|
||||||
|
/// Handles the SERVICE_CONTROL_DEVICEEVENT event. The default
|
||||||
|
/// implementation does nothing and returns ERROR_CALL_NOT_IMPLEMENTED.
|
||||||
|
#endif // if defined(POCO_OS_FAMILY_WINDOWS)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if defined(POCO_VXWORKS)
|
#if defined(POCO_VXWORKS)
|
||||||
static Poco::Event _terminate;
|
static Poco::Event _terminate;
|
||||||
@ -188,7 +198,7 @@ private:
|
|||||||
SRV_UNREGISTER
|
SRV_UNREGISTER
|
||||||
};
|
};
|
||||||
static BOOL __stdcall ConsoleCtrlHandler(DWORD ctrlType);
|
static BOOL __stdcall ConsoleCtrlHandler(DWORD ctrlType);
|
||||||
static void __stdcall ServiceControlHandler(DWORD control);
|
static DWORD __stdcall ServiceControlHandler(DWORD control, DWORD event_type, LPVOID event_data, LPVOID context);
|
||||||
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
||||||
static void __stdcall ServiceMain(DWORD argc, LPWSTR* argv);
|
static void __stdcall ServiceMain(DWORD argc, LPWSTR* argv);
|
||||||
#else
|
#else
|
||||||
|
@ -132,8 +132,23 @@ BOOL ServerApplication::ConsoleCtrlHandler(DWORD ctrlType)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ServerApplication::ServiceControlHandler(DWORD control)
|
HDEVNOTIFY ServerApplication::registerServiceDeviceNotification(LPVOID filter, DWORD flags)
|
||||||
{
|
{
|
||||||
|
return RegisterDeviceNotification(_serviceStatusHandle, filter, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DWORD ServerApplication::handleDeviceEvent(DWORD /*event_type*/, LPVOID /*event_data*/)
|
||||||
|
{
|
||||||
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DWORD ServerApplication::ServiceControlHandler(DWORD control, DWORD event_type, LPVOID event_data, LPVOID context)
|
||||||
|
{
|
||||||
|
DWORD result = NO_ERROR;
|
||||||
|
auto instance = reinterpret_cast<ServerApplication*>(context);
|
||||||
|
|
||||||
switch (control)
|
switch (control)
|
||||||
{
|
{
|
||||||
case SERVICE_CONTROL_STOP:
|
case SERVICE_CONTROL_STOP:
|
||||||
@ -143,8 +158,15 @@ void ServerApplication::ServiceControlHandler(DWORD control)
|
|||||||
break;
|
break;
|
||||||
case SERVICE_CONTROL_INTERROGATE:
|
case SERVICE_CONTROL_INTERROGATE:
|
||||||
break;
|
break;
|
||||||
|
case SERVICE_CONTROL_DEVICEEVENT:
|
||||||
|
if (instance)
|
||||||
|
{
|
||||||
|
result = instance->handleDeviceEvent(event_type, event_data);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
SetServiceStatus(_serviceStatusHandle, &_serviceStatus);
|
SetServiceStatus(_serviceStatusHandle, &_serviceStatus);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -159,9 +181,9 @@ void ServerApplication::ServiceMain(DWORD argc, LPTSTR* argv)
|
|||||||
app.config().setBool("application.runAsService", true);
|
app.config().setBool("application.runAsService", true);
|
||||||
|
|
||||||
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
||||||
_serviceStatusHandle = RegisterServiceCtrlHandlerW(L"", ServiceControlHandler);
|
_serviceStatusHandle = RegisterServiceCtrlHandlerExW(L"", ServiceControlHandler, &app);
|
||||||
#else
|
#else
|
||||||
_serviceStatusHandle = RegisterServiceCtrlHandlerA("", ServiceControlHandler);
|
_serviceStatusHandle = RegisterServiceCtrlHandlerExA("", ServiceControlHandler, &app);
|
||||||
#endif
|
#endif
|
||||||
if (!_serviceStatusHandle)
|
if (!_serviceStatusHandle)
|
||||||
throw SystemException("cannot register service control handler");
|
throw SystemException("cannot register service control handler");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user