mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-23 00:43:00 -05:00
inc: winfsp.hpp: Service class improvements
This commit is contained in:
parent
d5802f3a5f
commit
bf87c539fd
@ -953,10 +953,11 @@ class Service
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/* ctor/dtor */
|
/* ctor/dtor */
|
||||||
Service(PWSTR ServiceName) : _Service(0), _CreateResult()
|
Service(PWSTR ServiceName) : _Service(0)
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize();
|
||||||
_CreateResult = FspServiceCreate(ServiceName, OnStart, OnStop, 0, &_Service);
|
FspServiceCreate(ServiceName, OnStart, OnStop, 0, &_Service);
|
||||||
|
if (0 != _Service)
|
||||||
_Service->UserContext = this;
|
_Service->UserContext = this;
|
||||||
}
|
}
|
||||||
virtual ~Service()
|
virtual ~Service()
|
||||||
@ -968,11 +969,12 @@ public:
|
|||||||
/* control */
|
/* control */
|
||||||
ULONG Run()
|
ULONG Run()
|
||||||
{
|
{
|
||||||
if (!NT_SUCCESS(_CreateResult))
|
if (0 == _Service)
|
||||||
{
|
{
|
||||||
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
||||||
L"The service cannot be created (Status=%lx).", _CreateResult);
|
L"The service cannot be created (Status=%lx).",
|
||||||
return FspWin32FromNtStatus(_CreateResult);
|
STATUS_INSUFFICIENT_RESOURCES);
|
||||||
|
return FspWin32FromNtStatus(STATUS_INSUFFICIENT_RESOURCES);
|
||||||
}
|
}
|
||||||
FspServiceAllowConsoleMode(_Service);
|
FspServiceAllowConsoleMode(_Service);
|
||||||
NTSTATUS Result = FspServiceLoop(_Service);
|
NTSTATUS Result = FspServiceLoop(_Service);
|
||||||
@ -980,17 +982,38 @@ public:
|
|||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
{
|
{
|
||||||
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
||||||
L"The service %s has failed to run (Status=%lx).", _Service->ServiceName, Result);
|
L"The service has failed to run (Status=%lx).",
|
||||||
|
Result);
|
||||||
return FspWin32FromNtStatus(Result);
|
return FspWin32FromNtStatus(Result);
|
||||||
}
|
}
|
||||||
return ExitCode;
|
return ExitCode;
|
||||||
}
|
}
|
||||||
VOID Stop()
|
VOID Stop()
|
||||||
{
|
{
|
||||||
if (!NT_SUCCESS(_CreateResult))
|
if (0 == _Service)
|
||||||
return;
|
return;
|
||||||
FspServiceStop(_Service);
|
FspServiceStop(_Service);
|
||||||
}
|
}
|
||||||
|
VOID RequestTime(ULONG Time)
|
||||||
|
{
|
||||||
|
if (0 == _Service)
|
||||||
|
return;
|
||||||
|
FspServiceRequestTime(_Service, Time);
|
||||||
|
}
|
||||||
|
ULONG GetExitCode()
|
||||||
|
{
|
||||||
|
return 0 != _Service ? FspServiceGetExitCode(_Service) : ERROR_NO_SYSTEM_RESOURCES;
|
||||||
|
}
|
||||||
|
VOID SetExitCode(ULONG ExitCode)
|
||||||
|
{
|
||||||
|
if (0 == _Service)
|
||||||
|
return;
|
||||||
|
FspServiceSetExitCode(_Service, ExitCode);
|
||||||
|
}
|
||||||
|
FSP_SERVICE *ServiceHandle()
|
||||||
|
{
|
||||||
|
return _Service;
|
||||||
|
}
|
||||||
static VOID Log(ULONG Type, PWSTR Format, ...)
|
static VOID Log(ULONG Type, PWSTR Format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -1042,7 +1065,6 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
FSP_SERVICE *_Service;
|
FSP_SERVICE *_Service;
|
||||||
NTSTATUS _CreateResult;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user