30
30
31
31
#include " lib/utils/utils.hpp"
32
32
33
- #include " libUSB .hpp"
33
+ #include " libusb .hpp"
34
34
35
35
namespace GLogiK
36
36
{
37
37
38
38
using namespace NSGKUtils ;
39
39
40
- libusb_context * LibUSB ::pContext = nullptr ;
41
- uint8_t LibUSB ::counter = 0 ;
42
- bool LibUSB ::status = false ;
40
+ libusb_context * libusb ::pContext = nullptr ;
41
+ uint8_t libusb ::counter = 0 ;
42
+ bool libusb ::status = false ;
43
43
44
44
/*
45
45
* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
@@ -51,38 +51,40 @@ bool LibUSB::status = false;
51
51
* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
52
52
*/
53
53
54
- LibUSB::LibUSB (void )
54
+ libusb::libusb (void )
55
55
{
56
- LibUSB ::counter++;
56
+ libusb ::counter++;
57
57
58
- if ( ! LibUSB ::status ) {
58
+ if ( ! libusb ::status ) {
59
59
#if DEBUGGING_ON
60
60
LOG (DEBUG3) << " initializing libusb" ;
61
61
#endif
62
- int ret = libusb_init ( &(LibUSB ::pContext) );
62
+ int ret = libusb_init ( &(libusb ::pContext) );
63
63
if ( this ->USBError (ret) ) {
64
64
throw GLogiKExcept (" libusb initialization failure" );
65
65
}
66
66
67
- LibUSB ::status = true ;
67
+ libusb ::status = true ;
68
68
}
69
69
}
70
70
71
- LibUSB::~LibUSB () {
72
- LibUSB::counter--;
71
+ libusb::~libusb ()
72
+ {
73
+ libusb::counter--;
73
74
74
- if (LibUSB ::status and LibUSB ::counter == 0 ) {
75
+ if (libusb ::status and libusb ::counter == 0 ) {
75
76
#if DEBUGGING_ON
76
77
LOG (DEBUG3) << " closing libusb" ;
77
78
#endif
78
- libusb_exit (LibUSB ::pContext);
79
- LibUSB ::status = false ;
79
+ libusb_exit (libusb ::pContext);
80
+ libusb ::status = false ;
80
81
}
81
82
}
82
83
83
- void LibUSB::openUSBDevice (USBDevice & device) {
84
+ void libusb::openUSBDevice (USBDevice & device)
85
+ {
84
86
libusb_device **list;
85
- int numDevices = libusb_get_device_list (LibUSB ::pContext, &(list));
87
+ int numDevices = libusb_get_device_list (libusb ::pContext, &(list));
86
88
if ( numDevices < 0 ) {
87
89
this ->USBError (numDevices);
88
90
throw GLogiKExcept (" error getting USB devices list" );
@@ -127,7 +129,8 @@ void LibUSB::openUSBDevice(USBDevice & device) {
127
129
}
128
130
}
129
131
130
- void LibUSB::closeUSBDevice (USBDevice & device) noexcept {
132
+ void libusb::closeUSBDevice (USBDevice & device) noexcept
133
+ {
131
134
if ( device.runDeviceUSBRequests () ) {
132
135
/* if we ever claimed or detached some interfaces, set them back
133
136
* to the same state in which we found them */
@@ -144,7 +147,7 @@ void LibUSB::closeUSBDevice(USBDevice & device) noexcept {
144
147
#endif
145
148
}
146
149
147
- void LibUSB ::sendControlRequest (
150
+ void libusb ::sendControlRequest (
148
151
USBDevice & device,
149
152
const unsigned char * data,
150
153
uint16_t wLength)
@@ -194,7 +197,7 @@ void LibUSB::sendControlRequest(
194
197
}
195
198
}
196
199
197
- int LibUSB ::performKeysInterruptTransfer (
200
+ int libusb ::performKeysInterruptTransfer (
198
201
USBDevice & device,
199
202
unsigned int timeout)
200
203
{
@@ -225,7 +228,7 @@ int LibUSB::performKeysInterruptTransfer(
225
228
return ret;
226
229
}
227
230
228
- int LibUSB ::performLCDScreenInterruptTransfer (
231
+ int libusb ::performLCDScreenInterruptTransfer (
229
232
USBDevice & device,
230
233
const unsigned char * buffer,
231
234
int bufferLength,
@@ -272,7 +275,8 @@ int LibUSB::performLCDScreenInterruptTransfer(
272
275
* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
273
276
*/
274
277
275
- int LibUSB::USBError (int errorCode) noexcept {
278
+ int libusb::USBError (int errorCode) noexcept
279
+ {
276
280
switch (errorCode) {
277
281
case LIBUSB_SUCCESS:
278
282
break ;
@@ -287,7 +291,8 @@ int LibUSB::USBError(int errorCode) noexcept {
287
291
return errorCode;
288
292
}
289
293
290
- void LibUSB::releaseUSBDeviceInterfaces (USBDevice & device) noexcept {
294
+ void libusb::releaseUSBDeviceInterfaces (USBDevice & device) noexcept
295
+ {
291
296
int ret = 0 ;
292
297
for (auto it = device._toRelease .begin (); it != device._toRelease .end ();) {
293
298
int numInt = (*it);
@@ -322,7 +327,8 @@ void LibUSB::releaseUSBDeviceInterfaces(USBDevice & device) noexcept {
322
327
* libusb_set_configuration() may succeed.
323
328
*
324
329
*/
325
- void LibUSB::setUSBDeviceActiveConfiguration (USBDevice & device) {
330
+ void libusb::setUSBDeviceActiveConfiguration (USBDevice & device)
331
+ {
326
332
int ret = 0 ;
327
333
328
334
#if DEBUGGING_ON
@@ -407,7 +413,7 @@ void LibUSB::setUSBDeviceActiveConfiguration(USBDevice & device) {
407
413
this ->attachUSBDeviceInterfacesToKernelDrivers (device);
408
414
}
409
415
410
- void LibUSB ::findUSBDeviceInterface (USBDevice & device) {
416
+ void libusb ::findUSBDeviceInterface (USBDevice & device) {
411
417
int ret = 0 ;
412
418
413
419
#if DEBUGGING_ON
@@ -684,9 +690,10 @@ void LibUSB::findUSBDeviceInterface(USBDevice & device) {
684
690
685
691
libusb_free_config_descriptor ( configDescriptor ); /* free */
686
692
} /* for .bNumConfigurations */
687
-
688
693
}
689
- void LibUSB::attachUSBDeviceInterfacesToKernelDrivers (USBDevice & device) noexcept {
694
+
695
+ void libusb::attachUSBDeviceInterfacesToKernelDrivers (USBDevice & device) noexcept
696
+ {
690
697
int ret = 0 ;
691
698
for (auto it = device._toAttach .begin (); it != device._toAttach .end ();) {
692
699
int numInt = (*it);
@@ -704,7 +711,8 @@ void LibUSB::attachUSBDeviceInterfacesToKernelDrivers(USBDevice & device) noexce
704
711
device._toAttach .clear ();
705
712
}
706
713
707
- void LibUSB::detachKernelDriverFromUSBDeviceInterface (USBDevice & device, int numInt) {
714
+ void libusb::detachKernelDriverFromUSBDeviceInterface (USBDevice & device, int numInt)
715
+ {
708
716
int ret = libusb_kernel_driver_active (device._pUSBDeviceHandle , numInt);
709
717
if ( ret < 0 ) {
710
718
this ->USBError (ret);
0 commit comments