Skip to content

Commit 9fa6618

Browse files
authored
feat: system-events (#2)
* 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
1 parent 67194fc commit 9fa6618

File tree

19 files changed

+576
-105
lines changed

19 files changed

+576
-105
lines changed

dist/libs/simconnect.node

19.5 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@flybywiresim/msfs-nodejs",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "Wrapper around the MSFS SDK for Node.JS applications",
55
"main": "dist/index.js",
66
"module": "dist/index.esm.js",

src/bindings/simconnect/binding.gyp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"dispatcher.cc",
99
"helper.cc",
1010
"simconnect.cc",
11-
"simulatordataarea.cc"
11+
"simulatordataarea.cc",
12+
"systemevent.cc"
1213
],
1314
"cflags!": [ "-fno-exceptions" ],
1415
"cflags_cc!": [ "-fno-exceptions" ],

src/bindings/simconnect/connection.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Connection::Connection(const Napi::CallbackInfo& info) :
1212
_isConnected(false),
1313
_lastError(),
1414
_clientDataIds(),
15-
_simulatorDataIds() { }
15+
_simulatorDataIds(),
16+
_systemEventIds() { }
1617

1718
Connection::~Connection() {
1819
if (this->_simConnect != 0) {
@@ -58,6 +59,19 @@ void Connection::addSimulatorDataId(SIMCONNECT_DATA_DEFINITION_ID simulatorDataI
5859
this->_simulatorDataIds.push_back(simulatorDataId);
5960
}
6061

62+
bool Connection::systemEventIdExists(std::uint32_t systemEventId) const {
63+
for (const auto& id : std::as_const(this->_systemEventIds)) {
64+
if (id == systemEventId)
65+
return true;
66+
}
67+
68+
return false;
69+
}
70+
71+
void Connection::addSystemEventId(std::uint32_t systemEventId) {
72+
this->_systemEventIds.push_back(systemEventId);
73+
}
74+
6175
void Connection::connectionEstablished(bool established) {
6276
this->_isConnected = established;
6377
}
Lines changed: 112 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,112 @@
1-
#pragma once
2-
3-
#include <string>
4-
#include <list>
5-
6-
#include <napi.h>
7-
#include <Windows.h>
8-
#include <SimConnect.h>
9-
10-
namespace msfs {
11-
namespace simconnect {
12-
class ClientDataArea;
13-
class Dispatcher;
14-
15-
class Connection : public Napi::ObjectWrap<Connection> {
16-
private:
17-
HANDLE _simConnect;
18-
bool _isConnected;
19-
std::string _lastError;
20-
std::list<SIMCONNECT_CLIENT_DATA_ID> _clientDataIds;
21-
std::list<SIMCONNECT_DATA_DEFINITION_ID> _simulatorDataIds;
22-
23-
void close();
24-
25-
public:
26-
Connection(const Napi::CallbackInfo& info);
27-
~Connection();
28-
29-
/**
30-
* @brief Returns the current HANDLE for the connection
31-
* @return The handle for the connection
32-
*/
33-
HANDLE simConnect() const;
34-
/**
35-
* @brief Checks if the connection is established to the server
36-
* @return True if the connection is established, else false
37-
*/
38-
bool isConnected() const;
39-
/**
40-
* @brief Checks if a client data ID exists
41-
* @param clientDataId The client data ID
42-
* @return True if the ID is already registered, else false
43-
*/
44-
bool clientDataIdExists(SIMCONNECT_CLIENT_DATA_ID clientDataId) const;
45-
/**
46-
* @brief Adds the client data ID to the managed list
47-
* @param clientDataId The client data ID
48-
*/
49-
void addClientDataId(SIMCONNECT_CLIENT_DATA_ID clientDataId);
50-
/**
51-
* @brief Checks if a simulator data ID exists
52-
* @param clientDataId The simulator data ID
53-
* @return True if the ID is already registered, else false
54-
*/
55-
bool simulatorDataIdExists(SIMCONNECT_DATA_DEFINITION_ID simulatorDataId) const;
56-
/**
57-
* @brief Adds the simulator data ID to the managed list
58-
* @param simulatorDataId The simulator data ID
59-
*/
60-
void addSimulatorDataId(SIMCONNECT_DATA_DEFINITION_ID simulatorDataId);
61-
/**
62-
* @brief Marks if the connection with the server response is established
63-
* @param established True if the server response was received, else false
64-
*/
65-
void connectionEstablished(bool established);
66-
/**
67-
* @brief Opens a SimConnect connection to the server
68-
* @param info The callback block where the first element needs to be the client's name
69-
* @return Returns a Napi::Boolean and sets the last error, if the function returned false
70-
* @throw Excpetions if the arguments do not match
71-
*/
72-
Napi::Value open(const Napi::CallbackInfo& info);
73-
/**
74-
* @brief Closes a SimConnect connection
75-
* @param info The parameter block without additional parameters
76-
*/
77-
void close(const Napi::CallbackInfo& info);
78-
/**
79-
* @brief Checks if the SimConnect connection is actove
80-
* @param info The parameter block without additional parameters
81-
* @return True if the connection is active, else false
82-
*/
83-
Napi::Value isConnected(const Napi::CallbackInfo& info);
84-
/**
85-
* @brief Creates anew client data area on the server
86-
* @param info The info block with the paramaters clientDataId, size and readOnly
87-
* @return True if the creation was successful, else false with the last error set
88-
*/
89-
Napi::Value createClientDataArea(const Napi::CallbackInfo& info);
90-
/**
91-
* @brief Returns the last error of an other call
92-
* @param info The parameter block without additional parameters
93-
* @return Returns Napi::String with the last error
94-
*/
95-
Napi::Value lastError(const Napi::CallbackInfo& info);
96-
97-
static Napi::Object initialize(Napi::Env env, Napi::Object exports);
98-
};
99-
}
100-
}
1+
#pragma once
2+
3+
#include <string>
4+
#include <list>
5+
6+
#include <napi.h>
7+
#include <Windows.h>
8+
#include <SimConnect.h>
9+
10+
namespace msfs {
11+
namespace simconnect {
12+
class ClientDataArea;
13+
class Dispatcher;
14+
15+
class Connection : public Napi::ObjectWrap<Connection> {
16+
private:
17+
HANDLE _simConnect;
18+
bool _isConnected;
19+
std::string _lastError;
20+
std::list<SIMCONNECT_CLIENT_DATA_ID> _clientDataIds;
21+
std::list<SIMCONNECT_DATA_DEFINITION_ID> _simulatorDataIds;
22+
std::list<std::uint32_t> _systemEventIds;
23+
24+
void close();
25+
26+
public:
27+
Connection(const Napi::CallbackInfo& info);
28+
~Connection();
29+
30+
/**
31+
* @brief Returns the current HANDLE for the connection
32+
* @return The handle for the connection
33+
*/
34+
HANDLE simConnect() const;
35+
/**
36+
* @brief Checks if the connection is established to the server
37+
* @return True if the connection is established, else false
38+
*/
39+
bool isConnected() const;
40+
/**
41+
* @brief Checks if a client data ID exists
42+
* @param clientDataId The client data ID
43+
* @return True if the ID is already registered, else false
44+
*/
45+
bool clientDataIdExists(SIMCONNECT_CLIENT_DATA_ID clientDataId) const;
46+
/**
47+
* @brief Adds the client data ID to the managed list
48+
* @param clientDataId The client data ID
49+
*/
50+
void addClientDataId(SIMCONNECT_CLIENT_DATA_ID clientDataId);
51+
/**
52+
* @brief Checks if a simulator data ID exists
53+
* @param simulatorDataId The simulator data ID
54+
* @return True if the ID is already registered, else false
55+
*/
56+
bool simulatorDataIdExists(SIMCONNECT_DATA_DEFINITION_ID simulatorDataId) const;
57+
/**
58+
* @brief Adds the simulator data ID to the managed list
59+
* @param simulatorDataId The simulator data ID
60+
*/
61+
void addSimulatorDataId(SIMCONNECT_DATA_DEFINITION_ID simulatorDataId);
62+
/**
63+
* @brief Checks if a system event ID exists
64+
* @param systemEventId The system event ID
65+
* @return True if the ID is already registered, else false
66+
*/
67+
bool systemEventIdExists(std::uint32_t systemEventId) const;
68+
/**
69+
* @brief Adds the system event ID to the managed list
70+
* @param systemEventId The system event ID
71+
*/
72+
void addSystemEventId(std::uint32_t systemEventId);
73+
/**
74+
* @brief Marks if the connection with the server response is established
75+
* @param established True if the server response was received, else false
76+
*/
77+
void connectionEstablished(bool established);
78+
/**
79+
* @brief Opens a SimConnect connection to the server
80+
* @param info The callback block where the first element needs to be the client's name
81+
* @return Returns a Napi::Boolean and sets the last error, if the function returned false
82+
* @throw Excpetions if the arguments do not match
83+
*/
84+
Napi::Value open(const Napi::CallbackInfo& info);
85+
/**
86+
* @brief Closes a SimConnect connection
87+
* @param info The parameter block without additional parameters
88+
*/
89+
void close(const Napi::CallbackInfo& info);
90+
/**
91+
* @brief Checks if the SimConnect connection is actove
92+
* @param info The parameter block without additional parameters
93+
* @return True if the connection is active, else false
94+
*/
95+
Napi::Value isConnected(const Napi::CallbackInfo& info);
96+
/**
97+
* @brief Creates anew client data area on the server
98+
* @param info The info block with the paramaters clientDataId, size and readOnly
99+
* @return True if the creation was successful, else false with the last error set
100+
*/
101+
Napi::Value createClientDataArea(const Napi::CallbackInfo& info);
102+
/**
103+
* @brief Returns the last error of an other call
104+
* @param info The parameter block without additional parameters
105+
* @return Returns Napi::String with the last error
106+
*/
107+
Napi::Value lastError(const Napi::CallbackInfo& info);
108+
109+
static Napi::Object initialize(Napi::Env env, Napi::Object exports);
110+
};
111+
}
112+
}

0 commit comments

Comments
 (0)