bluetooth-serial-port 2.2.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv.h +1724 -0
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv.h.blob +0 -0
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv@darwin.h +61 -0
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv@darwin.h.blob +0 -0
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv@errno.h +443 -0
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv@errno.h.blob +0 -0
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv@threadpool.h +37 -0
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv@threadpool.h.blob +0 -0
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv@unix.h +491 -0
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv@unix.h.blob +0 -0
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv@version.h +43 -0
- package/.ccls-cache/@@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/@usr@local@Cellar@libuv@1.31.0@include@uv@version.h.blob +0 -0
- package/.ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@DeviceINQ.h +78 -0
- package/.ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@DeviceINQ.h.blob +0 -0
- package/.ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@linux@BTSerialPortBinding.cc +404 -0
- package/.ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@linux@BTSerialPortBinding.cc.blob +0 -0
- package/{src/osx/BluetoothSerialPort.mm → .ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@linux@BluetoothSerialPort.cc} +3 -3
- package/.ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@linux@BluetoothSerialPort.cc.blob +0 -0
- package/.ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@linux@DeviceINQ.cc +369 -0
- package/.ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@linux@DeviceINQ.cc.blob +0 -0
- package/.ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@windows@BluetoothHelpers.h +24 -0
- package/.ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@windows@BluetoothHelpers.h.blob +0 -0
- package/.ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@windows@DeviceINQ.cc +527 -0
- package/.ccls-cache/@Users@eelco@Projects@Figaro@workspace@node-bluetooth-serial-port/src@windows@DeviceINQ.cc.blob +0 -0
- package/.circleci/config.yml +47 -0
- package/.github/dependabot.yml +11 -0
- package/Dockerfile +1 -1
- package/Dockerfile.bk +13 -0
- package/README.md +91 -78
- package/RELEASE_NOTES.md +14 -0
- package/appveyor.yml +6 -9
- package/binding.gyp +0 -8
- package/package.json +56 -58
- package/qemu-arm-static +0 -0
- package/src/BTSerialPortBinding.h +3 -3
- package/src/BTSerialPortBindingServer.h +1 -1
- package/src/DeviceINQ.h +1 -1
- package/src/linux/BTSerialPortBinding.cc +17 -15
- package/src/linux/BTSerialPortBindingServer.cc +29 -19
- package/src/linux/BluetoothSerialPort.cc +1 -1
- package/src/linux/BluetoothSerialPortServer.cc +1 -1
- package/src/linux/DeviceINQ.cc +18 -15
- package/src/{osx → macos}/BTSerialPortBinding.mm +23 -17
- package/src/{osx → macos}/BluetoothDeviceResources.h +0 -0
- package/src/{osx → macos}/BluetoothDeviceResources.mm +0 -0
- package/src/macos/BluetoothSerialPort.mm +23 -0
- package/src/{osx → macos}/BluetoothWorker.h +3 -3
- package/src/{osx → macos}/BluetoothWorker.mm +139 -140
- package/src/{osx → macos}/DeviceINQ.mm +21 -23
- package/src/{osx → macos}/pipe.c +0 -0
- package/src/{osx → macos}/pipe.h +0 -0
- package/src/windows/BTSerialPortBinding.cc +17 -18
- package/src/windows/BluetoothSerialPort.cc +3 -3
- package/src/windows/DeviceINQ.cc +17 -15
- package/.travis.yml +0 -48
|
@@ -162,7 +162,8 @@ void BTSerialPortBindingServer::EIO_AfterListen(uv_work_t *req) {
|
|
|
162
162
|
Nan::Error(baton->errorString)
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
Nan::AsyncResource resource("bluetooth-serial-port:server.Listen");
|
|
166
|
+
baton->ecb->Call(1, argv, &resource);
|
|
166
167
|
return;
|
|
167
168
|
}
|
|
168
169
|
|
|
@@ -214,7 +215,9 @@ void BTSerialPortBindingServer::EIO_AfterWrite(uv_work_t *req) {
|
|
|
214
215
|
argv[1] = Nan::New<v8::Integer>((int32_t)data->result);
|
|
215
216
|
}
|
|
216
217
|
|
|
217
|
-
|
|
218
|
+
|
|
219
|
+
Nan::AsyncResource resource("bluetooth-serial-port:server.Write");
|
|
220
|
+
data->callback->Call(2, argv, &resource);
|
|
218
221
|
|
|
219
222
|
uv_mutex_lock(&data->rfcomm->mWriteQueueMutex);
|
|
220
223
|
ngx_queue_remove(&queuedWrite->queue);
|
|
@@ -283,6 +286,7 @@ void BTSerialPortBindingServer::EIO_AfterRead(uv_work_t *req) {
|
|
|
283
286
|
|
|
284
287
|
Local<Value> argv[2];
|
|
285
288
|
|
|
289
|
+
Nan::AsyncResource resource("bluetooth-serial-port:server.Read");
|
|
286
290
|
if (baton->size <= 0) {
|
|
287
291
|
char msg[512];
|
|
288
292
|
sprintf(msg, "Error reading from connection: errno: %d", baton->errorno);
|
|
@@ -294,21 +298,18 @@ void BTSerialPortBindingServer::EIO_AfterRead(uv_work_t *req) {
|
|
|
294
298
|
baton->rfcomm->AdvertiseAndAccept();
|
|
295
299
|
}
|
|
296
300
|
argv[0] = Nan::Error(CLIENT_CLOSED_CONNECTION);
|
|
297
|
-
baton->cb->Call(2, argv);
|
|
301
|
+
baton->cb->Call(2, argv, &resource);
|
|
298
302
|
}
|
|
299
303
|
return;
|
|
300
304
|
}
|
|
301
305
|
|
|
302
|
-
Local<Object>
|
|
303
|
-
Local<Function> bufferConstructor = Local<Function>::Cast(globalObj->Get(Nan::New("Buffer").ToLocalChecked()));
|
|
304
|
-
Handle<Value> constructorArgs[1] = { Nan::New<v8::Integer>(baton->size) };
|
|
305
|
-
Local<Object> resultBuffer = Nan::NewInstance(bufferConstructor, 1, constructorArgs).ToLocalChecked();
|
|
306
|
+
Local<Object> resultBuffer = Nan::NewBuffer(baton->size).ToLocalChecked();
|
|
306
307
|
memcpy(Buffer::Data(resultBuffer), baton->result, baton->size);
|
|
307
308
|
|
|
308
309
|
argv[0] = Nan::Undefined();
|
|
309
310
|
argv[1] = resultBuffer;
|
|
310
311
|
|
|
311
|
-
baton->cb->Call(2, argv);
|
|
312
|
+
baton->cb->Call(2, argv, &resource);
|
|
312
313
|
|
|
313
314
|
if (try_catch.HasCaught()) {
|
|
314
315
|
Nan::FatalException(try_catch);
|
|
@@ -319,7 +320,7 @@ void BTSerialPortBindingServer::EIO_AfterRead(uv_work_t *req) {
|
|
|
319
320
|
delete baton;
|
|
320
321
|
}
|
|
321
322
|
|
|
322
|
-
void BTSerialPortBindingServer::Init(
|
|
323
|
+
void BTSerialPortBindingServer::Init(Local<Object> target) {
|
|
323
324
|
Nan::HandleScope scope;
|
|
324
325
|
|
|
325
326
|
Local<FunctionTemplate> t = Nan::New<FunctionTemplate>(New);
|
|
@@ -327,13 +328,16 @@ void BTSerialPortBindingServer::Init(Handle<Object> target) {
|
|
|
327
328
|
t->InstanceTemplate()->SetInternalFieldCount(1);
|
|
328
329
|
t->SetClassName(Nan::New("BTSerialPortBindingServer").ToLocalChecked());
|
|
329
330
|
|
|
331
|
+
Isolate *isolate = target->GetIsolate();
|
|
332
|
+
Local<Context> ctx = isolate->GetCurrentContext();
|
|
333
|
+
|
|
330
334
|
Nan::SetPrototypeMethod(t, "write", Write);
|
|
331
335
|
Nan::SetPrototypeMethod(t, "read", Read);
|
|
332
336
|
Nan::SetPrototypeMethod(t, "close", Close);
|
|
333
337
|
Nan::SetPrototypeMethod(t, "disconnectClient", DisconnectClient);
|
|
334
338
|
Nan::SetPrototypeMethod(t, "isOpen", IsOpen);
|
|
335
339
|
|
|
336
|
-
|
|
340
|
+
Nan::Set(target, Nan::New("BTSerialPortBindingServer").ToLocalChecked(), t->GetFunction(ctx).ToLocalChecked());
|
|
337
341
|
}
|
|
338
342
|
|
|
339
343
|
BTSerialPortBindingServer::BTSerialPortBindingServer() :
|
|
@@ -377,16 +381,19 @@ NAN_METHOD(BTSerialPortBindingServer::New) {
|
|
|
377
381
|
listen_baton_t * baton = rfcomm->mListenBaton;
|
|
378
382
|
rfcomm->Wrap(info.This());
|
|
379
383
|
|
|
380
|
-
|
|
381
|
-
|
|
384
|
+
Local<Object> jsOptions = Local<Object>::Cast(info[2]);
|
|
385
|
+
Isolate *isolate = jsOptions->GetIsolate();
|
|
386
|
+
Local<Context> ctx = isolate->GetCurrentContext();
|
|
387
|
+
|
|
388
|
+
Local<Array> properties = jsOptions->GetPropertyNames(ctx).ToLocalChecked();
|
|
382
389
|
int n = properties->Length();
|
|
383
390
|
std::map<std::string, std::string> options;
|
|
384
391
|
|
|
385
392
|
for (int i = 0; i < n ; i++) {
|
|
386
|
-
|
|
387
|
-
string propertyName = std::string(*String::Utf8Value(property));
|
|
388
|
-
|
|
389
|
-
options[propertyName] = std::string(*String::Utf8Value(optionValue));
|
|
393
|
+
Local<Value> property = Nan::Get(properties, Nan::New<Integer>(i)).ToLocalChecked();
|
|
394
|
+
string propertyName = std::string(*String::Utf8Value(isolate, property));
|
|
395
|
+
Local<Value> optionValue = Nan::Get(jsOptions, property).ToLocalChecked();
|
|
396
|
+
options[propertyName] = std::string(*String::Utf8Value(isolate, optionValue));
|
|
390
397
|
}
|
|
391
398
|
|
|
392
399
|
if(!str2uuid(options["uuid"].c_str(), &baton->uuid)){
|
|
@@ -600,8 +607,9 @@ NAN_METHOD(BTSerialPortBindingServer::Read) {
|
|
|
600
607
|
argv[0] = Nan::Error(CLIENT_CLOSED_CONNECTION);
|
|
601
608
|
argv[1] = Nan::Undefined();
|
|
602
609
|
|
|
610
|
+
Nan::AsyncResource resource("bluetooth-serial-port:server.Read");
|
|
603
611
|
std::unique_ptr<Nan::Callback> nc(new Nan::Callback(cb));
|
|
604
|
-
nc->Call(2, argv);
|
|
612
|
+
nc->Call(2, argv, &resource);
|
|
605
613
|
return;
|
|
606
614
|
}
|
|
607
615
|
read_baton_t *baton = new read_baton_t();
|
|
@@ -666,7 +674,7 @@ void BTSerialPortBindingServer::ClientWorker::Execute(){
|
|
|
666
674
|
|
|
667
675
|
select_status = select(mBaton->rfcomm->s + 1, &fds, NULL, NULL, &timeout);
|
|
668
676
|
if (select_status > 0) {
|
|
669
|
-
break;
|
|
677
|
+
break;
|
|
670
678
|
}
|
|
671
679
|
else if (select_status == -1) {
|
|
672
680
|
return Nan::ThrowError("error pselect'ing socket!");
|
|
@@ -701,6 +709,8 @@ void BTSerialPortBindingServer::ClientWorker::HandleOKCallback(){
|
|
|
701
709
|
Local<Value> argv[] = {
|
|
702
710
|
Nan::New<v8::String>((mBaton->clientAddress)).ToLocalChecked()
|
|
703
711
|
};
|
|
704
|
-
|
|
712
|
+
|
|
713
|
+
Nan::AsyncResource resource("bluetooth-serial-port:server.HandleOK");
|
|
714
|
+
callback->Call(1, argv, &resource);
|
|
705
715
|
|
|
706
716
|
}
|
package/src/linux/DeviceINQ.cc
CHANGED
|
@@ -136,7 +136,8 @@ void DeviceINQ::EIO_AfterSdpSearch(uv_work_t *req) {
|
|
|
136
136
|
Nan::New(baton->channelID)
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
Nan::AsyncResource resource("bluetooth-serial-port:SdpSearch");
|
|
140
|
+
baton->cb->Call(1, argv, &resource);
|
|
140
141
|
|
|
141
142
|
if (try_catch.HasCaught()) {
|
|
142
143
|
Nan::FatalException(try_catch);
|
|
@@ -148,7 +149,7 @@ void DeviceINQ::EIO_AfterSdpSearch(uv_work_t *req) {
|
|
|
148
149
|
baton = NULL;
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
void DeviceINQ::Init(
|
|
152
|
+
void DeviceINQ::Init(Local<Object> target) {
|
|
152
153
|
Nan::HandleScope scope;
|
|
153
154
|
|
|
154
155
|
Local<FunctionTemplate> t = Nan::New<FunctionTemplate>(New);
|
|
@@ -156,14 +157,14 @@ void DeviceINQ::Init(Handle<Object> target) {
|
|
|
156
157
|
t->InstanceTemplate()->SetInternalFieldCount(1);
|
|
157
158
|
t->SetClassName(Nan::New("DeviceINQ").ToLocalChecked());
|
|
158
159
|
|
|
160
|
+
Isolate *isolate = target->GetIsolate();
|
|
161
|
+
Local<Context> ctx = isolate->GetCurrentContext();
|
|
162
|
+
|
|
159
163
|
Nan::SetPrototypeMethod(t, "inquireSync", InquireSync);
|
|
160
164
|
Nan::SetPrototypeMethod(t, "inquire", Inquire);
|
|
161
165
|
Nan::SetPrototypeMethod(t, "findSerialPortChannel", SdpSearch);
|
|
162
166
|
Nan::SetPrototypeMethod(t, "listPairedDevices", ListPairedDevices);
|
|
163
|
-
target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
|
|
164
|
-
target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
|
|
165
|
-
target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
|
|
166
|
-
target->Set(Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction());
|
|
167
|
+
target->Set(ctx, Nan::New("DeviceINQ").ToLocalChecked(), t->GetFunction(ctx).ToLocalChecked());
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
bt_inquiry DeviceINQ::doInquire() {
|
|
@@ -239,26 +240,27 @@ NAN_METHOD(DeviceINQ::InquireSync) {
|
|
|
239
240
|
return Nan::ThrowError(usage);
|
|
240
241
|
}
|
|
241
242
|
|
|
243
|
+
Nan::AsyncResource resource("bluetooth-serial-port:InquireSync");
|
|
242
244
|
Nan::Callback *found = new Nan::Callback(info[0].As<Function>());
|
|
243
245
|
Nan::Callback *callback = new Nan::Callback(info[1].As<Function>());
|
|
244
246
|
|
|
245
247
|
bt_inquiry inquiryResult = DeviceINQ::doInquire();
|
|
246
248
|
for (int i = 0; i < inquiryResult.num_rsp; i++) {
|
|
247
249
|
Local<Value> argv[] = {
|
|
248
|
-
Nan::New(inquiryResult.devices[i].address).ToLocalChecked(),
|
|
250
|
+
Nan::New(inquiryResult.devices[i].address).ToLocalChecked(),
|
|
249
251
|
Nan::New(inquiryResult.devices[i].name).ToLocalChecked()
|
|
250
252
|
};
|
|
251
|
-
found->Call(2, argv);
|
|
253
|
+
found->Call(2, argv, &resource);
|
|
252
254
|
}
|
|
253
255
|
|
|
254
256
|
Local<Value> argv[] = {};
|
|
255
|
-
callback->Call(0, argv);
|
|
257
|
+
callback->Call(0, argv, &resource);
|
|
256
258
|
return;
|
|
257
259
|
}
|
|
258
260
|
|
|
259
261
|
class InquireWorker : public Nan::AsyncWorker {
|
|
260
262
|
public:
|
|
261
|
-
InquireWorker(Nan::Callback* found, Nan::Callback *callback)
|
|
263
|
+
InquireWorker(Nan::Callback* found, Nan::Callback *callback)
|
|
262
264
|
: Nan::AsyncWorker(callback), found(found) {}
|
|
263
265
|
~InquireWorker() {}
|
|
264
266
|
|
|
@@ -276,16 +278,17 @@ class InquireWorker : public Nan::AsyncWorker {
|
|
|
276
278
|
void HandleOKCallback () {
|
|
277
279
|
Nan::HandleScope scope;
|
|
278
280
|
|
|
281
|
+
Nan::AsyncResource resource("bluetooth-serial-port:Inquire");
|
|
279
282
|
for (int i = 0; i < inquiryResult.num_rsp; i++) {
|
|
280
283
|
Local<Value> argv[] = {
|
|
281
|
-
Nan::New(inquiryResult.devices[i].address).ToLocalChecked(),
|
|
284
|
+
Nan::New(inquiryResult.devices[i].address).ToLocalChecked(),
|
|
282
285
|
Nan::New(inquiryResult.devices[i].name).ToLocalChecked()
|
|
283
286
|
};
|
|
284
|
-
found->Call(2, argv);
|
|
287
|
+
found->Call(2, argv, &resource);
|
|
285
288
|
}
|
|
286
289
|
|
|
287
290
|
Local<Value> argv[] = {};
|
|
288
|
-
callback->Call(0, argv);
|
|
291
|
+
callback->Call(0, argv, &resource);
|
|
289
292
|
}
|
|
290
293
|
|
|
291
294
|
private:
|
|
@@ -314,7 +317,7 @@ NAN_METHOD(DeviceINQ::SdpSearch) {
|
|
|
314
317
|
if (!info[0]->IsString()) {
|
|
315
318
|
return Nan::ThrowTypeError("First argument should be a string value");
|
|
316
319
|
}
|
|
317
|
-
String::Utf8Value address(info[0]);
|
|
320
|
+
String::Utf8Value address(info.GetIsolate(), info[0]);
|
|
318
321
|
|
|
319
322
|
if(!info[1]->IsFunction()) {
|
|
320
323
|
return Nan::ThrowTypeError("Second argument must be a function");
|
|
@@ -363,7 +366,7 @@ NAN_METHOD(DeviceINQ::ListPairedDevices) {
|
|
|
363
366
|
Local<Value> argv[1] = {
|
|
364
367
|
resultArray
|
|
365
368
|
};
|
|
366
|
-
cb->Call(Nan::GetCurrentContext()->Global(), 1, argv);
|
|
369
|
+
cb->Call(Nan::GetCurrentContext(), Nan::GetCurrentContext()->Global(), 1, argv);
|
|
367
370
|
|
|
368
371
|
return;
|
|
369
372
|
}
|
|
@@ -75,15 +75,16 @@ void BTSerialPortBinding::EIO_AfterConnect(uv_work_t *req) {
|
|
|
75
75
|
|
|
76
76
|
Nan::TryCatch try_catch;
|
|
77
77
|
|
|
78
|
+
Nan::AsyncResource resource("bluetooth-serial-port:Connect");
|
|
78
79
|
if (baton->status == 0) {
|
|
79
|
-
baton->cb->Call(0, NULL);
|
|
80
|
+
baton->cb->Call(0, NULL, &resource);
|
|
80
81
|
} else {
|
|
81
82
|
char msg[80];
|
|
82
83
|
sprintf(msg, "Cannot connect: %d", baton->status);
|
|
83
84
|
Local<Value> argv[] = {
|
|
84
85
|
Nan::Error(msg)
|
|
85
86
|
};
|
|
86
|
-
baton->ecb->Call(1, argv);
|
|
87
|
+
baton->ecb->Call(1, argv, &resource);
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
if (try_catch.HasCaught()) {
|
|
@@ -130,7 +131,8 @@ void BTSerialPortBinding::EIO_AfterWrite(uv_work_t *req) {
|
|
|
130
131
|
argv[1] = Nan::New<v8::Integer>((int32_t)data->result);
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
|
|
134
|
+
Nan::AsyncResource resource("bluetooth-serial-port:Write");
|
|
135
|
+
data->callback->Call(2, argv, &resource);
|
|
134
136
|
|
|
135
137
|
uv_mutex_lock(&write_queue_mutex);
|
|
136
138
|
ngx_queue_remove(&queuedWrite->queue);
|
|
@@ -186,17 +188,15 @@ void BTSerialPortBinding::EIO_AfterRead(uv_work_t *req) {
|
|
|
186
188
|
argv[0] = Nan::Error("Error reading from connection");
|
|
187
189
|
argv[1] = Nan::Undefined();
|
|
188
190
|
} else {
|
|
189
|
-
Local<Object>
|
|
190
|
-
Local<Function> bufferConstructor = Local<Function>::Cast(globalObj->Get(Nan::New("Buffer").ToLocalChecked()));
|
|
191
|
-
Local<Value> constructorArgs[1] = { Nan::New<v8::Integer>(baton->size) };
|
|
192
|
-
Local<Object> resultBuffer = Nan::NewInstance(bufferConstructor, 1, constructorArgs).ToLocalChecked();
|
|
191
|
+
Local<Object> resultBuffer = Nan::NewBuffer(baton->size).ToLocalChecked();
|
|
193
192
|
memcpy(Buffer::Data(resultBuffer), baton->result, baton->size);
|
|
194
193
|
|
|
195
194
|
argv[0] = Nan::Undefined();
|
|
196
195
|
argv[1] = resultBuffer;
|
|
197
196
|
}
|
|
198
197
|
|
|
199
|
-
|
|
198
|
+
Nan::AsyncResource resource("bluetooth-serial-port:Read");
|
|
199
|
+
baton->cb->Call(2, argv, &resource);
|
|
200
200
|
|
|
201
201
|
if (try_catch.HasCaught()) {
|
|
202
202
|
Nan::FatalException(try_catch);
|
|
@@ -208,7 +208,7 @@ void BTSerialPortBinding::EIO_AfterRead(uv_work_t *req) {
|
|
|
208
208
|
baton = NULL;
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
void BTSerialPortBinding::Init(
|
|
211
|
+
void BTSerialPortBinding::Init(Local<Object> target) {
|
|
212
212
|
Nan::HandleScope scope;
|
|
213
213
|
|
|
214
214
|
Local<FunctionTemplate> t = Nan::New<FunctionTemplate>(New);
|
|
@@ -216,12 +216,13 @@ void BTSerialPortBinding::Init(Handle<Object> target) {
|
|
|
216
216
|
t->InstanceTemplate()->SetInternalFieldCount(1);
|
|
217
217
|
t->SetClassName(Nan::New("BTSerialPortBinding").ToLocalChecked());
|
|
218
218
|
|
|
219
|
+
Isolate *isolate = target->GetIsolate();
|
|
220
|
+
Local<Context> ctx = isolate->GetCurrentContext();
|
|
221
|
+
|
|
219
222
|
Nan::SetPrototypeMethod(t, "write", Write);
|
|
220
223
|
Nan::SetPrototypeMethod(t, "read", Read);
|
|
221
224
|
Nan::SetPrototypeMethod(t, "close", Close);
|
|
222
|
-
target->Set(Nan::New("BTSerialPortBinding").ToLocalChecked(), t->GetFunction());
|
|
223
|
-
target->Set(Nan::New("BTSerialPortBinding").ToLocalChecked(), t->GetFunction());
|
|
224
|
-
target->Set(Nan::New("BTSerialPortBinding").ToLocalChecked(), t->GetFunction());
|
|
225
|
+
target->Set(ctx, Nan::New("BTSerialPortBinding").ToLocalChecked(), t->GetFunction(ctx).ToLocalChecked());
|
|
225
226
|
}
|
|
226
227
|
|
|
227
228
|
BTSerialPortBinding::BTSerialPortBinding() :
|
|
@@ -240,9 +241,9 @@ NAN_METHOD(BTSerialPortBinding::New) {
|
|
|
240
241
|
return Nan::ThrowError(usage);
|
|
241
242
|
}
|
|
242
243
|
|
|
243
|
-
String::Utf8Value address(info[0]);
|
|
244
|
+
String::Utf8Value address(info.GetIsolate(), info[0]);
|
|
244
245
|
|
|
245
|
-
int channelID = info[1]->Int32Value();
|
|
246
|
+
int channelID = info[1]->Int32Value(Nan::GetCurrentContext()).ToChecked();
|
|
246
247
|
if (channelID <= 0) {
|
|
247
248
|
return Nan::ThrowTypeError("ChannelID should be a positive int value.");
|
|
248
249
|
}
|
|
@@ -283,7 +284,11 @@ NAN_METHOD(BTSerialPortBinding::Write) {
|
|
|
283
284
|
void* bufferData = Buffer::Data(bufferObject);
|
|
284
285
|
size_t bufferLength = Buffer::Length(bufferObject);
|
|
285
286
|
|
|
286
|
-
|
|
287
|
+
// string
|
|
288
|
+
if (!info[1]->IsString()) {
|
|
289
|
+
Nan::ThrowTypeError("Second argument must be a string");
|
|
290
|
+
}
|
|
291
|
+
String::Utf8Value addressParameter(info.GetIsolate(), info[1]);
|
|
287
292
|
|
|
288
293
|
// callback
|
|
289
294
|
if(!info[2]->IsFunction()) {
|
|
@@ -328,7 +333,7 @@ NAN_METHOD(BTSerialPortBinding::Close) {
|
|
|
328
333
|
}
|
|
329
334
|
|
|
330
335
|
//TODO should be a better way to do this...
|
|
331
|
-
String::Utf8Value addressParameter(info[0]);
|
|
336
|
+
String::Utf8Value addressParameter(info.GetIsolate(), info[0]);
|
|
332
337
|
char addressArray[32];
|
|
333
338
|
strncpy(addressArray, *addressParameter, 32);
|
|
334
339
|
NSString *address = [NSString stringWithCString:addressArray encoding:NSASCIIStringEncoding];
|
|
@@ -356,7 +361,8 @@ NAN_METHOD(BTSerialPortBinding::Read) {
|
|
|
356
361
|
argv[1] = Nan::Undefined();
|
|
357
362
|
|
|
358
363
|
Nan::Callback *nc = new Nan::Callback(cb);
|
|
359
|
-
|
|
364
|
+
Nan::AsyncResource resource("bluetooth-serial-port:Read");
|
|
365
|
+
nc->Call(2, argv, &resource);
|
|
360
366
|
} else {
|
|
361
367
|
read_baton_t *baton = new read_baton_t();
|
|
362
368
|
baton->rfcomm = rfcomm;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2012-2013, Eelco Cramer
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
6
|
+
*
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
8
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#include <node.h>
|
|
13
|
+
#include "DeviceINQ.h"
|
|
14
|
+
#include "BTSerialPortBinding.h"
|
|
15
|
+
|
|
16
|
+
using namespace v8;
|
|
17
|
+
|
|
18
|
+
void InitAll(Local<Object> exports) {
|
|
19
|
+
DeviceINQ::Init(exports);
|
|
20
|
+
BTSerialPortBinding::Init(exports);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
NODE_MODULE(BluetoothSerialPort, InitAll)
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
8
8
|
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
9
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
#ifndef NODE_BTSP_SRC_BLUETOOTH_WORKER_H
|
|
@@ -29,7 +29,7 @@ struct device_info_t {
|
|
|
29
29
|
@interface BluetoothWorker: NSObject {
|
|
30
30
|
@private
|
|
31
31
|
BluetoothDeviceResources *res;
|
|
32
|
-
|
|
32
|
+
dispatch_queue_t worker_queue;
|
|
33
33
|
pipe_producer_t *inquiryProducer;
|
|
34
34
|
NSLock *sdpLock;
|
|
35
35
|
NSLock *connectLock;
|