28#define WIN32_LEAN_AND_MEAN
32#include "client/exports.h"
33#include "client/enums.h"
34#include "client/structs.h"
40#ifndef WSMCMND_CLIENT_USE_CONCURRENT_CALLBACKS
41 #define WSMCMND_CLIENT_USE_CONCURRENT_CALLBACKS 1
55#ifndef E_NOT_CONNECTED
59static const HRESULT
E_TIMEOUT = 1460L | ( 7 << 16) | 0x80000000;
94 explicit WASimClient(uint32_t clientId,
const std::string &configFile = std::string());
102 bool isInitialized()
const;
103 bool isConnected()
const;
104 uint32_t clientVersion()
const;
105 uint32_t serverVersion()
const;
115 HRESULT connectSimulator(uint32_t timeout = 0);
124 HRESULT connectSimulator(
int networkConfigId, uint32_t timeout = 0);
127 void disconnectSimulator();
134 uint32_t pingServer(uint32_t timeout = 0);
144 HRESULT connectServer(uint32_t timeout = 0);
146 void disconnectServer();
150 uint32_t defaultTimeout()
const;
152 void setDefaultTimeout(uint32_t ms);
156 int networkConfigurationId()
const;
159 void setNetworkConfigurationId(
int configId);
200 HRESULT getVariable(
const VariableRequest &variable,
double *pfResult, std::string *psResult =
nullptr);
207 HRESULT getLocalVariable(
const std::string &variableName,
double *pfResult,
const std::string &unitName = std::string());
215 HRESULT getOrCreateLocalVariable(
const std::string &variableName,
double *pfResult,
double defaultValue = 0.0,
const std::string &unitName = std::string());
233 HRESULT setVariable(
const VariableRequest &variable,
const double value);
238 HRESULT setVariable(
const VariableRequest &variable,
const std::string &stringValue);
246 HRESULT setLocalVariable(
const std::string &variableName,
const double value,
const std::string &unitName = std::string());
255 HRESULT setOrCreateLocalVariable(
const std::string &variableName,
const double value,
const std::string &unitName = std::string());
262 inline HRESULT
setSimVarVariable(
const std::string &variableName,
const std::string &unitName,
double value) {
return setVariable(
VariableRequest(variableName, unitName), value); }
266 inline HRESULT
setSimVarVariable(
const std::string &variableName, uint8_t simVarIndex,
const std::string &unitName,
double value) {
return setVariable(
VariableRequest(variableName, unitName, simVarIndex), value); }
274 inline HRESULT
setSimVarVariable(
const std::string &variableName, uint8_t index,
const std::string &stringValue) {
return setVariable(
VariableRequest(variableName, {}, index), stringValue); }
293 HRESULT saveDataRequest(
const DataRequest &request,
bool async =
false);
301 HRESULT removeDataRequest(
const uint32_t requestId);
307 HRESULT updateDataRequest(uint32_t requestId);
313 std::vector<DataRequestRecord> dataRequests()
const;
315 std::vector<uint32_t> dataRequestIdsList()
const;
323 HRESULT setDataRequestsPaused(
bool paused)
const;
340 HRESULT removeEvent(uint32_t eventId);
345 HRESULT transmitEvent(uint32_t eventId);
351 std::vector<RegisteredEvent> registeredEvents()
const;
379 HRESULT sendKeyEvent(uint32_t keyEventId, uint32_t v1 = 0, uint32_t v2 = 0, uint32_t v3 = 0, uint32_t v4 = 0, uint32_t v5 = 0)
const;
396 HRESULT sendKeyEvent(
const std::string &keyEventName, uint32_t v1 = 0, uint32_t v2 = 0, uint32_t v3 = 0, uint32_t v4 = 0, uint32_t v5 = 0);
416 HRESULT registerCustomKeyEvent(
const std::string &customEventName, uint32_t *puiCustomEventId =
nullptr,
bool useLegacyTransmit =
false);
423 HRESULT removeCustomKeyEvent(
const std::string &customEventName);
428 HRESULT removeCustomKeyEvent(uint32_t eventId);
457 HRESULT sendCommand(
const Command &command)
const;
464 HRESULT sendCommandWithResponse(
const Command &command,
Command *response, uint32_t timeout = 0);
499 template<
class Tcaller>
500 inline void setClientEventCallback(
void(__stdcall Tcaller::*
const member)(
const ClientEvent &), Tcaller *
const caller);
510 template<
class Tcaller>
511 inline void setListResultsCallback(
void(__stdcall Tcaller::*
const member)(
const ListResult &), Tcaller *
const caller);
520 template<
class Tcaller>
521 inline void setDataCallback(
void(__stdcall Tcaller::*
const member)(
const DataRequestRecord &), Tcaller *
const caller);
530 template<
class Tcaller>
531 inline void setLogCallback(
void(__stdcall Tcaller::*
const member)(
const LogRecord &,
LogSource), Tcaller *
const caller);
544 template<
class Tcaller>
545 inline void setCommandResultCallback(
void(__stdcall Tcaller::*
const member)(
const Command &), Tcaller *
const caller);
556 template<
class Tcaller>
557 inline void setResponseCallback(
void(__stdcall Tcaller::*
const member)(
const Command &), Tcaller *
const caller);
563#pragma warning( suppress: 4251 )
564 const std::unique_ptr<Private> d;
566 friend class Private;
577 template<
class Tcaller>
583 template<
class Tcaller>
589 template<
class Tcaller>
595 template<
class Tcaller>
598 setLogCallback(std::bind(member, caller, std::placeholders::_1, std::placeholders::_2));
601 template<
class Tcaller>
607 template<
class Tcaller>
WASimCommander Client implementation. Handles all aspects of communication with the WASimCommander Se...
void setDataCallback(dataCallback_t cb)
Sets a callback for value update data arriving from the server. Pass a nullptr value to remove a prev...
void setLogCallback(logCallback_t cb)
Sets a callback for logging activity, both from the server and the client itself. Pass a nullptr valu...
HRESULT setSimVarVariable(const std::string &variableName, const std::string &unitName, double value)
Sets a numeric value on an 'A' (aka "SimVar" / "Simulator Variable") type variable....
HRESULT setSimVarVariable(const std::string &variableName, const std::string &stringValue)
Sets a string value on an 'A' (aka "SimVar" / "Simulator Variable") type variable....
void setCommandResultCallback(commandCallback_t cb)
Sets a callback for delivering command results returned by the server. Pass a nullptr value to remove...
void setListResultsCallback(listResultsCallback_t cb)
Sets a callback for list results arriving from the server. Pass a nullptr value to remove a previousl...
void setResponseCallback(commandCallback_t cb)
Sets a callback for delivering response commands sent to this client by the server module....
HRESULT setSimVarVariable(const std::string &variableName, uint8_t simVarIndex, const std::string &unitName, double value)
Sets a numeric value on an indexed 'A' (aka "SimVar" / "Simulator Variable") type variable....
HRESULT setSimVarVariable(const std::string &variableName, uint8_t index, const std::string &stringValue)
Sets a string value on an indexed 'A' (aka "SimVar" / "Simulator Variable") type variable....
void setClientEventCallback(clientEventCallback_t cb)
Sets a callback for Client event updates which indicate status changes. Pass a nullptr value to remov...
WASimCommander::Client namespace. Defines/declares everything needed to interact with the WASimComman...
static const HRESULT E_TIMEOUT
Error result: timeout communicating with server.
std::function< void __stdcall(const LogRecord &, LogSource)> logCallback_t
Callback function for log entries (from both Client and Server).
std::function< void __stdcall(const DataRequestRecord &)> dataCallback_t
Callback function for subscription result data.
std::function< void __stdcall(const ListResult &)> listResultsCallback_t
Callback function for delivering list results, eg. of local variables sent from Server.
std::function< void __stdcall(const Command &)> commandCallback_t
Callback function for commands sent from server.
LogSource
Log entry source, Client or Server.
@ Client
Log record from WASimClient.
static const HRESULT E_NOT_CONNECTED
Error result: server not connected.
static const uint32_t CUSTOM_KEY_EVENT_ID_MIN
Starting ID range for "Custom Key Events" for use with registerCustomKeyEvent() generated IDs....
std::function< void __stdcall(const ClientEvent &)> clientEventCallback_t
Callback function for Client events.
ClientStatus
Client status flags.
Client Event data, delivered via callback.
Structure for delivering list results, eg. of local variables sent from Server.
LookupItemType
Types of things to look up or list.
@ LocalVariable
LVar ('L') names and IDs. Available for List and Lookup commands.
CalcResultType
The type of result that calculator code is expected to produce.
@ None
No result is expected (eg. triggering an event).
LogFacility
Logging destination type.
@ Remote
Remote destination, eg. network transmission or a callback event.
DataRequestRecord inherits and extends WASimCommander::DataRequest with data pertinent for use by a d...
Structure to hold data for registered (reusable) calculator events. Used to submit events with WASimC...
Structure for using with WASimClient::getVariable() and WASimClient::setVariable() to specify informa...
Command data structure. The member contents depend on the command type as described in each command t...
Structure for variable value subscription requests.