Skip to content

Commit

Permalink
updated to nan 2.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneHollander committed Sep 11, 2015
1 parent 8a19012 commit 2819b1c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
build/
npm-debug.log
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raspberrypi",
"version": "0.0.2",
"version": "0.0.3",
"description": "Various NodeJS bindings for the Raspberry Pi",
"keywords": ["raspberrypi", "raspi", "gpu", "pi"],
"main": "lib/raspberrypi.js",
Expand All @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"bindings": "^1.2.1",
"nan": "^1.8.4"
"nan": "^2.0.9"
},
"bugs": {
"url": "https://github.com/ReneHollander/node-raspberrypi/issues"
Expand Down
78 changes: 38 additions & 40 deletions src/GPUInterface.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "GPUInterface.h"

Persistent<Function> GPUInterface::constructor;
Nan::Persistent<Function> GPUInterface::constructor;

GPUInterface::GPUInterface() {
client = init();
Expand All @@ -11,80 +11,78 @@ GPUInterface::~GPUInterface() {
}

void GPUInterface::Init(Handle<Object> exports) {
NanScope();
Nan::HandleScope scope;

Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(GPUInterface::New);
Local<FunctionTemplate> ctor = Nan::New<FunctionTemplate>(GPUInterface::New);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(NanNew("GPUInterface"));
ctor->SetClassName(Nan::New("GPUInterface").ToLocalChecked());

NODE_SET_PROTOTYPE_METHOD(ctor, "viewImageSync", ViewImageSync);
NODE_SET_PROTOTYPE_METHOD(ctor, "viewImageAsync", ViewImageAsync);
NODE_SET_PROTOTYPE_METHOD(ctor, "viewVideoSync", ViewVideoSync);
NODE_SET_PROTOTYPE_METHOD(ctor, "viewVideoAsync", ViewVideoAsync);
Nan::SetPrototypeMethod(ctor, "viewImageSync", ViewImageSync);
Nan::SetPrototypeMethod(ctor, "viewImageAsync", ViewImageAsync);
Nan::SetPrototypeMethod(ctor, "viewVideoSync", ViewVideoSync);
Nan::SetPrototypeMethod(ctor, "viewVideoAsync", ViewVideoAsync);

exports->Set(NanNew("GPUInterface"), ctor->GetFunction());
exports->Set(Nan::New("GPUInterface").ToLocalChecked(), ctor->GetFunction());
}

NAN_METHOD(GPUInterface::New) {
NanScope();
Nan::HandleScope scope;
GPUInterface *gpui = new GPUInterface();
gpui->Wrap(args.This());
NanReturnValue(args.This());
gpui->Wrap(info.This());
info.GetReturnValue().Set(info.This());
}

NAN_METHOD(GPUInterface::ViewImageSync) {
NanScope();
GPUInterface *gpui = ObjectWrap::Unwrap<GPUInterface>(args.This());
Nan::HandleScope scope;
GPUInterface *gpui = Nan::ObjectWrap::Unwrap<GPUInterface>(info.This());

Local<String> fileName = args[0].As<String>();
int duration = args[1]->Uint32Value();
int ret = viewImageFilename(gpui->client, *String::Utf8Value(fileName), duration);
string fileName(*String::Utf8Value(info[0]));
int duration = info[1]->Uint32Value();
int ret = viewImageFilename(gpui->client, const_cast<char *>(fileName.c_str()), duration);

NanReturnValue(NanNew<Number>(ret));
info.GetReturnValue().Set(Nan::New<Number>(ret));
}

NAN_METHOD(GPUInterface::ViewImageAsync) {
NanScope();
GPUInterface *gpui = ObjectWrap::Unwrap<GPUInterface>(args.This());
Nan::HandleScope scope;
GPUInterface *gpui = Nan::ObjectWrap::Unwrap<GPUInterface>(info.This());

string fileName(*NanAsciiString(args[0]));
int duration = args[1]->Uint32Value();
NanCallback *callback = new NanCallback(args[2].As<Function>());
string fileName(*String::Utf8Value(info[0]));
int duration = info[1]->Uint32Value();
Nan::Callback *callback = new Nan::Callback(info[2].As<Function>());

NanAsyncQueueWorker(new AsyncImageViewer(callback, gpui, fileName, duration));
NanReturnUndefined();
Nan::AsyncQueueWorker(new AsyncImageViewer(callback, gpui, fileName, duration));
}

NAN_METHOD(GPUInterface::ViewVideoSync) {
NanScope();
GPUInterface *gpui = ObjectWrap::Unwrap<GPUInterface>(args.This());
Nan::HandleScope scope;
GPUInterface *gpui = Nan::ObjectWrap::Unwrap<GPUInterface>(info.This());

Local<String> fileName = args[0].As<String>();
int ret = playVideoFilename(gpui->client, *String::Utf8Value(fileName));
string fileName(*String::Utf8Value(info[0]));
int ret = playVideoFilename(gpui->client, const_cast<char *>(fileName.c_str()));

NanReturnValue(NanNew<Number>(ret));
info.GetReturnValue().Set(Nan::New<Number>(ret));
}

NAN_METHOD(GPUInterface::ViewVideoAsync) {
NanScope();
GPUInterface *gpui = ObjectWrap::Unwrap<GPUInterface>(args.This());
Nan::HandleScope scope;
GPUInterface *gpui = Nan::ObjectWrap::Unwrap<GPUInterface>(info.This());

string fileName(*NanAsciiString(args[0]));
NanCallback *callback = new NanCallback(args[1].As<Function>());
string fileName(*String::Utf8Value(info[0]));
Nan::Callback *callback = new Nan::Callback(info[1].As<Function>());

NanAsyncQueueWorker(new AsyncVideoViewer(callback, gpui, fileName));
NanReturnUndefined();
Nan::AsyncQueueWorker(new AsyncVideoViewer(callback, gpui, fileName));
}

void AsyncImageViewer::Execute() {
returnVal = viewImageFilename(gpui->client, const_cast<char*>(filename.c_str()), duration);
}

void AsyncImageViewer::HandleOKCallback() {
NanScope();
Nan::HandleScope scope;

Local<Value> argv[] = {
NanNew<Number>(returnVal)
Nan::New<Number>(returnVal)
};

callback->Call(1, argv);
Expand All @@ -95,10 +93,10 @@ void AsyncVideoViewer::Execute() {
}

void AsyncVideoViewer::HandleOKCallback() {
NanScope();
Nan::HandleScope scope;

Local<Value> argv[] = {
NanNew<Number>(returnVal)
Nan::New<Number>(returnVal)
};

callback->Call(1, argv);
Expand Down
12 changes: 6 additions & 6 deletions src/GPUInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern "C" {
using namespace v8;
using namespace std;

class GPUInterface : public node::ObjectWrap {
class GPUInterface : public Nan::ObjectWrap {
public:
GPUInterface();
~GPUInterface();
Expand All @@ -25,15 +25,15 @@ class GPUInterface : public node::ObjectWrap {
static NAN_METHOD(ViewImageAsync);
static NAN_METHOD(ViewVideoSync);
static NAN_METHOD(ViewVideoAsync);
static v8::Persistent<v8::Function> constructor;
static Nan::Persistent<v8::Function> constructor;

ILCLIENT_T *client;
};


class AsyncImageViewer : public NanAsyncWorker {
class AsyncImageViewer : public Nan::AsyncWorker {
public:
AsyncImageViewer(NanCallback *callback, GPUInterface *gpui, string filename, int duration) : NanAsyncWorker(callback), gpui(gpui), filename(filename), duration(duration) {}
AsyncImageViewer(Nan::Callback *callback, GPUInterface *gpui, string filename, int duration) : Nan::AsyncWorker(callback), gpui(gpui), filename(filename), duration(duration) {}
~AsyncImageViewer() {}

void Execute();
Expand All @@ -46,9 +46,9 @@ class AsyncImageViewer : public NanAsyncWorker {
int returnVal;
};

class AsyncVideoViewer : public NanAsyncWorker {
class AsyncVideoViewer : public Nan::AsyncWorker {
public:
AsyncVideoViewer(NanCallback *callback, GPUInterface *gpui, string filename) : NanAsyncWorker(callback), gpui(gpui), filename(filename) {}
AsyncVideoViewer(Nan::Callback *callback, GPUInterface *gpui, string filename) : Nan::AsyncWorker(callback), gpui(gpui), filename(filename) {}
~AsyncVideoViewer() {}

void Execute();
Expand Down
2 changes: 1 addition & 1 deletion src/raspberrypi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using namespace v8;

void Init(Handle<Object> exports) {
NanScope();
Nan::HandleScope scope;
GPUInterface::Init(exports);
}

Expand Down

0 comments on commit 2819b1c

Please sign in to comment.