Permalink
Browse files

libgphoto2-2.5.x and node-10.x compatibility

  • Loading branch information...
1 parent 92270e3 commit 39474fc72471dd370367772fee6a6c912e720741 @lwille committed Apr 6, 2013
Showing with 71 additions and 72 deletions.
  1. +7 −5 binding.gyp
  2. +1 −0 package.json
  3. +3 −2 src/binding.h
  4. +45 −45 src/camera.cc
  5. +5 −5 src/camera_helpers.cc
  6. +9 −11 src/gphoto.cc
  7. +1 −4 src/gphoto.h
View
@@ -9,10 +9,12 @@
'src/camera_helpers.cc',
'src/gphoto.cc'
],
- 'libraries': [
- '-lgphoto2',
- '-lgphoto2_port'
- ],
+ 'link_settings': {
+ 'libraries': [
+ '-lgphoto2',
+ '-lgphoto2_port'
+ ]
+ },
'cflags!': ['-fno-exceptions'],
'target_arch': 'x64',
'conditions': [
@@ -24,4 +26,4 @@
]
}
]
-}
+}
View
@@ -27,6 +27,7 @@
"async": "0.1.x"
},
"scripts": {
+ "preinstall": "node-gyp configure build",
"prepublish": "node-gyp clean",
"test": "mocha test/*.test.coffee"
}
View
@@ -16,7 +16,8 @@
#define ASYNC_FN(NAME)\
static void NAME(uv_work_t* req);
-#define ASYNC_CB ASYNC_FN
+#define ASYNC_CB(NAME)\
+static void NAME(uv_work_t* req, int status);
#define DO_ASYNC(BATON,ASYNC,AFTER)\
uv_work_t* req = new uv_work_t();\
@@ -90,4 +91,4 @@ int set_config_value_string (Camera *camera, const char *key, const char *val,
int get_config_value_string (Camera *camera, const char *key, char **str, GPContext *context);
-#endif
+#endif
View
@@ -20,19 +20,19 @@ GPCamera::~GPCamera(){
this->gphoto_->closeCamera(this);
this->gphoto.Dispose();
this->close();
-
+
pthread_mutex_destroy(&this->cameraMutex);
}
void
GPCamera::Initialize(Handle<Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(New);
-
+
// Constructor
constructor_template = Persistent<FunctionTemplate>::New(t);
-
-
+
+
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("Camera"));
@@ -53,7 +53,7 @@ GPCamera::TakePicture(const Arguments& args) {
if(args.Length() >= 2){
REQ_OBJ_ARG(0, options);
- REQ_FUN_ARG(1, cb);
+ REQ_FUN_ARG(1, cb);
picture_req->cb = Persistent<Function>::New(cb);
Local<Value> dl = options->Get(String::New("download"));
Local<Value> target = options->Get(String::New("targetPath"));
@@ -73,12 +73,12 @@ GPCamera::TakePicture(const Arguments& args) {
}
}else{
REQ_FUN_ARG(0, cb);
- picture_req->cb = Persistent<Function>::New(cb);
+ picture_req->cb = Persistent<Function>::New(cb);
}
picture_req->camera = camera->getCamera();
picture_req->cameraObject = camera;
-
+
picture_req->context = gp_context_new();
DO_ASYNC(picture_req, EIO_Capture, EIO_CaptureCb);
return Undefined();
@@ -96,10 +96,10 @@ GPCamera::EIO_Capture(uv_work_t *_req){
req->cameraObject->unlock();
}
-void GPCamera::EIO_CaptureCb(uv_work_t *req){
+void GPCamera::EIO_CaptureCb(uv_work_t *req, int status=0){
HandleScope scope;
take_picture_request *capture_req = (take_picture_request*) req->data;
-
+
Handle<Value> argv[2];
int argc = 1;
argv[0] = Undefined();
@@ -109,7 +109,7 @@ void GPCamera::EIO_CaptureCb(uv_work_t *req){
else if(capture_req->download && !capture_req->target_path.empty()){
argc=2;
argv[1] = String::New(capture_req->target_path.c_str());
- }
+ }
else if(capture_req->data && capture_req->download) {
argc = 2;
node::Buffer* slowBuffer = node::Buffer::New(capture_req->length);
@@ -125,41 +125,41 @@ void GPCamera::EIO_CaptureCb(uv_work_t *req){
argc = 2;
argv[1] = cv::CastToJS(capture_req->path);
}
-
+
capture_req->cb->Call(Context::GetCurrent()->Global(), argc, argv);
capture_req->cb.Dispose();
if(capture_req->ret == GP_OK) gp_file_free(capture_req->file);
capture_req->cameraObject->Unref();
gp_context_unref(capture_req->context);
// gp_camera_unref(capture_req->camera);
-
- delete capture_req;
+
+ delete capture_req;
}
Handle<Value>
GPCamera::DownloadPicture(const Arguments& args){
HandleScope scope;
-
+
REQ_OBJ_ARG(0, options);
REQ_FUN_ARG(1, cb);
-
+
GPCamera *camera = ObjectWrap::Unwrap<GPCamera>(args.This());
camera->Ref();
take_picture_request *picture_req = new take_picture_request();
picture_req->cb = Persistent<Function>::New(cb);
-
+
picture_req->camera = camera->getCamera();
picture_req->cameraObject = camera;
picture_req->context = gp_context_new();
picture_req->download = true;
-
+
Local<Value> source = options->Get(String::New("cameraPath"));
Local<Value> target = options->Get(String::New("targetPath"));
if(target->IsString()){
picture_req->target_path = cv::CastFromJS<std::string>(target);
}
-
+
picture_req->path = cv::CastFromJS<std::string>(source);
gp_camera_ref(picture_req->camera);
DO_ASYNC(picture_req, EIO_DownloadPicture, EIO_CaptureCb);
@@ -168,10 +168,10 @@ GPCamera::DownloadPicture(const Arguments& args){
void GPCamera::EIO_DownloadPicture(uv_work_t *_req){
take_picture_request *req = (take_picture_request *)_req->data;
-
+
req->cameraObject->lock();
downloadPicture(req);
- req->cameraObject->unlock();
+ req->cameraObject->unlock();
}
// Return available configuration widgets as a list in the form
// /main/status/model
@@ -185,16 +185,16 @@ GPCamera::GetConfig(const Arguments& args) {
camera->Ref();
get_config_request *config_req = new get_config_request();
config_req->cameraObject = camera;
- config_req->camera = camera->getCamera();
+ config_req->camera = camera->getCamera();
gp_camera_ref(config_req->camera);
config_req->context = gp_context_new();
config_req->cb = Persistent<Function>::New(cb);
DO_ASYNC(config_req, EIO_GetConfig, EIO_GetConfigCb);
-
+
//eio_custom(EIO_GetConfig, EIO_PRI_DEFAULT, EIO_GetConfigCb, config_req);
//ev_ref(EV_DEFAULT_UC);
- return Undefined();
+ return Undefined();
}
namespace cvv8 {
@@ -209,7 +209,7 @@ namespace cvv8 {
Local<Object> obj = value->ToObject();
if(node.subtree.size()){
obj->Set(cvv8::CastToJS("children"), cvv8::CastToJS(node.subtree));
- }else{
+ }else{
obj->Set(cvv8::CastToJS("children"), Undefined());
}
}
@@ -238,13 +238,13 @@ void GPCamera::EIO_GetConfig(uv_work_t *req){
config_req->ret = ret;
}
}
-void GPCamera::EIO_GetConfigCb(uv_work_t *req){
+void GPCamera::EIO_GetConfigCb(uv_work_t *req, int status=0){
HandleScope scope;
get_config_request *config_req = (get_config_request*)req->data;
-
+
Handle<Value> argv[2];
-
-
+
+
if(config_req->ret == GP_OK){
argv[0] = Undefined();
argv[1] = cv::CastToJS(config_req->settings);
@@ -255,13 +255,13 @@ void GPCamera::EIO_GetConfigCb(uv_work_t *req){
}
config_req->cb->Call(Context::GetCurrent()->Global(), 2, argv);
-
+
gp_widget_free(config_req->root);
- config_req->cb.Dispose();
+ config_req->cb.Dispose();
config_req->cameraObject->Unref();
gp_context_unref(config_req->context);
gp_camera_unref(config_req->camera);
-
+
delete config_req;
}
@@ -270,7 +270,7 @@ GPCamera::SetConfigValue(const Arguments& args) {
HandleScope scope;
GPCamera *camera = ObjectWrap::Unwrap<GPCamera>(args.This());
camera->Ref();
-
+
REQ_ARGS(3);
REQ_STR_ARG(0, key);
REQ_FUN_ARG(2, cb);
@@ -290,51 +290,51 @@ GPCamera::SetConfigValue(const Arguments& args) {
config_req->valueType = set_config_request::Float;
}else{
delete config_req;
- return ThrowException(Exception::TypeError(String::New("Argument 1 invalid: String, Integer or Float value expected")));
+ return ThrowException(Exception::TypeError(String::New("Argument 1 invalid: String, Integer or Float value expected")));
}
config_req->cameraObject = camera;
config_req->camera = camera->getCamera();
config_req->context = gp_context_new();
config_req->cb = Persistent<Function>::New(cb);
config_req->key = *key;
-
+
gp_camera_ref(config_req->camera);
DO_ASYNC(config_req, EIO_SetConfigValue, EIO_SetConfigValueCb);
-
+
return Undefined();
}
void
GPCamera::EIO_SetConfigValue(uv_work_t *req){
set_config_request *config_req = (set_config_request *)req->data;
-
+
config_req->cameraObject->lock();
config_req->ret = setWidgetValue(config_req);
config_req->cameraObject->unlock();
}
void
-GPCamera::EIO_SetConfigValueCb(uv_work_t *req){
+GPCamera::EIO_SetConfigValueCb(uv_work_t *req, int status=0){
HandleScope scope;
set_config_request *config_req = (set_config_request *)req->data;
-
+
int argc = 0;
Local<Value> argv[1];
if(config_req->ret < GP_OK){
argv[0] = Integer::New(config_req->ret);
- argc = 1;
+ argc = 1;
}
config_req->cb->Call(Context::GetCurrent()->Global(), argc, argv);
- config_req->cb.Dispose();
+ config_req->cb.Dispose();
config_req->cameraObject->Unref();
gp_context_unref(config_req->context);
gp_camera_unref(config_req->camera);
delete config_req;
-
+
}
Handle<Value>
GPCamera::New(const Arguments& args) {
HandleScope scope;
-
+
REQ_EXT_ARG(0, js_gphoto);
REQ_STR_ARG(1, model_);
REQ_STR_ARG(2, port_);
@@ -345,13 +345,13 @@ GPCamera::New(const Arguments& args) {
This->Set(String::New("model"),String::New(camera->model_.c_str()));
This->Set(String::New("port"),String::New(camera->port_.c_str()));
return args.This();
-}
+}
Camera* GPCamera::getCamera(){
//printf("getCamera %s gphoto=%p\n", this->isOpen() ? "open" : "closed", gp);
if(!this->isOpen()){
this->gphoto_->openCamera(this);
- }
+ }
return this->camera_;
};
@@ -361,5 +361,5 @@ GPCamera::close(){
if(this->camera_)
return gp_camera_exit(this->camera_, this->gphoto_->getContext()) < GP_OK ? false : true;
else
- return true;
+ return true;
}
View
@@ -305,7 +305,7 @@ GPCamera::downloadPicture(take_picture_request *req){
retval = gp_camera_file_delete(req->camera, folder.str().c_str(), name.c_str(), req->context);
}
- if(!req->target_path.empty()){
+ if(!req->target_path.empty()) {
gp_file_free(file);
}
req->ret=retval;
@@ -314,18 +314,18 @@ GPCamera::downloadPicture(take_picture_request *req){
void
GPCamera::capturePreview(take_picture_request *req){
int retval;
- CameraFileType type;
-
CameraFile *file;
retval = getCameraFile(req, &file);
if(retval == GP_OK){
retval = gp_camera_capture_preview(req->camera, file, req->context);
}
- if(!req->target_path.empty()){
+
+ if(!req->target_path.empty()) {
gp_file_free(file);
}
+
req->ret = retval;
}
@@ -350,4 +350,4 @@ GPCamera::takePicture(take_picture_request *req) {
if(retval == GP_OK && req->download){
downloadPicture(req);
}
-}
+}
Oops, something went wrong.

0 comments on commit 39474fc

Please sign in to comment.