From d9da40c0e85b9953b5c5e298b778edc384bc13e6 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Sat, 13 Apr 2019 21:20:07 +0100 Subject: [PATCH] Internal interfaces do the await callback automatically --- .../Callbacks/SteamApiCallback.cs | 16 +++++++++++++--- .../Generated/Interfaces/ISteamApps.cs | 5 +++-- .../Generated/Interfaces/ISteamUtils.cs | 5 +++-- Generator/CodeWriter/ClassVTable.cs | 1 + Generator/CodeWriter/Types/BaseType.cs | 4 ++-- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Facepunch.Steamworks/Callbacks/SteamApiCallback.cs b/Facepunch.Steamworks/Callbacks/SteamApiCallback.cs index 8698692..f452318 100644 --- a/Facepunch.Steamworks/Callbacks/SteamApiCallback.cs +++ b/Facepunch.Steamworks/Callbacks/SteamApiCallback.cs @@ -16,13 +16,23 @@ public SteamApiCallback( ulong callbackHandle ) CallHandle = callbackHandle; } - public bool IsComplete() + public bool IsComplete( out bool failed ) { - return Utils.IsCallComplete( CallHandle, out bool failed ); + return Utils.IsCallComplete( CallHandle, out failed ); } - public T? GetResult() + public async Task GetResult() { + bool failed = false; + + while ( !IsComplete( out failed ) ) + { + await Task.Delay( 1 ); + } + + if ( failed ) + return null; + return Utils.GetResult( CallHandle ); } } diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamApps.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamApps.cs index 1e0037f..de33f68 100644 --- a/Facepunch.Steamworks/Generated/Interfaces/ISteamApps.cs +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamApps.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using System.Text; +using System.Threading.Tasks; using SteamNative; @@ -337,9 +338,9 @@ public void RequestAllProofOfPurchaseKeys() private GetFileDetailsDelegate GetFileDetailsDelegatePointer; #endregion - public SteamApiCallback GetFileDetails( string pszFileName ) + public async Task GetFileDetails( string pszFileName ) { - return new SteamApiCallback( GetFileDetailsDelegatePointer( Self, pszFileName ) ); + return await (new SteamApiCallback( GetFileDetailsDelegatePointer( Self, pszFileName ) )).GetResult(); } #region FunctionMeta diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamUtils.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamUtils.cs index 911b520..59b4e92 100644 --- a/Facepunch.Steamworks/Generated/Interfaces/ISteamUtils.cs +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamUtils.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using System.Text; +using System.Threading.Tasks; using SteamNative; @@ -266,9 +267,9 @@ public bool BOverlayNeedsPresent() private CheckFileSignatureDelegate CheckFileSignatureDelegatePointer; #endregion - public SteamApiCallback CheckFileSignature( string szFileName ) + public async Task CheckFileSignature( string szFileName ) { - return new SteamApiCallback( CheckFileSignatureDelegatePointer( Self, szFileName ) ); + return await (new SteamApiCallback( CheckFileSignatureDelegatePointer( Self, szFileName ) )).GetResult(); } #region FunctionMeta diff --git a/Generator/CodeWriter/ClassVTable.cs b/Generator/CodeWriter/ClassVTable.cs index bc6eaf5..10e163e 100644 --- a/Generator/CodeWriter/ClassVTable.cs +++ b/Generator/CodeWriter/ClassVTable.cs @@ -17,6 +17,7 @@ public void GenerateVTableClass( string className, string filename ) WriteLine( $"using System;" ); WriteLine( $"using System.Runtime.InteropServices;" ); WriteLine( $"using System.Text;" ); + WriteLine( $"using System.Threading.Tasks;" ); WriteLine( $"using SteamNative;" ); WriteLine(); diff --git a/Generator/CodeWriter/Types/BaseType.cs b/Generator/CodeWriter/Types/BaseType.cs index 958c532..53ad04e 100644 --- a/Generator/CodeWriter/Types/BaseType.cs +++ b/Generator/CodeWriter/Types/BaseType.cs @@ -73,8 +73,8 @@ internal class SteamApiCallType : BaseType { public string CallResult; public override string TypeName => "SteamAPICall_t"; - public override string Return( string varname ) => $"return new SteamApiCallback<{CallResult}>( {varname} );"; - public override string ReturnType => $"SteamApiCallback<{CallResult}>"; + public override string Return( string varname ) => $"return await (new SteamApiCallback<{CallResult}>( {varname} )).GetResult();"; + public override string ReturnType => $"async Task<{CallResult}?>"; } internal class CSteamIdType : BaseType