-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build one package per component of the MSFS SDK
- Loading branch information
Showing
7 changed files
with
120 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "helper.h" | ||
#include "wrapper.h" | ||
|
||
#include <SimConnect.h> | ||
|
||
using namespace msfs::simconnect; | ||
|
||
Wrapper::Wrapper(const Napi::CallbackInfo& info) : | ||
Napi::ObjectWrap<Wrapper>(info), | ||
_simConnect(0), | ||
_lastError() { } | ||
|
||
Wrapper::~Wrapper() { | ||
this->close(); | ||
} | ||
|
||
Napi::Value Wrapper::lastError(const Napi::CallbackInfo& info) { | ||
Napi::Env env = info.Env(); | ||
return Napi::String::New(env, this->_lastError); | ||
} | ||
|
||
Napi::Value Wrapper::createNewItem(const Napi::CallbackInfo& info) { | ||
Napi::FunctionReference* constructor = info.Env().GetInstanceData<Napi::FunctionReference>(); | ||
return constructor->New({}); | ||
} | ||
|
||
Napi::Object Wrapper::initialize(Napi::Env env, Napi::Object exports) { | ||
Napi::Function func = DefineClass(env, "SimConnect", { | ||
InstanceMethod<&Wrapper::open>("open", static_cast<napi_property_attributes>(napi_writable | napi_configurable)), | ||
InstanceMethod<&Wrapper::close>("close", static_cast<napi_property_attributes>(napi_writable | napi_configurable)), | ||
InstanceMethod<&Wrapper::lastError>("lastError", static_cast<napi_property_attributes>(napi_writable | napi_configurable)), | ||
StaticMethod<&Wrapper::createNewItem>("createNewItem", static_cast<napi_property_attributes>(napi_writable | napi_configurable)), | ||
}); | ||
|
||
Napi::FunctionReference* constructor = new Napi::FunctionReference(); | ||
|
||
*constructor = Napi::Persistent(func); | ||
exports.Set("SimConnect", func); | ||
|
||
env.SetInstanceData<Napi::FunctionReference>(constructor); | ||
|
||
return exports; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#pragma once | ||
|
||
#include <Windows.h> | ||
#include <SimConnect.h> | ||
#include <napi.h> | ||
|
||
namespace msfs { | ||
namespace simconnect { | ||
class Wrapper : public Napi::ObjectWrap<Wrapper> { | ||
private: | ||
HANDLE _simConnect; | ||
std::string _lastError; | ||
|
||
void close(); | ||
public: | ||
/** | ||
* @brief Constructs a new Wrapper object | ||
* @param info Parameter block for the Wrapper | ||
*/ | ||
Wrapper(const Napi::CallbackInfo& info); | ||
/** | ||
* @brief Destroys the Wrapper object | ||
*/ | ||
~Wrapper(); | ||
|
||
/** | ||
* @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 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); | ||
|
||
/** | ||
* @brief Creates a new Wrapper object | ||
* @param info Parameter block for the new object | ||
* @return Returns the newly created object | ||
*/ | ||
static Napi::Value createNewItem(const Napi::CallbackInfo& info); | ||
/** | ||
* @brief Registers all binding functions in the JS environment | ||
* @param env The javascript environment | ||
* @param exports The collection of exported functions | ||
* @return The extended exported functions | ||
*/ | ||
static Napi::Object initialize(Napi::Env env, Napi::Object exports); | ||
}; | ||
} | ||
} |