-
-
Notifications
You must be signed in to change notification settings - Fork 3
Add facility manager API and tests #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add facility manager API and tests #14
Conversation
| foreach (var result in this.Results) | ||
| { | ||
| if (result.DataType == dataType) | ||
| { | ||
| return result; | ||
| } | ||
| } |
| /// <param name="fieldName">The field path to add.</param> | ||
| /// <returns>The raw SimConnect result.</returns> | ||
| public int AddToFacilityDefinition(IntPtr handle, uint definitionId, string fieldName) | ||
| => SimConnectNative.SimConnect_AddToFacilityDefinition(handle, definitionId, fieldName); |
| /// <param name="region">Optional region code.</param> | ||
| /// <returns>The raw SimConnect result.</returns> | ||
| public int RequestFacilityData(IntPtr handle, uint definitionId, uint requestId, string icao, string region) | ||
| => SimConnectNative.SimConnect_RequestFacilityData(handle, definitionId, requestId, icao, region ?? string.Empty); |
| /// <param name="requestId">Client request identifier.</param> | ||
| /// <returns>The raw SimConnect result.</returns> | ||
| public int RequestFacilitiesList(IntPtr handle, uint type, uint requestId) | ||
| => SimConnectNative.SimConnect_RequestFacilitiesList(handle, type, requestId); |
| /// <param name="requestId">Client request identifier.</param> | ||
| /// <returns>The raw SimConnect result.</returns> | ||
| public int RequestFacilitiesListEx1(IntPtr handle, uint type, uint requestId) | ||
| => SimConnectNative.SimConnect_RequestFacilitiesList_EX1(handle, type, requestId); |
| /// <param name="oldOutRangeRequestId">Request ID for entries leaving range.</param> | ||
| /// <returns>The raw SimConnect result.</returns> | ||
| public int SubscribeToFacilitiesEx1(IntPtr handle, uint type, uint newInRangeRequestId, uint oldOutRangeRequestId) | ||
| => SimConnectNative.SimConnect_SubscribeToFacilities_EX1(handle, type, newInRangeRequestId, oldOutRangeRequestId); |
| /// <param name="unsubscribeOldOutRange">Whether to unsubscribe from out-of-range events.</param> | ||
| /// <returns>The raw SimConnect result.</returns> | ||
| public int UnsubscribeFromFacilitiesEx1(IntPtr handle, uint type, bool unsubscribeNewInRange, bool unsubscribeOldOutRange) | ||
| => SimConnectNative.SimConnect_UnsubscribeToFacilities_EX1(handle, type, unsubscribeNewInRange, unsubscribeOldOutRange); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a comprehensive facility management API for SimConnect.NET, enabling developers to query and subscribe to flight simulator facility data (airports, waypoints, VORs, NDBs) using high-level abstractions with async/await patterns.
- Adds a
FacilityManagerclass with support for custom definitions via builders or attribute annotations - Implements minimal facility list requests and detailed facility data retrieval with proper message correlation
- Provides a subscription mechanism for tracking facilities entering/exiting the user's reality bubble
- Includes a new xUnit-based test project that verifies core functionality through unit tests with faked API implementations
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/SimConnect.NET.UnitTests/SimConnect.NET.UnitTests.csproj | New xUnit test project configuration targeting .NET 8.0 |
| tests/SimConnect.NET.UnitTests/FacilityManagerTests.cs | Comprehensive unit tests for facility definitions, requests, and subscriptions |
| src/SimConnect.NET/Structs/SimConnectIcao.cs | Refactored to use byte arrays with encoding helpers for proper ANSI marshaling |
| src/SimConnect.NET/SimConnectClient.cs | Integrated FacilityManager lifecycle and message routing |
| src/SimConnect.NET/Properties/AssemblyInfo.cs | Added InternalsVisibleTo for test assembly access |
| src/SimConnect.NET/Internal/ISimConnectFacilityApi.cs | Abstraction layer for facility P/Invoke calls with testable interface |
| src/SimConnect.NET/Facilities/FacilitySubscription.cs | Disposable subscription handle for in-range facility notifications |
| src/SimConnect.NET/Facilities/FacilityManager.cs | Core manager implementing definition creation, requests, and subscriptions |
| src/SimConnect.NET/Facilities/FacilityFieldAttribute.cs | Attribute for annotating struct fields with facility field paths |
| src/SimConnect.NET/Facilities/FacilityDefinitionBuilder.cs | Fluent builder for creating facility definitions |
| src/SimConnect.NET/Facilities/FacilityDefinition.cs | Immutable definition wrapper with field list and definition ID |
| src/SimConnect.NET/Facilities/FacilityDataResult.cs | Result structure containing raw payload with marshaling helper |
| src/SimConnect.NET/Facilities/FacilityDataResponse.cs | Response container with helper to find specific data types |
| SimConnect.NET.sln | Added new test project to solution configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| private sealed class FacilityMinimalListRequest | ||
| { | ||
| private readonly TaskCompletionSource<IReadOnlyList<SimConnectFacilityMinimal>> tcs = new(TaskCreationOptions.RunContinuationsAsynchronously); | ||
| private readonly List<SimConnectFacilityMinimal> buffer = new(); | ||
| private uint expectedPackets; | ||
| private uint receivedPackets; | ||
|
|
||
| internal FacilityMinimalListRequest(uint requestId) | ||
| { | ||
| } | ||
|
|
||
| internal Task<IReadOnlyList<SimConnectFacilityMinimal>> Task => this.tcs.Task; | ||
|
|
||
| internal bool IsComplete => this.expectedPackets != 0 && this.receivedPackets >= this.expectedPackets; | ||
|
|
||
| internal void AddChunk(IReadOnlyList<SimConnectFacilityMinimal> chunk, uint entryNumber, uint outOf) | ||
| { | ||
| if (chunk.Count > 0) | ||
| { | ||
| this.buffer.AddRange(chunk); | ||
| } | ||
|
|
||
| this.receivedPackets++; | ||
| this.expectedPackets = outOf == 0 ? 1u : outOf; | ||
|
|
||
| if (this.IsComplete) | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimal list requests never complete for multi-packet responses
The completion logic for minimal facility lists interprets OutOf as the number of packets rather than the total number of facilities. In the SimConnect SIMCONNECT_RECV_FACILITY_MINIMAL_LIST payload, OutOf represents the total facility count and EntryNumber indicates the index of the first facility in this chunk. Here AddChunk only increments receivedPackets by 1 per message and sets expectedPackets = outOf, so a request that returns hundreds of facilities over a handful of packets will wait for outOf packets and the Task never completes. You should track completion based on entryNumber + chunk.Count >= outOf or by counting facilities, not packets.
Useful? React with 👍 / 👎.
Summary
Testing
dotnet test tests/SimConnect.NET.UnitTests/SimConnect.NET.UnitTests.csproj -p:TargetFrameworks=net8.0 -p:TargetFramework=net8.0Codex Task