diff options
Diffstat (limited to 'lib/ioctl.cpp')
-rw-r--r-- | lib/ioctl.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/ioctl.cpp b/lib/ioctl.cpp new file mode 100644 index 0000000..32af5fa --- /dev/null +++ b/lib/ioctl.cpp @@ -0,0 +1,42 @@ +#include <errno.h> +#include <sys/ioctl.h> +#include <linux/input.h> +#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<int32_t>(info[0]).ToChecked(); + int grab = Nan::To<int32_t>(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<int32_t>(info[0]).ToChecked(); + + struct input_id id; + if (ioctl(fd, EVIOCGID, &id) == -1) return Nan::ThrowError( + Nan::ErrnoException(errno, "ioctl", nullptr, nullptr)); + + v8::Local<v8::Object> size = Nan::New<v8::Object>(); + 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) |