Change log level for some error messages

Contrary to expectations, G15_LOG_WARN is more verbose level than
G15_LOG_INFO.
This commit is contained in:
Alexander Ponyatykh committed 2019-11-18 02:50:24 +03:00
1 parent 98449afc5d
commit aa2cf02029
2 files changed
+55 -51

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ libg15 (1.3.0~svn324-2) unstable; urgency=medium
* Migrate from legacy libusb-0.1 to libusb-1.0 (closes: bug#810409, * Migrate from legacy libusb-0.1 to libusb-1.0 (closes: bug#810409,
bug#611649). bug#611649).
-- Alexander Ponyatykh <lazyranma@gmail.com> Sun, 17 Nov 2019 00:17:00 +0300 -- Alexander Ponyatykh <lazyranma@gmail.com> Sun, 17 Nov 2019 03:14:55 +0300
libg15 (1.3.0~svn324-1) unstable; urgency=medium libg15 (1.3.0~svn324-1) unstable; urgency=medium
@@ -4,12 +4,14 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
--- ---
configure.in | 5 +- configure.in | 5 +-
libg15.c | 458 ++++++++++++++++++++++++++++------------------------------- libg15.c | 476 +++++++++++++++++++++++++++++------------------------------
2 files changed, 222 insertions(+), 241 deletions(-) 2 files changed, 234 insertions(+), 247 deletions(-)
diff --git a/configure.in b/configure.in
index 074d98e..b533d2c 100644
--- a/configure.in --- a/configure.in
+++ b/configure.in +++ b/configure.in
@@ -31,7 +31,8 @@ @@ -31,7 +31,8 @@ case $host_os in
esac esac
# Checks for libraries. # Checks for libraries.
@@ -19,7 +21,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
dnl Some versions of libusb do not honour timeout and block. Suns' version is one of them. dnl Some versions of libusb do not honour timeout and block. Suns' version is one of them.
if test "x$libusb_blocks" == "xtrue"; then if test "x$libusb_blocks" == "xtrue"; then
@@ -41,7 +42,7 @@ @@ -41,7 +42,7 @@ fi
# Checks for header files. # Checks for header files.
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS([string.h]) AC_CHECK_HEADERS([string.h])
@@ -28,6 +30,8 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
# Checks for typedefs, structures, and compiler characteristics. # Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST AC_C_CONST
diff --git a/libg15.c b/libg15.c
index ba1c94b..435e396 100644
--- a/libg15.c --- a/libg15.c
+++ b/libg15.c +++ b/libg15.c
@@ -24,14 +24,15 @@ @@ -24,14 +24,15 @@
@@ -49,7 +53,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
static int found_devicetype = -1; static int found_devicetype = -1;
static int shared_device = 0; static int shared_device = 0;
@@ -67,7 +68,9 @@ @@ -67,7 +68,9 @@ int g15DeviceCapabilities() {
void libg15Debug(int option) { void libg15Debug(int option) {
libg15_debugging_enabled = option; libg15_debugging_enabled = option;
@@ -60,7 +64,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
} }
/* debugging wrapper */ /* debugging wrapper */
@@ -86,191 +89,209 @@ @@ -86,191 +89,209 @@ static int g15_log (FILE *fd, unsigned int level, const char *fmt, ...) {
/* return number of connected and supported devices */ /* return number of connected and supported devices */
int g15NumberOfConnectedDevices() { int g15NumberOfConnectedDevices() {
@@ -77,7 +81,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
+ +
+ if (cnt < 0) + if (cnt < 0)
+ { + {
+ g15_log(stderr, G15_LOG_WARN, "Unable to list USB devices: %s\n", libusb_strerror(cnt)); + g15_log(stderr, G15_LOG_INFO, "Unable to list USB devices: %s\n", libusb_strerror(cnt));
+ return 0; + return 0;
+ } + }
+ +
@@ -104,17 +108,17 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
static int initLibUsb() static int initLibUsb()
{ {
- usb_init(); - usb_init();
+ int errcode = libusb_init(NULL); -
- /** - /**
- * usb_find_busses and usb_find_devices both report the number of devices - * usb_find_busses and usb_find_devices both report the number of devices
- * / busses added / removed since the last call. since this is the first - * / busses added / removed since the last call. since this is the first
- * call we have to return values != 0 or else we didnt find anything */ - * call we have to return values != 0 or else we didnt find anything */
- + int errcode = libusb_init(NULL);
- if (!usb_find_busses()) - if (!usb_find_busses())
+ if (errcode != 0) + if (errcode != 0)
+ { + {
+ g15_log(stderr, G15_LOG_WARN, "Failed to initialize libusb-1.0: %s\n", libusb_strerror(errcode)); + g15_log(stderr, G15_LOG_INFO, "Failed to initialize libusb-1.0: %s\n", libusb_strerror(errcode));
return G15_ERROR_OPENING_USB_DEVICE; return G15_ERROR_OPENING_USB_DEVICE;
+ } + }
@@ -144,17 +148,17 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
+ int ret; + int ret;
+ +
+ ssize_t cnt = libusb_get_device_list(NULL, &list); + ssize_t cnt = libusb_get_device_list(NULL, &list);
+
+ if (cnt < 0)
+ {
+ g15_log(stderr, G15_LOG_WARN, "Unable to list USB devices: %s\n", libusb_strerror(cnt));
+ return 0;
+ }
- for (bus = usb_busses; bus; bus = bus->next) - for (bus = usb_busses; bus; bus = bus->next)
+ for (ssize_t devno = 0; devno < cnt; devno++) + if (cnt < 0)
{ {
- for (dev = bus->devices; dev; dev = dev->next) - for (dev = bus->devices; dev; dev = dev->next)
+ g15_log(stderr, G15_LOG_INFO, "Unable to list USB devices: %s\n", libusb_strerror(cnt));
+ return 0;
+ }
+
+ for (ssize_t devno = 0; devno < cnt; devno++)
+ {
+ libusb_get_device_descriptor(list[devno], &desc); + libusb_get_device_descriptor(list[devno], &desc);
+ if (desc.idVendor == handled_device.vendorid && desc.idProduct == handled_device.productid) + if (desc.idVendor == handled_device.vendorid && desc.idProduct == handled_device.productid)
{ {
@@ -190,33 +194,38 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
+ } + }
+ +
+ found_devicetype = device_index; + found_devicetype = device_index;
+
+ g15_log(stderr,G15_LOG_INFO,"Found %s, trying to open it\n",handled_device.name);
- usleep(50*1000); - usleep(50*1000);
+ g15_log(stderr,G15_LOG_INFO,"Found %s, trying to open it\n",handled_device.name);
+
+ ret = libusb_open(dev, &devh); + ret = libusb_open(dev, &devh);
+ libusb_free_device_list(list, 1); + libusb_free_device_list(list, 1);
+
- g15_log(stderr, G15_LOG_INFO, "Device has %i possible configurations\n",dev->descriptor.bNumConfigurations);
+ if (ret || !devh) + if (ret || !devh)
+ { + {
+ g15_log(stderr,G15_LOG_WARN, "Error, could not open the keyboard: %s\n", libusb_strerror(ret)); + g15_log(stderr,G15_LOG_INFO, "Error, could not open the keyboard: %s\n", libusb_strerror(ret));
+ return 0; + return 0;
+ } + }
+ +
+ usleep(50*1000); + usleep(50*1000);
+ +
+ g15_log(stderr, G15_LOG_INFO, "Device has %i possible configurations\n", desc.bNumConfigurations); + g15_log(stderr, G15_LOG_INFO, "Device has %i possible configurations\n", desc.bNumConfigurations);
+
- /* if device is shared with another driver, such as the Z-10 speakers sharing with alsa, we have to disable some calls */
- if(g15DeviceCapabilities() & G15_DEVICE_IS_SHARED)
- shared_device = 1;
+ /* if device is shared with another driver, such as the Z-10 speakers sharing with alsa, we have to disable some calls */ + /* if device is shared with another driver, such as the Z-10 speakers sharing with alsa, we have to disable some calls */
+ if(g15DeviceCapabilities() & G15_DEVICE_IS_SHARED) + if(g15DeviceCapabilities() & G15_DEVICE_IS_SHARED)
+ shared_device = 1; + shared_device = 1;
+
- for (j = 0; j<dev->descriptor.bNumConfigurations;j++){
- struct usb_config_descriptor *cfg = &dev->config[j];
+ for (int j = 0; j < desc.bNumConfigurations; j++) + for (int j = 0; j < desc.bNumConfigurations; j++)
+ { + {
+ struct libusb_config_descriptor *cfg; + struct libusb_config_descriptor *cfg;
+ if (libusb_get_config_descriptor(dev, j, &cfg)) continue; + if (libusb_get_config_descriptor(dev, j, &cfg)) continue;
+
- g15_log(stderr, G15_LOG_INFO, "Device has %i possible configurations\n",dev->descriptor.bNumConfigurations);
+ for (int i = 0; i < cfg->bNumInterfaces; i++) + for (int i = 0; i < cfg->bNumInterfaces; i++)
+ { + {
+ if (g15DeviceCapabilities() & G15_DEVICE_G510) + if (g15DeviceCapabilities() & G15_DEVICE_G510)
@@ -224,17 +233,15 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
+ if (i==G510_STANDARD_KEYBOARD_INTERFACE) continue; + if (i==G510_STANDARD_KEYBOARD_INTERFACE) continue;
+ } + }
- /* if device is shared with another driver, such as the Z-10 speakers sharing with alsa, we have to disable some calls */ - for (i=0;i<cfg->bNumInterfaces; i++){
- if(g15DeviceCapabilities() & G15_DEVICE_IS_SHARED) - if (g15DeviceCapabilities()&G15_DEVICE_G510){
- shared_device = 1; - if (i==G510_STANDARD_KEYBOARD_INTERFACE) continue;
+ const struct libusb_interface *ifp = &cfg->interface[i]; + const struct libusb_interface *ifp = &cfg->interface[i];
+ /* if endpoints are already known, finish up */ + /* if endpoints are already known, finish up */
+ if (g15_keys_endpoint && g15_lcd_endpoint) + if (g15_keys_endpoint && g15_lcd_endpoint)
+ break; + break;
+ g15_log(stderr, G15_LOG_INFO, "Device has %i Alternate Settings\n", ifp->num_altsetting); + g15_log(stderr, G15_LOG_INFO, "Device has %i Alternate Settings\n", ifp->num_altsetting);
+
- for (j = 0; j<dev->descriptor.bNumConfigurations;j++){
- struct usb_config_descriptor *cfg = &dev->config[j];
+ for (int k=0; k < ifp->num_altsetting; k++) + for (int k=0; k < ifp->num_altsetting; k++)
+ { + {
+ const struct libusb_interface_descriptor *as = &ifp->altsetting[k]; + const struct libusb_interface_descriptor *as = &ifp->altsetting[k];
@@ -243,10 +250,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
+ { + {
+ g15_log(stderr, G15_LOG_INFO, "Interface %i has %i Endpoints\n", i, as->bNumEndpoints); + g15_log(stderr, G15_LOG_INFO, "Interface %i has %i Endpoints\n", i, as->bNumEndpoints);
+ usleep(50*1000); + usleep(50*1000);
+
- for (i=0;i<cfg->bNumInterfaces; i++){
- if (g15DeviceCapabilities()&G15_DEVICE_G510){
- if (i==G510_STANDARD_KEYBOARD_INTERFACE) continue;
+ if (libusb_kernel_driver_active(devh, i) == 1) + if (libusb_kernel_driver_active(devh, i) == 1)
+ { + {
+ g15_log(stderr, G15_LOG_INFO, "Trying to detach driver currently attached.\n"); + g15_log(stderr, G15_LOG_INFO, "Trying to detach driver currently attached.\n");
@@ -414,7 +418,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
int i; int i;
for (i=0; g15_devices[i].name !=NULL ;i++){ for (i=0; g15_devices[i].name !=NULL ;i++){
g15_log(stderr,G15_LOG_INFO,"Trying to find %s\n",g15_devices[i].name); g15_log(stderr,G15_LOG_INFO,"Trying to find %s\n",g15_devices[i].name);
@@ -288,19 +309,13 @@ @@ -288,19 +309,13 @@ static int closeKeyboardDevice()
{ {
int retval = G15_NO_ERROR; int retval = G15_NO_ERROR;
@@ -439,7 +443,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
keyboard_device=0; keyboard_device=0;
return retval; return retval;
} }
@@ -311,9 +326,6 @@ @@ -311,9 +326,6 @@ int re_initLibG15()
{ {
closeKeyboardDevice(); closeKeyboardDevice();
@@ -449,7 +453,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
keyboard_device = findAndOpenG15(); keyboard_device = findAndOpenG15();
if (!keyboard_device) if (!keyboard_device)
return G15_ERROR_OPENING_USB_DEVICE; return G15_ERROR_OPENING_USB_DEVICE;
@@ -330,10 +342,6 @@ @@ -330,10 +342,6 @@ int initLibG15()
g15_log(stderr,G15_LOG_INFO,"%s\n",PACKAGE_STRING); g15_log(stderr,G15_LOG_INFO,"%s\n",PACKAGE_STRING);
@@ -460,7 +464,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
g15NumberOfConnectedDevices(); g15NumberOfConnectedDevices();
keyboard_device = findAndOpenG15(); keyboard_device = findAndOpenG15();
@@ -347,7 +355,9 @@ @@ -347,7 +355,9 @@ int initLibG15()
int exitLibG15() int exitLibG15()
{ {
pthread_mutex_destroy(&libusb_mutex); pthread_mutex_destroy(&libusb_mutex);
@@ -471,7 +475,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
} }
static void dumpPixmapIntoLCDFormat(unsigned char *lcd_buffer, unsigned char const *data) static void dumpPixmapIntoLCDFormat(unsigned char *lcd_buffer, unsigned char const *data)
@@ -428,36 +438,6 @@ @@ -428,36 +438,6 @@ static void dumpPixmapIntoLCDFormat(unsigned char *lcd_buffer, unsigned char con
} }
} }
@@ -508,7 +512,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
int writePixmapToLCD(unsigned char const *data) int writePixmapToLCD(unsigned char const *data)
{ {
int ret = 0; int ret = 0;
@@ -474,43 +454,27 @@ @@ -474,43 +454,27 @@ int writePixmapToLCD(unsigned char const *data)
/* the keyboard needs this magic byte */ /* the keyboard needs this magic byte */
lcd_buffer[0] = 0x03; lcd_buffer[0] = 0x03;
@@ -570,7 +574,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
return 0; return 0;
} }
@@ -535,7 +499,9 @@ @@ -535,7 +499,9 @@ int setLCDContrast(unsigned int level)
usb_data[3] = 18; usb_data[3] = 18;
} }
pthread_mutex_lock(&libusb_mutex); pthread_mutex_lock(&libusb_mutex);
@@ -581,7 +585,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
pthread_mutex_unlock(&libusb_mutex); pthread_mutex_unlock(&libusb_mutex);
return retval; return retval;
} }
@@ -553,7 +519,9 @@ @@ -553,7 +519,9 @@ int setLEDs(unsigned int leds)
return G15_ERROR_UNSUPPORTED; return G15_ERROR_UNSUPPORTED;
pthread_mutex_lock(&libusb_mutex); pthread_mutex_lock(&libusb_mutex);
@@ -592,7 +596,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
pthread_mutex_unlock(&libusb_mutex); pthread_mutex_unlock(&libusb_mutex);
return retval; return retval;
} }
@@ -578,7 +546,9 @@ @@ -578,7 +546,9 @@ int setLCDBrightness(unsigned int level)
usb_data[2] = 0x00; usb_data[2] = 0x00;
} }
pthread_mutex_lock(&libusb_mutex); pthread_mutex_lock(&libusb_mutex);
@@ -603,7 +607,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
pthread_mutex_unlock(&libusb_mutex); pthread_mutex_unlock(&libusb_mutex);
return retval; return retval;
} }
@@ -604,7 +574,9 @@ @@ -604,7 +574,9 @@ int setKBBrightness(unsigned int level)
usb_data[2] = 0x0; usb_data[2] = 0x0;
} }
pthread_mutex_lock(&libusb_mutex); pthread_mutex_lock(&libusb_mutex);
@@ -614,7 +618,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
pthread_mutex_unlock(&libusb_mutex); pthread_mutex_unlock(&libusb_mutex);
return retval; return retval;
} }
@@ -619,7 +591,9 @@ @@ -619,7 +591,9 @@ int setG510LEDColor(unsigned char r, unsigned char g, unsigned char b)
usb_data[3] = b; usb_data[3] = b;
pthread_mutex_lock(&libusb_mutex); pthread_mutex_lock(&libusb_mutex);
@@ -625,7 +629,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
pthread_mutex_unlock(&libusb_mutex); pthread_mutex_unlock(&libusb_mutex);
return retval; return retval;
} }
@@ -1033,18 +1007,30 @@ @@ -1033,18 +1007,30 @@ static void processKeyEvent4Byte(unsigned int *pressed_keys, unsigned char *buff
int getPressedKeys(unsigned int *pressed_keys, unsigned int timeout) int getPressedKeys(unsigned int *pressed_keys, unsigned int timeout)
{ {
unsigned char buffer[G15_KEY_READ_LENGTH]; unsigned char buffer[G15_KEY_READ_LENGTH];
@@ -663,7 +667,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
return G15_ERROR_TRY_AGAIN; return G15_ERROR_TRY_AGAIN;
} }
@@ -1054,7 +1040,7 @@ @@ -1054,7 +1040,7 @@ int getPressedKeys(unsigned int *pressed_keys, unsigned int timeout)
return G15_NO_ERROR; return G15_NO_ERROR;
} }
@@ -672,7 +676,7 @@ Subject: Migrate from legacy libusb-0.1 to libusb-1.0
case 4: case 4:
processKeyEvent4Byte(pressed_keys, buffer); processKeyEvent4Byte(pressed_keys, buffer);
return G15_NO_ERROR; return G15_NO_ERROR;
@@ -1065,6 +1051,6 @@ @@ -1065,6 +1051,6 @@ int getPressedKeys(unsigned int *pressed_keys, unsigned int timeout)
processKeyEvent9Byte(pressed_keys, buffer); processKeyEvent9Byte(pressed_keys, buffer);
return G15_NO_ERROR; return G15_NO_ERROR;
default: default: