Skip to content

Commit fcd8b79

Browse files
committed
Final Review feedback
- made both JobContext and ProgressService internal - Added missing HResult functions
1 parent 1b8b061 commit fcd8b79

File tree

4 files changed

+149
-6
lines changed

4 files changed

+149
-6
lines changed

sources/Core/Core/HRESULT.Manual.cs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
#pragma warning disable CS1589, CS0419, CA1416, CS0618
5+
using System.Runtime.CompilerServices;
6+
using System.Runtime.InteropServices;
7+
58
namespace Silk.NET.Core;
69

710
/// <summary>
@@ -18,4 +21,131 @@ public partial struct HResult
1821
/// Has the function succeeded
1922
/// </summary>
2023
public bool Succeeded => Value >= 0;
24+
25+
/// <summary>
26+
/// Does the given HResult value indicates success
27+
/// </summary>
28+
/// <param name="hr">HResult value</param>
29+
/// <returns>Whether the value indicates success</returns>
30+
[MethodImpl((MethodImplOptions)768)]
31+
public static bool IndicatesSuccess(int hr) => hr >= 0;
32+
33+
/// <summary>
34+
/// Does the given HResult value indicates failure
35+
/// </summary>
36+
/// <param name="hr">HResult value</param>
37+
/// <returns>Whether the value indicates failure</returns>
38+
[MethodImpl((MethodImplOptions)768)]
39+
public static bool IndicatesFailure(int hr) => hr < 0;
40+
41+
/// <summary>
42+
/// Does the given HResult status indicates error
43+
/// </summary>
44+
/// <param name="status">HResult status value</param>
45+
/// <returns>Whether the value indicates error</returns>
46+
[MethodImpl((MethodImplOptions)768)]
47+
public static bool IndicatesError(int status) => ((uint)status >> 31) == 1;
48+
49+
/// <summary>
50+
/// Gets the code from the given HResult value
51+
/// </summary>
52+
/// <param name="hr">HResult value</param>
53+
/// <returns>code of the HResult</returns>
54+
[MethodImpl((MethodImplOptions)768)]
55+
public static int GetCode(int hr) => hr & 0xFFFF;
56+
57+
/// <summary>
58+
/// Gets the facility from the given HResult value
59+
/// </summary>
60+
/// <param name="hr">HResult value</param>
61+
/// <returns>facility of the HResult</returns>
62+
[MethodImpl((MethodImplOptions)768)]
63+
public static int GetFacility(int hr) => (hr >> 16) & 0x1FFF;
64+
65+
/// <summary>
66+
/// Gets the severity from the given HResult value
67+
/// </summary>
68+
/// <param name="hr">HResult value</param>
69+
/// <returns>severity of the HResult</returns>
70+
[MethodImpl((MethodImplOptions)768)]
71+
public static int GetSeverity(int hr) => (hr >> 31) & 1;
72+
73+
/// <summary>
74+
/// Creates a HResult from the given severity, facility, and code values
75+
/// </summary>
76+
/// <param name="severity">severity value</param>
77+
/// <param name="facility">facility value</param>
78+
/// <param name="code">code value</param>
79+
/// <returns>HResult with the given severity, facility, and code</returns>
80+
[MethodImpl((MethodImplOptions)768)]
81+
public static int Create(int severity, int facility, int code) =>
82+
(int)(((uint)severity << 31) | ((uint)facility << 16) | (uint)code);
83+
84+
/// <summary>
85+
/// Constructs a HResult from the given severity, facility, and code values
86+
/// </summary>
87+
/// <param name="severity">severity value</param>
88+
/// <param name="facility">facility value</param>
89+
/// <param name="code">code value</param>
90+
public HResult(int severity, int facility, int code) =>
91+
Value = Create(severity, facility, code);
92+
93+
/// <summary>
94+
/// Does this HResult represent a success
95+
/// </summary>
96+
public bool IsSuccess
97+
{
98+
[MethodImpl((MethodImplOptions)768)]
99+
get => IndicatesSuccess(Value);
100+
}
101+
102+
/// <summary>
103+
/// Does this HResult represent a failure
104+
/// </summary>
105+
public bool IsFailure
106+
{
107+
[MethodImpl((MethodImplOptions)768)]
108+
get => IndicatesFailure(Value);
109+
}
110+
111+
/// <summary>
112+
/// Does this HResult represent a error
113+
/// </summary>
114+
public bool IsError
115+
{
116+
[MethodImpl((MethodImplOptions)768)]
117+
get => IndicatesError(Value);
118+
}
119+
120+
/// <summary>
121+
/// Gets the code for this HResult
122+
/// </summary>
123+
public int Code
124+
{
125+
[MethodImpl((MethodImplOptions)768)]
126+
get => GetCode(Value);
127+
}
128+
129+
/// <summary>
130+
/// Gets the facility for this HResult
131+
/// </summary>
132+
public int Facility
133+
{
134+
[MethodImpl((MethodImplOptions)768)]
135+
get => GetFacility(Value);
136+
}
137+
138+
/// <summary>
139+
/// Gets the severity for this HResult
140+
/// </summary>
141+
public int Severity
142+
{
143+
[MethodImpl((MethodImplOptions)768)]
144+
get => GetSeverity(Value);
145+
}
146+
147+
/// <summary>
148+
/// Throws this HResult as an exception
149+
/// </summary>
150+
public void Throw() => Marshal.ThrowExceptionForHR(Value);
21151
}

sources/Core/Core/PublicAPI/net8.0/PublicAPI.Unshipped.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,21 @@ Silk.NET.Core.Handle.Handle() -> void
164164
Silk.NET.Core.Handle.Handle(void* value) -> void
165165
Silk.NET.Core.Handle.ToString(string? format, System.IFormatProvider? formatProvider) -> string!
166166
Silk.NET.Core.HResult
167+
Silk.NET.Core.HResult.Code.get -> int
167168
Silk.NET.Core.HResult.CompareTo(object? obj) -> int
168169
Silk.NET.Core.HResult.CompareTo(Silk.NET.Core.HResult other) -> int
169170
Silk.NET.Core.HResult.Equals(Silk.NET.Core.HResult other) -> bool
171+
Silk.NET.Core.HResult.Facility.get -> int
170172
Silk.NET.Core.HResult.Failed.get -> bool
171173
Silk.NET.Core.HResult.HResult() -> void
174+
Silk.NET.Core.HResult.HResult(int severity, int facility, int code) -> void
172175
Silk.NET.Core.HResult.HResult(int value) -> void
176+
Silk.NET.Core.HResult.IsError.get -> bool
177+
Silk.NET.Core.HResult.IsFailure.get -> bool
178+
Silk.NET.Core.HResult.IsSuccess.get -> bool
179+
Silk.NET.Core.HResult.Severity.get -> int
173180
Silk.NET.Core.HResult.Succeeded.get -> bool
181+
Silk.NET.Core.HResult.Throw() -> void
174182
Silk.NET.Core.HResult.ToString(string? format, System.IFormatProvider? formatProvider) -> string!
175183
Silk.NET.Core.HString
176184
Silk.NET.Core.HString.CompareTo(object? obj) -> int
@@ -582,6 +590,7 @@ static Silk.NET.Core.Handle.operator <=(Silk.NET.Core.Handle left, Silk.NET.Core
582590
static Silk.NET.Core.Handle.operator ==(Silk.NET.Core.Handle left, Silk.NET.Core.Handle right) -> bool
583591
static Silk.NET.Core.Handle.operator >(Silk.NET.Core.Handle left, Silk.NET.Core.Handle right) -> bool
584592
static Silk.NET.Core.Handle.operator >=(Silk.NET.Core.Handle left, Silk.NET.Core.Handle right) -> bool
593+
static Silk.NET.Core.HResult.Create(int severity, int facility, int code) -> int
585594
static Silk.NET.Core.HResult.explicit operator byte(Silk.NET.Core.HResult value) -> byte
586595
static Silk.NET.Core.HResult.explicit operator nuint(Silk.NET.Core.HResult value) -> nuint
587596
static Silk.NET.Core.HResult.explicit operator sbyte(Silk.NET.Core.HResult value) -> sbyte
@@ -594,14 +603,22 @@ static Silk.NET.Core.HResult.explicit operator Silk.NET.Core.HResult(ulong value
594603
static Silk.NET.Core.HResult.explicit operator uint(Silk.NET.Core.HResult value) -> uint
595604
static Silk.NET.Core.HResult.explicit operator ulong(Silk.NET.Core.HResult value) -> ulong
596605
static Silk.NET.Core.HResult.explicit operator ushort(Silk.NET.Core.HResult value) -> ushort
606+
static Silk.NET.Core.HResult.GetCode(int hr) -> int
607+
static Silk.NET.Core.HResult.GetFacility(int hr) -> int
608+
static Silk.NET.Core.HResult.GetSeverity(int hr) -> int
609+
static Silk.NET.Core.HResult.implicit operator int(Silk.NET.Core.HResult hr) -> int
597610
static Silk.NET.Core.HResult.implicit operator int(Silk.NET.Core.HResult value) -> int
598611
static Silk.NET.Core.HResult.implicit operator long(Silk.NET.Core.HResult value) -> long
599612
static Silk.NET.Core.HResult.implicit operator nint(Silk.NET.Core.HResult value) -> nint
600613
static Silk.NET.Core.HResult.implicit operator Silk.NET.Core.HResult(byte value) -> Silk.NET.Core.HResult
614+
static Silk.NET.Core.HResult.implicit operator Silk.NET.Core.HResult(int hr) -> Silk.NET.Core.HResult
601615
static Silk.NET.Core.HResult.implicit operator Silk.NET.Core.HResult(int value) -> Silk.NET.Core.HResult
602616
static Silk.NET.Core.HResult.implicit operator Silk.NET.Core.HResult(sbyte value) -> Silk.NET.Core.HResult
603617
static Silk.NET.Core.HResult.implicit operator Silk.NET.Core.HResult(short value) -> Silk.NET.Core.HResult
604618
static Silk.NET.Core.HResult.implicit operator Silk.NET.Core.HResult(ushort value) -> Silk.NET.Core.HResult
619+
static Silk.NET.Core.HResult.IndicatesError(int status) -> bool
620+
static Silk.NET.Core.HResult.IndicatesFailure(int hr) -> bool
621+
static Silk.NET.Core.HResult.IndicatesSuccess(int hr) -> bool
605622
static Silk.NET.Core.HResult.operator !=(Silk.NET.Core.HResult left, Silk.NET.Core.HResult right) -> bool
606623
static Silk.NET.Core.HResult.operator <(Silk.NET.Core.HResult left, Silk.NET.Core.HResult right) -> bool
607624
static Silk.NET.Core.HResult.operator <=(Silk.NET.Core.HResult left, Silk.NET.Core.HResult right) -> bool

sources/SilkTouch/SilkTouch/JobContext.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ namespace Silk.NET.SilkTouch
1414
/// <summary>
1515
/// Information on the current Job
1616
/// </summary>
17-
[Experimental(
18-
"ST0005",
19-
UrlFormat = "https://dotnet.github.io/Silk.NET/docs/v3/silk.net/diagnostics/{0}"
20-
)]
21-
public class JobContext
17+
internal class JobContext
2218
{
2319
private readonly AsyncLocal<string?> _key = new AsyncLocal<string?>();
2420

sources/SilkTouch/SilkTouch/Logging/ProgressService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Silk.NET.SilkTouch.Logging
1515
/// <summary>
1616
/// Default Implementation for ProgressService
1717
/// </summary>
18-
public class ProgressService : IProgressService
18+
internal class ProgressService : IProgressService
1919
{
2020
private ConcurrentDictionary<string, (string, float)> Progress =
2121
new ConcurrentDictionary<string, (string, float)>();

0 commit comments

Comments
 (0)