Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/node 10 refetch #211

Merged
merged 8 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ foreach(SD_API_VER ${SD_API_VERS})
set_target_properties(${CURRENT_TARGET} PROPERTIES COMPILE_OPTIONS -DNRF_SD_BLE_API_VERSION=${_SD_API_VER_NUM})

target_include_directories(${CURRENT_TARGET} PRIVATE ${PC_BLE_DRIVER_${SD_API_VER}_PUBLIC_INCLUDE_DIRS})

if(WIN32)
# suppress C4251 v8/msvc related warning, for more info: https:/nodejs/node/pull/15570
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251")

target_include_directories(${CURRENT_TARGET} PRIVATE "${CMAKE_JS_INC}/win")
set_target_properties(${CURRENT_TARGET} PROPERTIES COMPILE_DEFINITIONS "_CRT_SECURE_NO_WARNINGS")
elseif(APPLE)
Expand Down
25 changes: 13 additions & 12 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@

'use strict';

function getBuildSystem(debug) {
const cmakeJS = require('cmake-js');
const os = require('os');
const cmakeJS = require('cmake-js');
const os = require('os');
const fs = require('fs');

function getBuildSystem(debug) {
const defaultRuntime = 'node';
const defaultRuntimeVersion = process.version.substr(1);
const defaultWinArch = os.arch();
Expand All @@ -61,7 +62,7 @@ function getBuildSystem(debug) {
buildSystem.options.runtimeVersion = defaultRuntimeVersion;
}

if (buildSystem.options.arch === undefined && process.platform == 'win32') {
if (buildSystem.options.arch === undefined && process.platform === 'win32') {
buildSystem.options.arch = defaultWinArch;
}

Expand All @@ -71,8 +72,7 @@ function getBuildSystem(debug) {
let times = 0;

function begin(args) {
// Sanity check for the platform-specific binary driver files
const fs = require('fs');
// Sanity check for the platform-specific binary driver files
fs.readdir('./pc-ble-driver', (err, files) => {
if (err) {
console.error('ERROR: Could not read the \'pc-ble-driver\' subrepo, please check manually.');
Expand All @@ -84,19 +84,20 @@ function begin(args) {
});

let debug = false;
let build = 'rebuild';

const length = args.length >>> 0;

for (let i = 0; i < length; i++) {
for (let i = 0; i < args.length; i += 1) {
if (args[i] === '--debug') debug = true;
if (args[i] === '--no-rebuild') build = 'build';
}

let buildSystem;
try {
buildSystem = getBuildSystem(debug);
} catch (e) {
if (e.code == 'MODULE_NOT_FOUND') {
if (times++ == 5) {
if (e.code === 'MODULE_NOT_FOUND') {
times += 1;
if (times === 5) {
throw e;
} else {
setTimeout(begin, 2000);
Expand All @@ -106,7 +107,7 @@ function begin(args) {
}
}

buildSystem.rebuild().catch(e => {
buildSystem[build]().catch(() => {
process.exit(1);
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"cmake-js": "1.1.0",
"crc": "^3.4.0",
"jszip": "^3.1.2",
"nan": "2.3.3",
"nan": "^2.12.1",
"node-pre-gyp": "^0.6.39",
"nrf-device-lister": "^2.1.0",
"nrf-device-setup": "^0.4.0",
Expand Down
2 changes: 1 addition & 1 deletion src/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ NAN_METHOD(Adapter::New)
else
{
v8::Local<v8::Function> cons = Nan::New(constructor);
info.GetReturnValue().Set(cons->NewInstance());
info.GetReturnValue().Set(Nan::NewInstance(cons).ToLocalChecked());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class ConvUtil
throw std::string("number");
}

return static_cast<NativeType>(js->ToUint32()->Uint32Value());
return static_cast<NativeType>(js->Uint32Value());
}

static NativeType getNativeSigned(v8::Local<v8::Value> js)
Expand All @@ -221,7 +221,7 @@ class ConvUtil
throw std::string("number");
}

return static_cast<NativeType>(js->ToInt32()->Int32Value());
return static_cast<NativeType>(js->Int32Value());
}

static NativeType getNativeFloat(v8::Local<v8::Value> js)
Expand All @@ -231,7 +231,7 @@ class ConvUtil
throw std::string("number");
}

return static_cast<NativeType>(js->ToNumber()->NumberValue());
return static_cast<NativeType>(js->NumberValue());
}

static NativeType getNativeBool(v8::Local<v8::Value> js)
Expand Down
49 changes: 31 additions & 18 deletions src/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ void Adapter::onLogEvent(uv_async_t *handle)
v8::Local<v8::Value> argv[2];
argv[0] = ConversionUtility::toJsNumber(static_cast<int>(logEntry->severity));
argv[1] = ConversionUtility::toJsString(logEntry->message);
logCallback->Call(2, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
logCallback->Call(2, argv, &resource);
}
else
{
Expand All @@ -180,7 +181,7 @@ void Adapter::dispatchEvents()
// Adapter::cleanUpV8Resources() is called from both Adapter::AfterClose and Adapter::AfterConnReset
//
// If Adapter::eventInterval is 0, this method, Adapter::dispatchEvents, will be called directly without being
// invoked from eventIntervalTimer.
// invoked from eventIntervalTimer.
//
// When Adapter::AfterClose is invoked, parts of Adapter::cleanUpV8Resources() is ran before the
// the following call graph is complete:
Expand All @@ -189,8 +190,8 @@ void Adapter::dispatchEvents()
//
// The above call graph is ran in thread SerializationTransport::eventThread when Adapter::eventInterval == 0.
//
// If eventInterval != 0 the event is popped out of the Adapter::eventQueue queue by
// Adapter::eventIntervalTimer, in a libuv thread-pool thread. Adapter::eventIntervalTimer is stopped in
// If eventInterval != 0 the event is popped out of the Adapter::eventQueue queue by
// Adapter::eventIntervalTimer, in a libuv thread-pool thread. Adapter::eventIntervalTimer is stopped in
// Adapter::cleanUpV8Resources().
//
// A quick fix to circumvent this race condition is to ignore the event when Adapter::asyncEvent is nullptr.
Expand Down Expand Up @@ -386,7 +387,8 @@ void Adapter::onRpcEvent(uv_async_t *handle)

if (eventCallback != nullptr)
{
eventCallback->Call(1, callback_value);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
eventCallback->Call(1, callback_value, &resource);
}
else
{
Expand Down Expand Up @@ -442,7 +444,8 @@ void Adapter::onStatusEvent(uv_async_t *handle)
{
v8::Local<v8::Value> argv[1];
argv[0] = StatusMessage::getStatus(statusEntry->id, statusEntry->message, statusEntry->timestamp);
statusCallback->Call(1, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
statusCallback->Call(1, argv, &resource);
}

// Free memory for current entry, we remove the element from the deque when the iteration is done
Expand Down Expand Up @@ -583,7 +586,8 @@ void Adapter::AfterEnableBLE(uv_work_t *req)
argv[2] = ConversionUtility::toJsNumber(baton->app_ram_base);
}

baton->callback->Call(3, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
baton->callback->Call(3, argv, &resource);
delete baton;
}

Expand Down Expand Up @@ -785,8 +789,8 @@ void Adapter::AfterOpen(uv_work_t *req)
}


baton->callback->Call(1, argv);

Nan::AsyncResource resource("pc-ble-driver-js:callback");
baton->callback->Call(1, argv, &resource);
delete baton;
}

Expand Down Expand Up @@ -843,7 +847,8 @@ void Adapter::AfterClose(uv_work_t *req)
baton->adapter = nullptr;
}

baton->callback->Call(1, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
baton->callback->Call(1, argv, &resource);
}

delete baton;
Expand Down Expand Up @@ -898,7 +903,8 @@ void Adapter::AfterConnReset(uv_work_t *req)
argv[0] = Nan::Undefined();
}

baton->callback->Call(1, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
baton->callback->Call(1, argv, &resource);
}

delete baton;
Expand Down Expand Up @@ -958,7 +964,8 @@ void Adapter::AfterAddVendorSpecificUUID(uv_work_t *req)
argv[1] = ConversionUtility::toJsNumber(baton->p_uuid_type);
}

baton->callback->Call(2, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
baton->callback->Call(2, argv, &resource);
delete baton;
}

Expand Down Expand Up @@ -1074,7 +1081,8 @@ void Adapter::AfterGetVersion(uv_work_t *req)
argv[1] = Nan::Undefined();
}

baton->callback->Call(2, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
baton->callback->Call(2, argv, &resource);
delete baton;
}

Expand Down Expand Up @@ -1150,7 +1158,8 @@ void Adapter::AfterEncodeUUID(uv_work_t *req)
argv[3] = ConversionUtility::encodeHex(reinterpret_cast<char *>(baton->uuid_le), baton->uuid_le_len);
}

baton->callback->Call(4, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
baton->callback->Call(4, argv, &resource);
delete baton;
}

Expand Down Expand Up @@ -1215,7 +1224,8 @@ void Adapter::AfterDecodeUUID(uv_work_t *req)
argv[1] = BleUUID(baton->p_uuid);
}

baton->callback->Call(2, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
baton->callback->Call(2, argv, &resource);
delete baton;
}

Expand Down Expand Up @@ -1298,7 +1308,8 @@ void Adapter::AfterReplyUserMemory(uv_work_t *req)
argv[0] = Nan::Undefined();
}

baton->callback->Call(1, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
baton->callback->Call(1, argv, &resource);
delete baton;
}

Expand Down Expand Up @@ -1373,7 +1384,8 @@ void Adapter::AfterSetBleOption(uv_work_t *req)
argv[0] = Nan::Undefined();
}

baton->callback->Call(1, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
baton->callback->Call(1, argv, &resource);
delete baton;
}

Expand Down Expand Up @@ -1450,7 +1462,8 @@ void Adapter::AfterGetBleOption(uv_work_t *req)
argv[1] = optionValue;
}

baton->callback->Call(2, argv);
Nan::AsyncResource resource("pc-ble-driver-js:callback");
baton->callback->Call(2, argv, &resource);
delete baton;
}

Expand Down
Loading