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());
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());
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());
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);
418 HRESULT registerCustomKeyEvent(
const std::string &customEventName, uint32_t *puiCustomEventId =
nullptr,
bool useLegacyTransmit =
false);
425 HRESULT removeCustomKeyEvent(
const std::string &customEventName);
430 HRESULT removeCustomKeyEvent(uint32_t eventId);
460 HRESULT sendCommand(
const Command &command)
const;
467 HRESULT sendCommandWithResponse(
const Command &command,
Command *response, uint32_t timeout = 0);
502 template<
class Tcaller>
503 inline void setClientEventCallback(
void(__stdcall Tcaller::*
const member)(
const ClientEvent &), Tcaller *
const caller);
513 template<
class Tcaller>
514 inline void setListResultsCallback(
void(__stdcall Tcaller::*
const member)(
const ListResult &), Tcaller *
const caller);
523 template<
class Tcaller>
524 inline void setDataCallback(
void(__stdcall Tcaller::*
const member)(
const DataRequestRecord &), Tcaller *
const caller);
533 template<
class Tcaller>
534 inline void setLogCallback(
void(__stdcall Tcaller::*
const member)(
const LogRecord &,
LogSource), Tcaller *
const caller);
547 template<
class Tcaller>
548 inline void setCommandResultCallback(
void(__stdcall Tcaller::*
const member)(
const Command &), Tcaller *
const caller);
559 template<
class Tcaller>
560 inline void setResponseCallback(
void(__stdcall Tcaller::*
const member)(
const Command &), Tcaller *
const caller);
566#pragma warning( suppress: 4251 )
567 const std::unique_ptr<Private> d;
569 friend class Private;
580 template<
class Tcaller>
586 template<
class Tcaller>
592 template<
class Tcaller>
598 template<
class Tcaller>
601 setLogCallback(std::bind(member, caller, std::placeholders::_1, std::placeholders::_2));
604 template<
class Tcaller>
610 template<
class Tcaller>
WASimCommander Client implementation. Handles all aspects of communication with the WASimCommander Se...
bool isInitialized() const
Check if simulator network link is established.
bool isConnected() const
Check WASimCommander server connection status.
void setDataCallback(dataCallback_t cb)
Sets a callback for value update data arriving from the server. Pass a nullptr value to remove a prev...
uint32_t defaultTimeout() const
Get the current default server response timeout value, which is used in all network requests....
HRESULT getLocalVariable(const std::string &variableName, double *pfResult, const std::string &unitName=std::string())
A convenience version of getVariable(VariableRequest(variableName, false, unitName),...
HRESULT executeCalculatorCode(const std::string &code, WASimCommander::Enums::CalcResultType resultType=WASimCommander::Enums::CalcResultType::None, double *pfResult=nullptr, std::string *psResult=nullptr) const
Run a string of MSFS Gauge API calculator code in RPN format, possibly with some kind of result expec...
HRESULT getOrCreateLocalVariable(const std::string &variableName, double *pfResult, double defaultValue=0.0, const std::string &unitName=std::string())
Gets the value of a local variable just like getLocalVariable() but will also create the variable on ...
uint32_t clientVersion() const
Return the current WASimClient version number. Version numbers are in "BCD" format: MAJOR << 24 | MIN...
HRESULT getVariable(const VariableRequest &variable, double *pfResult, std::string *psResult=nullptr)
Get a Variable value by name, with optional named unit type. This is primarily useful for local ('L')...
ClientStatus status() const
Get current connection status of this client.
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 connectSimulator(uint32_t timeout=0)
Initialize the simulator network link and set up minimum necessary for WASimCommander server ping or ...
HRESULT connectServer(uint32_t timeout=0)
Connect to WASimCommander server. This will implicitly call connectSimulator() first if it hasn't alr...
void setNetworkConfigurationId(int configId)
SimConnect is used for the network layer. This setting specifies the SimConnect.cfg index to use,...
HRESULT setSimVarVariable(const std::string &variableName, const std::string &stringValue)
Sets a string value on an 'A' (aka "SimVar" / "Simulator Variable") type variable....
WASimClient(uint32_t clientId, const std::string &configFile=std::string())
Instantiate the client with a unique ID and optional configuration file path.
HRESULT setOrCreateLocalVariable(const std::string &variableName, const double value, const std::string &unitName=std::string())
Set a Local Variable value by variable name, creating it first if it does not already exist....
HRESULT setVariable(const VariableRequest &variable, const double value)
Set a Variable value by name, with optional named unit type. Although any settable variable type can ...
void setCommandResultCallback(commandCallback_t cb)
Sets a callback for delivering command results returned by the server. Pass a nullptr value to remove...
void disconnectSimulator()
Shut down all network connections (and disconnect WASimCommander server if connected)....
void setListResultsCallback(listResultsCallback_t cb)
Sets a callback for list results arriving from the server. Pass a nullptr value to remove a previousl...
HRESULT setSimVarVariable(const std::string &variableName, uint8_t index, const std::string &unitName, double value)
Sets a numeric value on an indexed 'A' (aka "SimVar" / "Simulator Variable") type variable....
uint32_t pingServer(uint32_t timeout=0)
Check if WASimCommander Server exists (Simulator running, the WASIM module is installed and working)....
uint32_t serverVersion() const
Return the version number of the last-connected, or successfully pinged, WASimModule (sever),...
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 index, const std::string &stringValue)
Sets a string value on an indexed 'A' (aka "SimVar" / "Simulator Variable") type variable....
int networkConfigurationId() const
SimConnect is used for the network layer. This setting specifies the SimConnect.cfg index to use....
void disconnectServer()
Disconnect from the WASimCommander server. This does not close the Simulator network connection (use ...
void setClientEventCallback(clientEventCallback_t cb)
Sets a callback for Client event updates which indicate status changes. Pass a nullptr value to remov...
HRESULT setLocalVariable(const std::string &variableName, const double value, const std::string &unitName=std::string())
A convenience version of setVariable() for Local variable types. Equivalent to setVariable(VariableRe...
void setDefaultTimeout(uint32_t ms)
Get current connection status of this client.
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 ListResult &)> listResultsCallback_t
Callback function for delivering list results, eg. of local variables sent from Server.
LogSource
Log entry source, Client or Server.
@ Client
Log record from WASimClient.
std::function< void __stdcall(const ClientEvent &)> clientEventCallback_t
Callback function for Client events.
std::function< void __stdcall(const DataRequestRecord &)> dataCallback_t
Callback function for subscription result data.
std::function< void __stdcall(const Command &)> commandCallback_t
Callback function for commands sent from server.
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 LogRecord &, LogSource)> logCallback_t
Callback function for log entries (from both Client and Server).
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.
@ DataRequest
Saved value subscription for current Client, indexed by requestId and nameOrCode values....
@ 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...