-
Notifications
You must be signed in to change notification settings - Fork 4
/
eviocgrab.cpp
42 lines (31 loc) · 1002 Bytes
/
eviocgrab.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/input.h>
#include "nan.h"
using namespace v8;
using namespace node;
NAN_METHOD(Eviocgrab) {
Nan::HandleScope scope;
Local<Object> buf;
int length = info.Length();
assert(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);
}
void InitAll(Local<Object> exports) {
Nan::Set(exports,
Nan::New("eviocgrab").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(Eviocgrab)).ToLocalChecked());
}
NODE_MODULE(eviocgrab, InitAll)