25ref class WASimClient::Private
37 [UnmanagedFunctionPointer(CallingConvention::StdCall)]
39 [UnmanagedFunctionPointer(CallingConvention::StdCall)]
41 [UnmanagedFunctionPointer(CallingConvention::StdCall)]
43 [UnmanagedFunctionPointer(CallingConvention::StdCall)]
45 [UnmanagedFunctionPointer(CallingConvention::StdCall)]
47 [UnmanagedFunctionPointer(CallingConvention::StdCall)]
50 [MarshalAs(UnmanagedType::FunctionPtr)]
51 ClientEventCallback ^clientEventCb;
52 [MarshalAs(UnmanagedType::FunctionPtr)]
53 ListResultsCallback ^listResultsCb;
54 [MarshalAs(UnmanagedType::FunctionPtr)]
56 [MarshalAs(UnmanagedType::FunctionPtr)]
58 [MarshalAs(UnmanagedType::FunctionPtr)]
59 CommandResultCallback ^resultCb;
60 [MarshalAs(UnmanagedType::FunctionPtr)]
61 ResponseCallback ^responseCb;
63 ClientEventDelegate ^clientEventHandler;
64 ListResultsDelegate ^listResultsHandler;
65 DataDelegate ^dataHandler;
66 LogDelegate ^logHandler;
67 CommandResultDelegate ^resultHandler;
68 ResponseDelegate ^responseHandler;
73 clientEventCb = gcnew ClientEventCallback(
this, &Private::onClientEvent);
74 IntPtr pCb = Marshal::GetFunctionPointerForDelegate(clientEventCb);
77 listResultsCb = gcnew ListResultsCallback(
this, &Private::onListResult);
78 pCb = Marshal::GetFunctionPointerForDelegate(listResultsCb);
81 dataCb = gcnew DataCallback(
this, &Private::onDataResult);
82 pCb = Marshal::GetFunctionPointerForDelegate(dataCb);
85 logCb = gcnew LogCallback(
this, &Private::onLogRecord);
86 pCb = Marshal::GetFunctionPointerForDelegate(logCb);
89 resultCb = gcnew CommandResultCallback(
this, &Private::onCommandResult);
90 pCb = Marshal::GetFunctionPointerForDelegate(resultCb);
93 responseCb = gcnew ResponseCallback(
this, &Private::onServerResponse);
94 pCb = Marshal::GetFunctionPointerForDelegate(responseCb);
100 if (clientEventHandler)
106 if (listResultsHandler)
107 listResultsHandler->Invoke(gcnew
ListResult(lr));
119 logHandler->Invoke(gcnew
LogRecord(lr), (LogSource)s);
125 resultHandler->Invoke(gcnew
Command(cmd));
131 responseHandler->Invoke(gcnew
Command(cmd));
134 inline HR executeCalculatorCode(String ^ code, CalcResultType resultType, interior_ptr<double> pfResult, interior_ptr<String ^> psResult)
136 pin_ptr<double> pf = pfResult;
139 marshal_as<std::string>(code),
141 pf, psResult ? &s :
nullptr
144 *psResult = marshal_as<String ^>(s);
148 inline HR getVariable(
VariableRequest ^var, interior_ptr<double> pfResult, interior_ptr<String ^> psResult)
150 pin_ptr<double> pf = pfResult;
154 *psResult = marshal_as<String ^>(s);
158 inline HR getOrCreateLocalVariable(String ^ name, interior_ptr<String ^> unit,
double defaultValue, interior_ptr<double> pfResult)
160 pin_ptr<double> pf = pfResult;
162 return (
HR)client->
getOrCreateLocalVariable(marshal_as<std::string>(name), pf, defaultValue, marshal_as<std::string>((String ^)*unit));
177 delete clientEventHandler;
178 delete listResultsHandler;
181 delete resultHandler;
182 delete responseHandler;
184 delete clientEventCb;
185 delete listResultsCb;
195WASimClient::WASimClient(UInt32 clientId, String ^configFile) :
197 d { gcnew Private(this, m_client) }
203WASimClient::~WASimClient()
219 return d->executeCalculatorCode(code, resultType, &pfResult,
nullptr);
223 return d->executeCalculatorCode(code, resultType,
nullptr, &psResult);
227 return d->executeCalculatorCode(code, resultType, &pfResult, &psResult);
231 return d->getVariable(var, &pfResult,
nullptr);
235 return d->getVariable(var,
nullptr, &psResult);
239 return d->getVariable(var, &pfResult, &psResult);
243 return d->getOrCreateLocalVariable(variableName,
nullptr, defaultValue, &pfResult);
247 return d->getOrCreateLocalVariable(variableName, &unitName, defaultValue, &pfResult);
252 const std::vector<WASimCommander::Client::DataRequestRecord> &res = m_client->
dataRequests();
253 array<DataRequestRecord ^> ^ret = gcnew array<DataRequestRecord ^>((
int)res.size());
255 for (
const auto &dr : res)
263 array<UInt32> ^ret = gcnew array<UInt32>((
int)res.size());
265 pin_ptr<UInt32> pp = &ret[0];
266 memcpy(pp, res.data(), res.size() * 4);
273 const std::vector<WASimCommander::Client::RegisteredEvent> &res = m_client->
registeredEvents();
274 array<RegisteredEvent ^> ^ret = gcnew array<RegisteredEvent ^>((
int)res.size());
276 for (
const auto &ev : res)
281#define DELEGATE_HANDLER(E, D, H) \
282 void WASimClient::E::add(D ^ h) { H += h; } \
283 void WASimClient::E::remove(D ^ h) { H -= h; }
285DELEGATE_HANDLER(OnClientEvent, ClientEventDelegate, d->clientEventHandler)
286DELEGATE_HANDLER(OnListResults, ListResultsDelegate, d->listResultsHandler)
287DELEGATE_HANDLER(OnDataReceived, DataDelegate, d->dataHandler)
288DELEGATE_HANDLER(OnLogRecordReceived, LogDelegate, d->logHandler)
289DELEGATE_HANDLER(OnCommandResult, CommandResultDelegate, d->resultHandler)
290DELEGATE_HANDLER(OnResponseReceived, ResponseDelegate, d->responseHandler)
292#undef DELEGATE_HANDLER
C+/CLI wrapper implementation of WASimCommander::Client::WASimClient. See documentation for the C++ c...
HR getVariable(VariableRequest ^ var, [Out] double % pfResult)
Get the value of a variable with a numeric result type. This is the most typical use case since most ...
array< UInt32 > ^ dataRequestIdsList()
See WASimClient::dataRequestIdsList().
HR getOrCreateLocalVariable(String ^ variableName, double defaultValue, [Out] double % pfResult)
array< DataRequestRecord ^> ^ dataRequests()
See WASimClient::dataRequests().
WASimClient(UInt32 clientId)
Construct a new client with the given ID. The ID must be unique among any other possible clients and ...
void disconnectSimulator()
See WASimClient::disconnectSimulator().
HR executeCalculatorCode(String^ code)
Execute calculator code without result
array< RegisteredEvent ^> ^ registeredEvents()
See WASimClient::registeredEvents().
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...
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 ...
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')...
void setLogCallback(logCallback_t cb)
Sets a callback for logging activity, both from the server and the client itself. Pass a nullptr valu...
std::vector< DataRequestRecord > dataRequests() const
Returns a list of all data requests which have been added to the Client so far. (These are returned b...
void setCommandResultCallback(commandCallback_t cb)
Sets a callback for delivering command results returned by the server. Pass a nullptr value to remove...
std::vector< uint32_t > dataRequestIdsList() const
Returns a list of all DataRequest::requestIds which have been added to the Client so far.
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....
void setClientEventCallback(clientEventCallback_t cb)
Sets a callback for Client event updates which indicate status changes. Pass a nullptr value to remov...
std::vector< RegisteredEvent > registeredEvents() const
Returns a list of all registered events which have been added to the Client with registerEvent()....
WASimCommander::CLI::Client namespace. Implementation of the C++ WASimClient as a C++/CLI ....
HR
Method return status values; HRESULT "alias"
WASimCommander::CLI namespace. Container for implementation of the C++ WASimCommander API and WASimCl...
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.
std::function< void __stdcall(const ClientEvent &)> clientEventCallback_t
Callback function for Client events.
Client Event data, delivered via callback.
Structure for delivering list results, eg. of local variables sent from Server.
CalcResultType
The type of result that calculator code is expected to produce.
WASimCommander main namespace. Defines constants and structs used in Client-Server interactions....
Client Event data, delivered via callback.
Command data structure. The member contents depend on the command type as described in each command t...
DataRequestRecord inherits and extends WASimCommander::CLI::Structs::DataRequest with data pertinent ...
Structure for delivering list results, eg. of local variables sent from Server.
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...
DataRequestRecord inherits and extends WASimCommander::DataRequest with data pertinent for use by a d...
Command data structure. The member contents depend on the command type as described in each command t...