|
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