#include #include #include #include "nan.h" NAN_METHOD(eviocgrab) { assert(info.Length() == 2); if (!info[0]->IsUint32()) Nan::ThrowTypeError("Argument 0 Must be an Integer"); if (!info[1]->IsUint32()) Nan::ThrowTypeError("Argument 1 Must be an Integer"); int fd = Nan::To(info[0]).ToChecked(); int grab = Nan::To(info[1]).ToChecked(); int res = ioctl(fd, EVIOCGRAB, grab); if (res < 0) return Nan::ThrowError( Nan::ErrnoException(errno, "ioctl", nullptr, nullptr)); info.GetReturnValue().Set(res); } NAN_METHOD(eviocgid) { assert(info.Length() == 1); if (!info[0]->IsUint32()) Nan::ThrowTypeError("Argument 0 Must be an Integer"); int fd = Nan::To(info[0]).ToChecked(); struct input_id id; if (ioctl(fd, EVIOCGID, &id) == -1) return Nan::ThrowError( Nan::ErrnoException(errno, "ioctl", nullptr, nullptr)); v8::Local size = Nan::New(); Nan::Set(size, Nan::New("bustype").ToLocalChecked(), Nan::New((double)id.bustype)); Nan::Set(size, Nan::New("vendor" ).ToLocalChecked(), Nan::New((double)id.vendor )); Nan::Set(size, Nan::New("product").ToLocalChecked(), Nan::New((double)id.product)); Nan::Set(size, Nan::New("version").ToLocalChecked(), Nan::New((double)id.version)); info.GetReturnValue().Set(size); } NAN_MODULE_INIT(InitAll) { NAN_EXPORT(target, eviocgrab); NAN_EXPORT(target, eviocgid); } NODE_MODULE(ioctl, InitAll)