From bea8bccba38fae987690d5af259f6f8b22fbc781 Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Fri, 27 Oct 2023 17:22:09 -0400 Subject: [PATCH] [WASimClient] Save the request updates paused state (set with `setDataRequestsPaused()`) locally even if not connected to server; Send the paused state to server upon connection before sending any queued data requests. --- src/WASimClient/WASimClient.cpp | 12 +++++++++++- src/include/client/WASimClient.h | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/WASimClient/WASimClient.cpp b/src/WASimClient/WASimClient.cpp index 2aaa706..c292199 100644 --- a/src/WASimClient/WASimClient.cpp +++ b/src/WASimClient/WASimClient.cpp @@ -234,6 +234,7 @@ class WASimClient::Private atomic_bool simConnected = false; atomic_bool serverConnected = false; atomic_bool logCDAcreated = false; + atomic_bool requestsPaused = false; HANDLE hSim = nullptr; HANDLE hSimEvent = nullptr; @@ -676,6 +677,8 @@ class WASimClient::Private listResult.reset(); // make sure server knows our desired log level and set up data area/request if needed updateServerLogLevel(); + // set update status of data requests before adding any, in case we don't actually want results yet + sendServerCommand(Command(CommandId::Subscribe, (requestsPaused ? 0 : 1))); // (re-)register (or delete) any saved DataRequests registerAllDataRequests(); // same with calculator events @@ -1610,7 +1613,14 @@ vector WASimClient::dataRequestIdsList() const } HRESULT WASimClient::setDataRequestsPaused(bool paused) const { - return d_const->sendServerCommand(Command(CommandId::Subscribe, (paused ? 0 : 1))); + if (isConnected()) { + HRESULT hr = d_const->sendServerCommand(Command(CommandId::Subscribe, (paused ? 0 : 1))); + if SUCCEEDED(hr) + d->requestsPaused = paused; + return hr; + } + d->requestsPaused = paused; + return S_OK; } #pragma endregion Data diff --git a/src/include/client/WASimClient.h b/src/include/client/WASimClient.h index df0058c..566c1a7 100644 --- a/src/include/client/WASimClient.h +++ b/src/include/client/WASimClient.h @@ -411,7 +411,10 @@ static const HRESULT E_TIMEOUT = /*ERROR_TIMEOUT*/ 1460L | (/*FACILI /// Enables or disables all data request subscription updates at the same time. Use this to temporarily suspend value update checks when they are not needed, but may be again in the future. /// This is a lot more efficient than disconnecting and re-connecting to the server, since all the data requests need to be re-created upon every new connection (similar to SimConnect itself). - /// \return `S_OK` on success, `E_NOT_CONNECTED` if not connected to server. + /// \since{v1.2} + /// This method can be called while not connected to the server. In this case the setting is saved and sent to the server upon next connection, before sending any data request subscriptions. + /// This way updates could be suspended upon initial connection, then re-enabled when the data is actually needed. + /// \return `S_OK` on success; If currently connected to the server, may also return `E_TIMEOUT` on general server communication failure. HRESULT setDataRequestsPaused(bool paused) const; // Custom Event registration --------------------------