Skip to content

Commit

Permalink
feat: system-events (#2)
Browse files Browse the repository at this point in the history
* fix documentation issues

* introduce the system event wrapper class

* add the system event id management to the connection

* export the system event functions and classes

* extend the dispatcher to process subscribed system events

* introduce system event return types

* export the C++ wrapper for the system events

* introduce the different system event types

* export the functions to subscribe and unsubscribe the system events

* extend the receiver to process system events

* add a missing break for the case

* extend the receiver to subscribe and unsubscribe to system events

* publish the new build of the wrapper

* increase the package version
  • Loading branch information
svengcz authored Jul 7, 2023
1 parent 67194fc commit 9fa6618
Show file tree
Hide file tree
Showing 19 changed files with 576 additions and 105 deletions.
Binary file modified dist/libs/simconnect.node
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flybywiresim/msfs-nodejs",
"version": "0.2.0",
"version": "0.3.0",
"description": "Wrapper around the MSFS SDK for Node.JS applications",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand Down
3 changes: 2 additions & 1 deletion src/bindings/simconnect/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"dispatcher.cc",
"helper.cc",
"simconnect.cc",
"simulatordataarea.cc"
"simulatordataarea.cc",
"systemevent.cc"
],
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
Expand Down
16 changes: 15 additions & 1 deletion src/bindings/simconnect/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Connection::Connection(const Napi::CallbackInfo& info) :
_isConnected(false),
_lastError(),
_clientDataIds(),
_simulatorDataIds() { }
_simulatorDataIds(),
_systemEventIds() { }

Connection::~Connection() {
if (this->_simConnect != 0) {
Expand Down Expand Up @@ -58,6 +59,19 @@ void Connection::addSimulatorDataId(SIMCONNECT_DATA_DEFINITION_ID simulatorDataI
this->_simulatorDataIds.push_back(simulatorDataId);
}

bool Connection::systemEventIdExists(std::uint32_t systemEventId) const {
for (const auto& id : std::as_const(this->_systemEventIds)) {
if (id == systemEventId)
return true;
}

return false;
}

void Connection::addSystemEventId(std::uint32_t systemEventId) {
this->_systemEventIds.push_back(systemEventId);
}

void Connection::connectionEstablished(bool established) {
this->_isConnected = established;
}
Expand Down
212 changes: 112 additions & 100 deletions src/bindings/simconnect/connection.h
Original file line number Diff line number Diff line change
@@ -1,100 +1,112 @@
#pragma once

#include <string>
#include <list>

#include <napi.h>
#include <Windows.h>
#include <SimConnect.h>

namespace msfs {
namespace simconnect {
class ClientDataArea;
class Dispatcher;

class Connection : public Napi::ObjectWrap<Connection> {
private:
HANDLE _simConnect;
bool _isConnected;
std::string _lastError;
std::list<SIMCONNECT_CLIENT_DATA_ID> _clientDataIds;
std::list<SIMCONNECT_DATA_DEFINITION_ID> _simulatorDataIds;

void close();

public:
Connection(const Napi::CallbackInfo& info);
~Connection();

/**
* @brief Returns the current HANDLE for the connection
* @return The handle for the connection
*/
HANDLE simConnect() const;
/**
* @brief Checks if the connection is established to the server
* @return True if the connection is established, else false
*/
bool isConnected() const;
/**
* @brief Checks if a client data ID exists
* @param clientDataId The client data ID
* @return True if the ID is already registered, else false
*/
bool clientDataIdExists(SIMCONNECT_CLIENT_DATA_ID clientDataId) const;
/**
* @brief Adds the client data ID to the managed list
* @param clientDataId The client data ID
*/
void addClientDataId(SIMCONNECT_CLIENT_DATA_ID clientDataId);
/**
* @brief Checks if a simulator data ID exists
* @param clientDataId The simulator data ID
* @return True if the ID is already registered, else false
*/
bool simulatorDataIdExists(SIMCONNECT_DATA_DEFINITION_ID simulatorDataId) const;
/**
* @brief Adds the simulator data ID to the managed list
* @param simulatorDataId The simulator data ID
*/
void addSimulatorDataId(SIMCONNECT_DATA_DEFINITION_ID simulatorDataId);
/**
* @brief Marks if the connection with the server response is established
* @param established True if the server response was received, else false
*/
void connectionEstablished(bool established);
/**
* @brief Opens a SimConnect connection to the server
* @param info The callback block where the first element needs to be the client's name
* @return Returns a Napi::Boolean and sets the last error, if the function returned false
* @throw Excpetions if the arguments do not match
*/
Napi::Value open(const Napi::CallbackInfo& info);
/**
* @brief Closes a SimConnect connection
* @param info The parameter block without additional parameters
*/
void close(const Napi::CallbackInfo& info);
/**
* @brief Checks if the SimConnect connection is actove
* @param info The parameter block without additional parameters
* @return True if the connection is active, else false
*/
Napi::Value isConnected(const Napi::CallbackInfo& info);
/**
* @brief Creates anew client data area on the server
* @param info The info block with the paramaters clientDataId, size and readOnly
* @return True if the creation was successful, else false with the last error set
*/
Napi::Value createClientDataArea(const Napi::CallbackInfo& info);
/**
* @brief Returns the last error of an other call
* @param info The parameter block without additional parameters
* @return Returns Napi::String with the last error
*/
Napi::Value lastError(const Napi::CallbackInfo& info);

static Napi::Object initialize(Napi::Env env, Napi::Object exports);
};
}
}
#pragma once

#include <string>
#include <list>

#include <napi.h>
#include <Windows.h>
#include <SimConnect.h>

namespace msfs {
namespace simconnect {
class ClientDataArea;
class Dispatcher;

class Connection : public Napi::ObjectWrap<Connection> {
private:
HANDLE _simConnect;
bool _isConnected;
std::string _lastError;
std::list<SIMCONNECT_CLIENT_DATA_ID> _clientDataIds;
std::list<SIMCONNECT_DATA_DEFINITION_ID> _simulatorDataIds;
std::list<std::uint32_t> _systemEventIds;

void close();

public:
Connection(const Napi::CallbackInfo& info);
~Connection();

/**
* @brief Returns the current HANDLE for the connection
* @return The handle for the connection
*/
HANDLE simConnect() const;
/**
* @brief Checks if the connection is established to the server
* @return True if the connection is established, else false
*/
bool isConnected() const;
/**
* @brief Checks if a client data ID exists
* @param clientDataId The client data ID
* @return True if the ID is already registered, else false
*/
bool clientDataIdExists(SIMCONNECT_CLIENT_DATA_ID clientDataId) const;
/**
* @brief Adds the client data ID to the managed list
* @param clientDataId The client data ID
*/
void addClientDataId(SIMCONNECT_CLIENT_DATA_ID clientDataId);
/**
* @brief Checks if a simulator data ID exists
* @param simulatorDataId The simulator data ID
* @return True if the ID is already registered, else false
*/
bool simulatorDataIdExists(SIMCONNECT_DATA_DEFINITION_ID simulatorDataId) const;
/**
* @brief Adds the simulator data ID to the managed list
* @param simulatorDataId The simulator data ID
*/
void addSimulatorDataId(SIMCONNECT_DATA_DEFINITION_ID simulatorDataId);
/**
* @brief Checks if a system event ID exists
* @param systemEventId The system event ID
* @return True if the ID is already registered, else false
*/
bool systemEventIdExists(std::uint32_t systemEventId) const;
/**
* @brief Adds the system event ID to the managed list
* @param systemEventId The system event ID
*/
void addSystemEventId(std::uint32_t systemEventId);
/**
* @brief Marks if the connection with the server response is established
* @param established True if the server response was received, else false
*/
void connectionEstablished(bool established);
/**
* @brief Opens a SimConnect connection to the server
* @param info The callback block where the first element needs to be the client's name
* @return Returns a Napi::Boolean and sets the last error, if the function returned false
* @throw Excpetions if the arguments do not match
*/
Napi::Value open(const Napi::CallbackInfo& info);
/**
* @brief Closes a SimConnect connection
* @param info The parameter block without additional parameters
*/
void close(const Napi::CallbackInfo& info);
/**
* @brief Checks if the SimConnect connection is actove
* @param info The parameter block without additional parameters
* @return True if the connection is active, else false
*/
Napi::Value isConnected(const Napi::CallbackInfo& info);
/**
* @brief Creates anew client data area on the server
* @param info The info block with the paramaters clientDataId, size and readOnly
* @return True if the creation was successful, else false with the last error set
*/
Napi::Value createClientDataArea(const Napi::CallbackInfo& info);
/**
* @brief Returns the last error of an other call
* @param info The parameter block without additional parameters
* @return Returns Napi::String with the last error
*/
Napi::Value lastError(const Napi::CallbackInfo& info);

static Napi::Object initialize(Napi::Env env, Napi::Object exports);
};
}
}
Loading

0 comments on commit 9fa6618

Please sign in to comment.