FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
node-usb/src/node_usb.h at main · node-usb/node-usb · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
node-usb
/
node-usb
Public
Notifications
You must be signed in to change notification settings
Fork
288
Star
1.7k
Code
Issues
11
Pull requests
2
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
node-usb
/
src
/
node_usb.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
137 lines (104 loc) · 3.88 KB
Breadcrumbs
node-usb
/
src
/
node_usb.h
Copy path
File metadata and controls
137 lines (104 loc) · 3.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#
ifndef
SRC_NODE_USB_H
#
define
SRC_NODE_USB_H
#
include
<
assert.h
>
#
include
<
string
>
#
include
<
map
>
#
ifdef
_WIN32
#
include
<
WinSock2.h
>
#
endif
#
include
<
thread
>
#
include
<
atomic
>
#
include
<
libusb.h
>
#
include
<
napi.h
>
#
include
"
helpers.h
"
#
include
"
uv_async_queue.h
"
struct
Transfer
;
struct
HotPlug
;
class
HotPlugManager
;
Napi::Error
libusbException
(Napi::Env env,
int
errorno);
void
handleCompletion
(Transfer* self);
struct
Device
:
public
Napi
::ObjectWrap<Device> {
Napi::Env env;
libusb_device* device;
libusb_device_handle* device_handle;
int
refs_;
UVQueue<Transfer*> completionQueue;
static
Napi::Object
Init
(Napi::Env env, Napi::Object exports);
static
Napi::Object
get
(Napi::Env env, libusb_device* handle);
inline
void
ref
(){ refs_ =
Ref
();}
inline
void
unref
(){ refs_ =
Unref
();}
inline
bool
canClose
(){
return
refs_ ==
0
;}
Device
(
const
Napi::CallbackInfo& info);
~Device
();
static
Napi::Object
cdesc2V8
(Napi::Env env, libusb_config_descriptor * cdesc);
Napi::Value
GetConfigDescriptor
(
const
Napi::CallbackInfo& info);
Napi::Value
GetAllConfigDescriptors
(
const
Napi::CallbackInfo& info);
Napi::Value
SetConfiguration
(
const
Napi::CallbackInfo& info);
Napi::Value
GetParent
(
const
Napi::CallbackInfo& info);
Napi::Value
Open
(
const
Napi::CallbackInfo& info);
Napi::Value
Reset
(
const
Napi::CallbackInfo& info);
Napi::Value
Close
(
const
Napi::CallbackInfo& info);
Napi::Value
IsKernelDriverActive
(
const
Napi::CallbackInfo& info);
Napi::Value
DetachKernelDriver
(
const
Napi::CallbackInfo& info);
Napi::Value
AttachKernelDriver
(
const
Napi::CallbackInfo& info);
Napi::Value
SetAutoDetachKernelDriver
(
const
Napi::CallbackInfo& info);
Napi::Value
ClaimInterface
(
const
Napi::CallbackInfo& info);
Napi::Value
SetInterface
(
const
Napi::CallbackInfo& info);
Napi::Value
ReleaseInterface
(
const
Napi::CallbackInfo& info);
Napi::Value
ClearHalt
(
const
Napi::CallbackInfo& info);
protected:
Napi::Value
Constructor
(
const
Napi::CallbackInfo& info);
};
struct
ModuleData
{
libusb_context* usb_context;
std::thread usb_thread;
std::atomic<
bool
> handlingEvents;
bool
hotplugEnabled =
0
;
std::unique_ptr<HotPlugManager> hotplugManager;
UVQueue<HotPlug*> hotplugQueue;
Napi::ObjectReference hotplugThis;
std::map<libusb_device*, Device*> byPtr;
Napi::FunctionReference deviceConstructor;
ModuleData
(libusb_context* usb_context);
~ModuleData
();
};
struct
Transfer
:
public
Napi
::ObjectWrap<Transfer> {
libusb_transfer* transfer;
Device* device;
Napi::ObjectReference v8buffer;
Napi::FunctionReference v8callback;
static
Napi::Object
Init
(Napi::Env env, Napi::Object exports);
inline
void
ref
(){
Ref
();}
inline
void
unref
(){
Unref
();}
Transfer
(
const
Napi::CallbackInfo& info);
~Transfer
();
Napi::Value
Submit
(
const
Napi::CallbackInfo& info);
Napi::Value
Cancel
(
const
Napi::CallbackInfo& info);
private:
Napi::Value
Constructor
(
const
Napi::CallbackInfo& info);
};
#
define
CHECK_USB_CLEANUP
(
r, cleanup
) \
do
{ \
int
_r = (r); \
if
(_r <
LIBUSB_SUCCESS
) { \
cleanup \
throw
libusbException
(env, _r); \
} \
}
while
(
0
)
#
define
CHECK_USB
(
r
)
CHECK_USB_CLEANUP
(r, {})
#
define
CALLBACK_ARG
(
CALLBACK_ARG_IDX
) \
Napi::Function callback; \
if
(info.Length() > (
CALLBACK_ARG_IDX
)) { \
if
(!info[
CALLBACK_ARG_IDX
].
IsFunction
()) { \
throw
Napi::TypeError::New
(env,
"
Argument
"
#
CALLBACK_ARG_IDX
"
must be a function
"
); \
} \
callback = info[
CALLBACK_ARG_IDX
].
As
<Napi::Function>(); \
} \
#
ifdef
DEBUG
#
define
DEBUG_HEADER
fprintf
(stderr,
"
node-usb [%s:%s() %d]:
"
, __FILE__, __FUNCTION__, __LINE__);
#
define
DEBUG_FOOTER
fprintf
(stderr,
"
\n
"
);
#
define
DEBUG_LOG
(...)
DEBUG_HEADER
fprintf
(stderr, __VA_ARGS__);
DEBUG_FOOTER
#
else
#
define
DEBUG_LOG
(...)
#
endif
#
endif
Back
|
FazBrowse Home
|
New Git URL