Skip to content

Commit

Permalink
[WASimClient] Add async option to saveDataRequest().
Browse files Browse the repository at this point in the history
  • Loading branch information
mpaperno committed Nov 1, 2023
1 parent 3090d53 commit 82ea425
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/WASimClient/WASimClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,14 +971,14 @@ class WASimClient::Private

// Writes DataRequest data to the corresponding CDA and waits for an Ack/Nak from server.
// If the DataRequest::requestType == None, the request will be deleted by the server and the response wait is skipped.
HRESULT sendDataRequest(const DataRequest &req)
HRESULT sendDataRequest(const DataRequest &req, bool async)
{
HRESULT hr;
if FAILED(hr = writeDataRequest(req))
return hr;

// check if just deleting an existing request and don't wait around for that response
if (req.requestType == RequestType::None)
if (async || req.requestType == RequestType::None)
return hr;

shared_ptr<condition_variable_any> cv = make_shared<condition_variable_any>();
Expand Down Expand Up @@ -1033,7 +1033,7 @@ class WASimClient::Private
return SimConnectHelper::removeClientDataDefinition(hSim, tr->dataId);
}

HRESULT addOrUpdateRequest(const DataRequest &req)
HRESULT addOrUpdateRequest(const DataRequest &req, bool async)
{
if (req.requestType == RequestType::None)
return removeRequest(req.requestId);
Expand Down Expand Up @@ -1082,7 +1082,7 @@ class WASimClient::Private
hr = registerDataRequestArea(tr, isNewRequest, dataAllocationChanged);
if SUCCEEDED(hr) {
// send the request and wait for Ack; Request may timeout or return a Nak.
hr = sendDataRequest(req);
hr = sendDataRequest(req, async);
}
if (FAILED(hr) && isNewRequest) {
// delete a new request if anything failed
Expand Down Expand Up @@ -1557,8 +1557,8 @@ HRESULT WASimClient::setOrCreateLocalVariable(const std::string &variableName, c

#pragma region Data Requests ----------------------------------------------

HRESULT WASimClient::saveDataRequest(const DataRequest &request) {
return d->addOrUpdateRequest(request);
HRESULT WASimClient::saveDataRequest(const DataRequest &request, bool async) {
return d->addOrUpdateRequest(request, async);
}

HRESULT WASimClient::removeDataRequest(const uint32_t requestId) {
Expand Down
11 changes: 8 additions & 3 deletions src/include/client/WASimClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,15 @@ static const HRESULT E_TIMEOUT = /*ERROR_TIMEOUT*/ 1460L | (/*FACILI

/// Add a new `WASimCommander::DataRequest` or update an existing one with the same `DataRequest::requestId`. If the client is not currently connected to the server, the request is queued until the next connection is established.
/// \param request The `WASimCommander::DataRequest` structure to process. See `WASimCommander::DataRequest` documentation for details of the structure members.
/// \return `S_OK` on success, `E_INVALIDARG` if there is a problem with the `DataRequest` contents; If currently connected to the server, may also return `E_FAIL` if the server returned `Nak` response, or `E_TIMEOUT` on general server communication failure.
/// \note If currently connected to the server, this method will block until either the Server responds or the timeout has expired (see `defaultTimeout()`).
/// \param async `true` to wait for a response from the server before returning, or `false` (default) to wait for an `Ack`/`Nak` response. See return values and the Note below for more details.
/// \return `S_OK` on success, `E_INVALIDARG` if there is a problem with the `DataRequest` contents. \n
/// If currently connected to the server and `async` is `false`, may also return `E_FAIL` if the server returned `Nak` response, or `E_TIMEOUT` on general server communication failure.
/// \note If currently connected to the server and the `async` param is `false`, this method will block until either the Server responds or the timeout has expired (see `defaultTimeout()`).
/// \par Tracking async calls
/// To track the status of an async request, set a callback function with `setCommandResultCallback()`. The server should respond with an \refwce{CommandId::Ack} or \refwce{CommandId::Nak}
/// \refwc{Command} where the `uData` value is \refwce{CommandId::Subscribe} and the \refwc{Command::token} will be the `requestId` value from the given `request` struct.
/// \sa \refwc{DataRequest} \refwce{CommandId::Subscribe}, removeDataRequest(), updateDataRequest()
HRESULT saveDataRequest(const DataRequest &request);
HRESULT saveDataRequest(const DataRequest &request, bool async = false);
/// Remove a previously-added `DataRequest`. This clears the subscription and any tracking/meta data from both server and client sides.
/// Using this method is effectively the same as calling `dataRequest()` with a `DataRequest` of type `RequestType::None`.
/// \param requestId ID of the request to remove.
Expand Down

0 comments on commit 82ea425

Please sign in to comment.