Permalink
Browse files

- libev replaced with libuv

- removed EventEmitter and node_events.h dependency
- BUG: still problems with ev_rt_now - not able to solve this at the moment (node.js in latest v0.5 and v0.6 and pre-v0.7.0)
  • Loading branch information...
1 parent f040d39 commit 435e8b97ded4343348c6f9cdc47230a377e9b65d Christopher Klein committed Jan 10, 2012
Showing with 57 additions and 83 deletions.
  1. +9 −3 src/bindings.h
  2. +8 −23 src/device.cc
  3. +5 −5 src/device.h
  4. +6 −10 src/endpoint.cc
  5. +5 −5 src/endpoint.h
  6. +9 −27 src/interface.cc
  7. +5 −5 src/interface.h
  8. +2 −1 src/node_usb.cc
  9. +3 −1 src/node_usb.h
  10. +2 −2 src/usb.cc
  11. +2 −1 src/usb.h
  12. +1 −0 wscript
View
@@ -50,6 +50,12 @@
HandleScope scope;\
TYPE *VARNAME = OBJUNWRAP<TYPE>(REF);
+#define EIO_CUSTOM(FUNC, STRUCTURE, CALLBACK) \
+ uv_work_t* req = new uv_work_t();\
+ req->data = STRUCTURE;\
+ uv_queue_work(uv_default_loop(), req, FUNC, CALLBACK);\
+ uv_ref(uv_default_loop());
+
#define EIO_CAST(TYPE, VARNAME) struct TYPE *VARNAME = reinterpret_cast<struct TYPE *>(req->data);
#define EIO_NEW(TYPE, VARNAME) struct TYPE *VARNAME = (struct TYPE *) calloc(1, sizeof(struct TYPE));
#define EIO_DELEGATION(VARNAME, CALLBACK_ARG_IDX) \
@@ -64,19 +70,19 @@
VARNAME->error = Persistent<Object>::New(Object::New()); \
#define EIO_AFTER(VARNAME) HandleScope scope; \
- ev_unref(EV_DEFAULT_UC); \
+ uv_unref(uv_default_loop()); \
if (sizeof(VARNAME->callback) > 0) { \
Local<Value> argv[1]; \
argv[0] = Local<Value>::New(scope.Close(VARNAME->error)); \
VARNAME->callback->Call(Context::GetCurrent()->Global(), 1, argv); \
VARNAME->callback.Dispose(); \
- }
+ }\
+ delete req;
#define TRANSFER_REQUEST_FREE(STRUCT)\
EIO_CAST(STRUCT, transfer_req)\
EIO_AFTER(transfer_req)\
free(transfer_req);\
- return 0;
#define INIT_TRANSFER_CALL(MINIMUM_ARG_LENGTH, CALLBACK_ARG_IDX, TIMEOUT_ARG_IDX) \
libusb_endpoint_direction modus; \
View
@@ -45,7 +45,7 @@ namespace NodeUsb {
DEBUG("Leave")
}
- Device::Device(libusb_device* _device) {
+ Device::Device(libusb_device* _device) : ObjectWrap() {
device_container = (nodeusb_device_container*)malloc(sizeof(nodeusb_device_container));
device_container->device = _device;
}
@@ -134,19 +134,15 @@ namespace NodeUsb {
reset_req->device = self->device_container->device;
- // Make asynchronous call
- eio_custom(EIO_Reset, EIO_PRI_DEFAULT, EIO_After_Reset, reset_req);
-
- // add reference
- ev_ref(EV_DEFAULT_UC);
-
+ EIO_CUSTOM(EIO_Reset, reset_req, EIO_After_Reset);
+
return Undefined();
}
/**
* Contains the blocking libusb_reset_device function
*/
- int Device::EIO_Reset(eio_req *req) {
+ void Device::EIO_Reset(uv_work_t *req) {
EIO_CAST(device_request, reset_req)
libusb_device_handle *handle;
@@ -163,21 +159,14 @@ namespace NodeUsb {
}
reset_req->error->Set(V8STR("error_code"), Uint32::New(errcode));
-
- // needed for EIO so that the EIO_After_Reset method will be called
- req->result = 0;
-
- return 0;
}
- int Device::EIO_After_Reset(eio_req *req) {
+ void Device::EIO_After_Reset(uv_work_t *req) {
EIO_CAST(device_request, reset_req)
EIO_AFTER(reset_req)
// release intermediate structure
free(reset_req);
-
- return 0;
}
@@ -362,14 +351,13 @@ namespace NodeUsb {
EIO_DELEGATION(control_transfer_req, 5)
- eio_custom(EIO_ControlTransfer, EIO_PRI_DEFAULT, EIO_After_ControlTransfer, control_transfer_req);
- ev_ref(EV_DEFAULT_UC);
+ EIO_CUSTOM(EIO_ControlTransfer, control_transfer_req, EIO_After_ControlTransfer);
return Undefined();
}
- int Device::EIO_ControlTransfer(eio_req *req) {
+ void Device::EIO_ControlTransfer(uv_work_t *req) {
EIO_CAST(control_transfer_request, ct_req)
int errcode = 0;
@@ -378,12 +366,9 @@ namespace NodeUsb {
}
ct_req->error->Set(V8STR("error_code"), Uint32::New(errcode));
- req->result = 0;
-
- return 0;
}
- int Device::EIO_After_ControlTransfer(eio_req *req) {
+ void Device::EIO_After_ControlTransfer(uv_work_t *req) {
TRANSFER_REQUEST_FREE(control_transfer_request)
}
}
View
@@ -4,7 +4,7 @@
#include "bindings.h"
namespace NodeUsb {
- class Device : public EventEmitter {
+ class Device : public ObjectWrap {
public:
// called from outside to initalize V8 class template
static void Initalize(Handle<Object> target);
@@ -37,15 +37,15 @@ namespace NodeUsb {
static Handle<Value> RemoveReference(const Arguments& args);
static Handle<Value> Reset(const Arguments& args);
// Reset -> Async
- static int EIO_After_Reset(eio_req *req);
- static int EIO_Reset(eio_req *req);
+ static void EIO_Reset(uv_work_t *req);
+ static void EIO_After_Reset(uv_work_t *req);
static Handle<Value> GetConfigDescriptor(const Arguments& args);
static Handle<Value> GetDeviceDescriptor(const Arguments& args);
static Handle<Value> GetExtraData(const Arguments& args);
static Handle<Value> GetInterfaces(const Arguments& args);
static Handle<Value> ControlTransfer(const Arguments& args);
- static int EIO_ControlTransfer(eio_req *req);
- static int EIO_After_ControlTransfer(eio_req *req);
+ static void EIO_ControlTransfer(uv_work_t *req);
+ static void EIO_After_ControlTransfer(uv_work_t *req);
};
}
#endif
View
@@ -4,7 +4,7 @@
namespace NodeUsb {
Persistent<FunctionTemplate> Endpoint::constructor_template;
- Endpoint::Endpoint(nodeusb_device_container* _device_container, const libusb_endpoint_descriptor* _endpoint_descriptor, uint32_t _idx_endpoint) {
+ Endpoint::Endpoint(nodeusb_device_container* _device_container, const libusb_endpoint_descriptor* _endpoint_descriptor, uint32_t _idx_endpoint) : ObjectWrap() {
device_container = _device_container;
descriptor = _endpoint_descriptor;
// if bit[7] of endpoint address is set => ENDPOINT_IN (device to host), else: ENDPOINT_OUT (host to device)
@@ -244,45 +244,41 @@ namespace NodeUsb {
bulk_interrupt_transfer_req->length = buflen;\
bulk_interrupt_transfer_req->data = buf;\
bulk_interrupt_transfer_req->endpoint = self->descriptor->bEndpointAddress;\
- eio_custom(EIO_TO_EXECUTE, EIO_PRI_DEFAULT, EIO_AFTER, bulk_interrupt_transfer_req);\
- ev_ref(EV_DEFAULT_UC);\
+ EIO_CUSTOM(EIO_TO_EXECUTE, bulk_interrupt_transfer_req, EIO_AFTER)\
return Undefined();
#define BULK_INTERRUPT_FREE TRANSFER_REQUEST_FREE(bulk_interrupt_transfer_request)
-
#define BULK_INTERRUPT_EXECUTE(METHOD, SOURCE)\
EIO_CAST(bulk_interrupt_transfer_request, bit_req)\
int errcode = 0;\
if ((errcode = libusb_bulk_transfer(bit_req->handle, bit_req->endpoint, bit_req->data, bit_req->length, &(bit_req->transferred), bit_req->timeout)) < LIBUSB_SUCCESS) {\
bit_req->error->Set(V8STR("error_source"), V8STR(SOURCE));\
}\
bit_req->error->Set(V8STR("error_code"), Uint32::New(errcode));\
- req->result = 0;\
- return 0;
Handle<Value> Endpoint::BulkTransfer(const Arguments& args) {
BULK_INTERRUPT_EIO(EIO_BulkTransfer, EIO_After_BulkTransfer)
}
- int Endpoint::EIO_BulkTransfer(eio_req *req) {
+ void Endpoint::EIO_BulkTransfer(uv_work_t *req) {
BULK_INTERRUPT_EXECUTE(libusb_bulk_transfer, "bulkTransfer")
}
- int Endpoint::EIO_After_BulkTransfer(eio_req *req) {
+ void Endpoint::EIO_After_BulkTransfer(uv_work_t *req) {
BULK_INTERRUPT_FREE
}
Handle<Value> Endpoint::InterruptTransfer(const Arguments& args) {
BULK_INTERRUPT_EIO(EIO_InterruptTransfer, EIO_After_InterruptTransfer)
}
- int Endpoint::EIO_InterruptTransfer(eio_req *req) {
+ void Endpoint::EIO_InterruptTransfer(uv_work_t *req) {
BULK_INTERRUPT_EXECUTE(libusb_interrupt_transfer, "interruptTransfer")
}
- int Endpoint::EIO_After_InterruptTransfer(eio_req *req) {
+ void Endpoint::EIO_After_InterruptTransfer(uv_work_t *req) {
BULK_INTERRUPT_FREE
}
}
View
@@ -8,7 +8,7 @@ namespace NodeUsb {
static void DispatchAsynchronousUsbTransfer(libusb_transfer *_transfer);
};
- class Endpoint : public EventEmitter {
+ class Endpoint : public ObjectWrap {
public:
static void Initalize(Handle<Object> target);
static Persistent<FunctionTemplate> constructor_template;
@@ -41,11 +41,11 @@ namespace NodeUsb {
static Handle<Value> Submit(const Arguments& args);
static Handle<Value> GetExtraData(const Arguments& args);
static Handle<Value> BulkTransfer(const Arguments& args);
- static int EIO_BulkTransfer(eio_req *req);
- static int EIO_After_BulkTransfer(eio_req *req);
+ static void EIO_BulkTransfer(uv_work_t *req);
+ static void EIO_After_BulkTransfer(uv_work_t *req);
static Handle<Value> InterruptTransfer(const Arguments& args);
- static int EIO_InterruptTransfer(eio_req *req);
- static int EIO_After_InterruptTransfer(eio_req *req);
+ static void EIO_InterruptTransfer(uv_work_t *req);
+ static void EIO_After_InterruptTransfer(uv_work_t *req);
};
View
@@ -5,7 +5,7 @@
namespace NodeUsb {
Persistent<FunctionTemplate> Interface::constructor_template;
- Interface::Interface(nodeusb_device_container* _device_container, const libusb_interface_descriptor* _interface_descriptor, uint32_t _idx_interface, uint32_t _idx_alt_setting) {
+ Interface::Interface(nodeusb_device_container* _device_container, const libusb_interface_descriptor* _interface_descriptor, uint32_t _idx_interface, uint32_t _idx_alt_setting) : ObjectWrap() {
device_container = _device_container;
descriptor = _interface_descriptor;
idx_interface = _idx_interface;
@@ -187,17 +187,14 @@ namespace NodeUsb {
release_req->handle = self->device_container->handle;
release_req->interface_number = self->descriptor->bInterfaceNumber;
- eio_custom(EIO_Release, EIO_PRI_DEFAULT, EIO_After_Release, release_req);
+
+ EIO_CUSTOM(EIO_Release, release_req, EIO_After_Release);
- // add reference
- ev_ref(EV_DEFAULT_UC);
-
return Undefined();
}
- int Interface::EIO_Release(eio_req *req) {
+ void Interface::EIO_Release(uv_work_t *req) {
EIO_CAST(release_request, release_req)
-
int errcode = 0;
@@ -206,20 +203,13 @@ namespace NodeUsb {
}
release_req->error->Set(V8STR("error_code"), Uint32::New(errcode));
-
- // needed for EIO so that the EIO_After_Reset method will be called
- req->result = 0;
-
- return 0;
}
- int Interface::EIO_After_Release(eio_req *req) {
+ void Interface::EIO_After_Release(uv_work_t *req) {
EIO_CAST(release_request, release_req)
EIO_AFTER(release_req)
free(release_req);
-
- return 0;
}
/**
@@ -244,15 +234,13 @@ namespace NodeUsb {
alt_req->handle = self->device_container->handle;
alt_req->interface_number = self->descriptor->bInterfaceNumber;
alt_req->alternate_setting = args[0]->Uint32Value();
- eio_custom(EIO_AlternateSetting, EIO_PRI_DEFAULT, EIO_After_AlternateSetting, alt_req);
+
+ EIO_CUSTOM(EIO_AlternateSetting, alt_req, EIO_After_AlternateSetting);
- // add reference
- ev_ref(EV_DEFAULT_UC);
-
return Undefined();
}
- int Interface::EIO_AlternateSetting(eio_req *req) {
+ void Interface::EIO_AlternateSetting(uv_work_t *req) {
EIO_CAST(alternate_setting_request, alt_req)
int errcode = 0;
@@ -262,19 +250,13 @@ namespace NodeUsb {
}
alt_req->error->Set(V8STR("error_code"), Uint32::New(errcode));
-
- req->result = 0;
-
- return 0;
}
- int Interface::EIO_After_AlternateSetting(eio_req *req) {
+ void Interface::EIO_After_AlternateSetting(uv_work_t *req) {
EIO_CAST(alternate_setting_request, alt_req)
EIO_AFTER(alt_req)
free(alt_req);
-
- return 0;
}
Handle<Value> Interface::GetEndpoints(const Arguments& args) {
View
@@ -4,7 +4,7 @@
#include "bindings.h"
namespace NodeUsb {
- class Interface : public EventEmitter {
+ class Interface : public ObjectWrap {
public:
static void Initalize(Handle<Object> target);
static Persistent<FunctionTemplate> constructor_template;
@@ -35,15 +35,15 @@ namespace NodeUsb {
int interface_number;
};
static Handle<Value> Release(const Arguments& args);
- static int EIO_Release(eio_req *req);
- static int EIO_After_Release(eio_req *req);
+ static void EIO_Release(uv_work_t *req);
+ static void EIO_After_Release(uv_work_t *req);
struct alternate_setting_request:release_request {
int alternate_setting;
};
static Handle<Value> AlternateSetting(const Arguments& args);
- static int EIO_AlternateSetting(eio_req *req);
- static int EIO_After_AlternateSetting(eio_req *req);
+ static void EIO_AlternateSetting(uv_work_t *req);
+ static void EIO_After_AlternateSetting(uv_work_t *req);
};
}
View
@@ -19,10 +19,11 @@ namespace NodeUsb {
context->Global()->Set(String::NewSymbol("Usb"), target);
}
- extern "C" void init(Handle<Object> target) {
+ void init(Handle<v8::Object> target) {
DEBUG("Initalizing NodeUsb")
HandleScope scope;
InitalizeAll(target);
}
}
+NODE_MODULE(usb_bindings, NodeUsb::init)
View
@@ -11,8 +11,10 @@
#include <unistd.h>
#include <node.h>
+#include <node_version.h>
#include <node_buffer.h>
-#include <node_events.h>
+#include <uv.h>
+#include <uv-private/ev.h>
#include <cstring>
#include <string>
#include <cstdlib>
Oops, something went wrong.

0 comments on commit 435e8b9

Please sign in to comment.