From de61eaf6b8a82e98d908876d2690c6b1bac073f7 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Thu, 6 Apr 2017 13:05:31 -0700 Subject: [PATCH] src: dotnet: Service improvements --- src/dotnet/Interop.cs | 17 +++++++++++++++++ src/dotnet/Service.cs | 23 ++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/dotnet/Interop.cs b/src/dotnet/Interop.cs index 8b294021..b3bd5e3c 100644 --- a/src/dotnet/Interop.cs +++ b/src/dotnet/Interop.cs @@ -389,6 +389,7 @@ namespace Fsp.Interop { internal struct Proto { + /* FileSystem */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate Int32 FspFileSystemPreflight( [MarshalAs(UnmanagedType.LPWStr)] String DevicePath, @@ -439,6 +440,8 @@ namespace Fsp.Interop out IoStatusBlock PIoStatus, IntPtr Buffer, ref UIntPtr PSize); + + /* Service */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate Int32 FspServiceCreate( [MarshalAs(UnmanagedType.LPWStr)] String ServiceName, @@ -453,6 +456,14 @@ namespace Fsp.Interop internal delegate void FspServiceAllowConsoleMode( IntPtr Service); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void FspServiceRequestTime( + IntPtr Service, + UInt32 Time); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void FspServiceSetExitCode( + IntPtr Service, + UInt32 ExitCode); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate UInt32 FspServiceGetExitCode( IntPtr Service); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -466,6 +477,8 @@ namespace Fsp.Interop UInt32 Type, [MarshalAs(UnmanagedType.LPWStr)] String Format, [MarshalAs(UnmanagedType.LPWStr)] String Message); + + /* utility */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate Int32 FspVersion( out UInt32 PVersion); @@ -517,6 +530,8 @@ namespace Fsp.Interop internal static Proto.FspServiceCreate FspServiceCreate; internal static Proto.FspServiceDelete FspServiceDelete; internal static Proto.FspServiceAllowConsoleMode FspServiceAllowConsoleMode; + internal static Proto.FspServiceRequestTime FspServiceRequestTime; + internal static Proto.FspServiceSetExitCode FspServiceSetExitCode; internal static Proto.FspServiceGetExitCode FspServiceGetExitCode; internal static Proto.FspServiceLoop FspServiceLoop; internal static Proto.FspServiceStop FspServiceStop; @@ -697,6 +712,8 @@ namespace Fsp.Interop FspServiceCreate = GetEntryPoint(Module); FspServiceDelete = GetEntryPoint(Module); FspServiceAllowConsoleMode = GetEntryPoint(Module); + FspServiceRequestTime = GetEntryPoint(Module); + FspServiceSetExitCode = GetEntryPoint(Module); FspServiceGetExitCode = GetEntryPoint(Module); FspServiceLoop = GetEntryPoint(Module); FspServiceStop = GetEntryPoint(Module); diff --git a/src/dotnet/Service.cs b/src/dotnet/Service.cs index 9320ce21..4a507a95 100644 --- a/src/dotnet/Service.cs +++ b/src/dotnet/Service.cs @@ -65,12 +65,21 @@ namespace Fsp } return (int)ExitCode; } - void Stop() + public void Stop() { if (0 > _CreateResult) return; Api.FspServiceStop(_Service); } + public void RequestTime(UInt32 Time) + { + Api.FspServiceRequestTime(_Service, Time); + } + public int ExitCode + { + get { return (int)Api.FspServiceGetExitCode(_Service); } + set { Api.FspServiceSetExitCode(_Service, (UInt32)value); } + } public static void Log(UInt32 Type, String Message) { Api.FspServiceLog(Type, "%s", Message); @@ -81,13 +90,11 @@ namespace Fsp { return unchecked((Int32)0xE0434f4D)/*STATUS_CLR_EXCEPTION*/; } - protected virtual Int32 OnStart(String[] Args) + protected virtual void OnStart(String[] Args) { - return 0; } - protected virtual Int32 OnStop() + protected virtual void OnStop() { - return 0; } /* callbacks */ @@ -99,8 +106,9 @@ namespace Fsp Service self = (Service)Api.GetUserContext(Service); try { - return self.OnStart( + self.OnStart( Argv); + return 0/*STATUS_SUCCESS*/; } catch (Exception ex) { @@ -113,7 +121,8 @@ namespace Fsp Service self = (Service)Api.GetUserContext(Service); try { - return self.OnStop(); + self.OnStop(); + return 0/*STATUS_SUCCESS*/; } catch (Exception ex) {