Skip to content

Commit

Permalink
[WASimClient] Save the request updates paused state (set with `setDat…
Browse files Browse the repository at this point in the history
…aRequestsPaused()`) locally even if not connected to server; Send the paused state to server upon connection before sending any queued data requests.
  • Loading branch information
mpaperno committed Nov 1, 2023
1 parent fe99bbb commit bea8bcc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/WASimClient/WASimClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1610,7 +1613,14 @@ vector<uint32_t> 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
Expand Down
5 changes: 4 additions & 1 deletion src/include/client/WASimClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------
Expand Down

0 comments on commit bea8bcc

Please sign in to comment.