Skip to content

Commit

Permalink
Fix usage of deprecated v8 apis
Browse files Browse the repository at this point in the history
  • Loading branch information
apihlaja committed Jul 2, 2019
1 parent fbb0f0c commit c6feee0
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 153 deletions.
92 changes: 46 additions & 46 deletions src/cpp/IRSDKWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,64 @@
#include <string>
#include <vector>

namespace NodeIrSdk {
namespace NodeIrSdk
{

class IRSDKWrapper
{
public:
IRSDKWrapper();
~IRSDKWrapper();

bool startup();
void shutdown();

bool isInitialized() const;
bool isConnected() const;
class IRSDKWrapper
{
public:
IRSDKWrapper();
~IRSDKWrapper();

bool updateTelemetry(); // returns true if telemetry update available
bool updateSessionInfo(); // returns true if session info update available
bool startup();
void shutdown();

const std::string getSessionInfo() const; // returns yaml string
bool isInitialized() const;
bool isConnected() const;

struct TelemetryVar
{
irsdk_varHeader* header;
irsdk_VarType type;
bool updateTelemetry(); // returns true if telemetry update available
bool updateSessionInfo(); // returns true if session info update available

union { // choose correct based on irsdk_VarType
char* value;
float* floatValue;
int* intValue;
bool* boolValue;
double* doubleValue;
};
const std::string getSessionInfo() const; // returns yaml string

TelemetryVar(irsdk_varHeader* varHeader);
~TelemetryVar();
struct TelemetryVar
{
irsdk_varHeader *header;
irsdk_VarType type;

union { // choose correct based on irsdk_VarType
char *value;
float *floatValue;
int *intValue;
bool *boolValue;
double *doubleValue;
};

const std::vector<irsdk_varHeader*> getVarHeaders() const;
TelemetryVar(irsdk_varHeader *varHeader);
~TelemetryVar();
};

bool getVarVal(TelemetryVar& var) const;
const std::vector<irsdk_varHeader *> getVarHeaders() const;

const double getLastTelemetryUpdateTS() const; // returns JS compatible TS
bool getVarVal(TelemetryVar &var) const;

private:
HANDLE hMemMapFile;
const char *pSharedMem;
const irsdk_header *pHeader;
int lastTickCount;
int lastSessionInfoUpdate;
time_t lastValidTime;
char* data;
int dataLen;
std::string sessionInfoStr;
const double getLastTelemetryUpdateTS() const; // returns JS compatible TS

std::vector<irsdk_varHeader*> varHeadersArr;
private:
HANDLE hMemMapFile;
const char *pSharedMem;
const irsdk_header *pHeader;
int lastTickCount;
int lastSessionInfoUpdate;
time_t lastValidTime;
char *data;
int dataLen;
std::string sessionInfoStr;

void updateVarHeaders(); // updates map and vector
const char* getSessionInfoStr() const;
std::vector<irsdk_varHeader *> varHeadersArr;

};
void updateVarHeaders(); // updates map and vector
const char *getSessionInfoStr() const;
};

}
} // namespace NodeIrSdk
20 changes: 10 additions & 10 deletions src/cpp/IrSdkBindingHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using namespace v8;
using namespace std;

Handle<Value> NodeIrSdk::convertTelemetryValueToObject(IRSDKWrapper::TelemetryVar& var, const int& index)
Local<Value> NodeIrSdk::convertTelemetryValueToObject(IRSDKWrapper::TelemetryVar& var, const int& index)
{
switch (var.type) {
case irsdk_char:
Expand Down Expand Up @@ -34,10 +34,10 @@ Handle<Value> NodeIrSdk::convertTelemetryValueToObject(IRSDKWrapper::TelemetryVa
}
}

Handle<Value> NodeIrSdk::convertTelemetryVarToObject(IRSDKWrapper::TelemetryVar& var)
Local<Value> NodeIrSdk::convertTelemetryVarToObject(IRSDKWrapper::TelemetryVar& var)
{
if (var.header->count > 1) {
Handle<Array> arr = Nan::New<Array>(var.header->count);
Local<Array> arr = Nan::New<Array>(var.header->count);
for (int i = 0; i < var.header->count; ++i)
{
arr->Set(i, convertTelemetryValueToObject(var, i));
Expand All @@ -50,13 +50,13 @@ Handle<Value> NodeIrSdk::convertTelemetryVarToObject(IRSDKWrapper::TelemetryVar&
}
}

void NodeIrSdk::convertVarHeaderToObject(IRSDKWrapper::TelemetryVar& var, Handle<Object>& obj)
void NodeIrSdk::convertVarHeaderToObject(IRSDKWrapper::TelemetryVar& var, Local<Object>& obj)
{
Nan::Set(obj, Nan::New("name").ToLocalChecked(), Nan::New(var.header->name).ToLocalChecked());
Nan::Set(obj, Nan::New("desc").ToLocalChecked(), Nan::New(var.header->desc).ToLocalChecked());
Nan::Set(obj, Nan::New("unit").ToLocalChecked(), Nan::New(var.header->unit).ToLocalChecked());
Nan::Set(obj, Nan::New("count").ToLocalChecked(), Nan::New(var.header->count));

switch (var.header->type) {
case irsdk_char:
Nan::Set(obj, Nan::New("type").ToLocalChecked(), Nan::New("char").ToLocalChecked());
Expand All @@ -82,7 +82,7 @@ void NodeIrSdk::convertVarHeaderToObject(IRSDKWrapper::TelemetryVar& var, Handle
}
}

Handle<Value> NodeIrSdk::getMaskedValues(const int& val, char* unit)
Local<Value> NodeIrSdk::getMaskedValues(const int& val, char* unit)
{
if (strcmp(unit,"irsdk_Flags") == 0) {
return getValueArr(val, FLAG_MASKS);
Expand All @@ -103,9 +103,9 @@ Handle<Value> NodeIrSdk::getMaskedValues(const int& val, char* unit)
return Nan::New(static_cast<int32_t>(val));
}

Handle<Array> NodeIrSdk::getValueArr(const int& val, const std::vector<NodeIrSdk::MaskName> MASKS)
Local<Array> NodeIrSdk::getValueArr(const int& val, const std::vector<NodeIrSdk::MaskName> MASKS)
{
Handle<Array> arr = Nan::New<Array>();
Local<Array> arr = Nan::New<Array>();
int counter = 0;
for (const auto& mask : MASKS)
{
Expand All @@ -116,7 +116,7 @@ Handle<Array> NodeIrSdk::getValueArr(const int& val, const std::vector<NodeIrSdk
return arr;
}

Handle<Value> NodeIrSdk::getStringValue(const int& val, const std::vector<NodeIrSdk::MaskName>& map)
Local<Value> NodeIrSdk::getStringValue(const int& val, const std::vector<NodeIrSdk::MaskName>& map)
{
for (const auto& mask : map) {
if (mask.val == val) {
Expand All @@ -126,7 +126,7 @@ Handle<Value> NodeIrSdk::getStringValue(const int& val, const std::vector<NodeIr
return Nan::Undefined();
}

NodeIrSdk::MaskName::MaskName(int val, const char* name) :
NodeIrSdk::MaskName::MaskName(int val, const char* name) :
val(val), name(name)
{
}
14 changes: 7 additions & 7 deletions src/cpp/IrSdkBindingHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ using namespace v8;
namespace NodeIrSdk
{

Handle<Value> convertTelemetryValueToObject(IRSDKWrapper::TelemetryVar& var, const int& index);
Handle<Value> convertTelemetryVarToObject(IRSDKWrapper::TelemetryVar& var);
void convertVarHeaderToObject(IRSDKWrapper::TelemetryVar& var, Handle<Object>& obj);
Local<Value> convertTelemetryValueToObject(IRSDKWrapper::TelemetryVar& var, const int& index);
Local<Value> convertTelemetryVarToObject(IRSDKWrapper::TelemetryVar& var);
void convertVarHeaderToObject(IRSDKWrapper::TelemetryVar& var, Local<Object>& obj);


struct MaskName {
Expand All @@ -22,10 +22,10 @@ namespace NodeIrSdk
MaskName(int val, const char* name);
};

Handle<Value> getStringValue(const int& val, const std::vector<MaskName>& map);
Local<Value> getStringValue(const int& val, const std::vector<MaskName>& map);

Handle<Value> getMaskedValues(const int& val, char* unit);
Handle<Array> getValueArr(const int& val, const std::vector<MaskName> MASKS);
Local<Value> getMaskedValues(const int& val, char* unit);
Local<Array> getValueArr(const int& val, const std::vector<MaskName> MASKS);

const std::vector<MaskName> FLAG_MASKS = {
MaskName((int)irsdk_checkered, "Checkered"),
Expand Down Expand Up @@ -58,7 +58,7 @@ namespace NodeIrSdk
MaskName((int)irsdk_startSet, "StartSet"),
MaskName((int)irsdk_startGo, "StartGo")
};

const std::vector<MaskName> PIT_SV_MASKS = {
MaskName((int)irsdk_LFTireChange, "LFTireChange"),
MaskName((int)irsdk_RFTireChange, "RFTireChange"),
Expand Down
Loading

0 comments on commit c6feee0

Please sign in to comment.