support for system specific error numbers
git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@253 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
@@ -10,9 +10,15 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
#include <errno.h>
|
||||
#include <usb.h>
|
||||
#include "LibusbJava.h"
|
||||
|
||||
// Windows specific stuff
|
||||
#ifdef WIN32
|
||||
#include <error.h>
|
||||
#endif
|
||||
|
||||
//#define DEBUGON
|
||||
|
||||
// global bus (updated when usb_get_busses() is called)
|
||||
@@ -805,4 +811,32 @@ JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1strerror
|
||||
return env->NewStringUTF(str);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: ch_ntb_usb_LibusbJava
|
||||
* Method: usb_error_no
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1error_1no
|
||||
(JNIEnv *env, jclass obj, jint java_error_no){
|
||||
|
||||
switch (java_error_no) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
return EBADF;
|
||||
case 2:
|
||||
return ENXIO;
|
||||
case 3:
|
||||
return EBUSY;
|
||||
case 4:
|
||||
return EINVAL;
|
||||
case 5:
|
||||
return ETIMEDOUT;
|
||||
case 6:
|
||||
return EIO;
|
||||
case 7:
|
||||
return ENOMEM;
|
||||
default:
|
||||
return 100000;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,6 +191,14 @@ JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1read
|
||||
JNIEXPORT jstring JNICALL Java_ch_ntb_usb_LibusbJava_usb_1strerror
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: ch_ntb_usb_LibusbJava
|
||||
* Method: usb_error_no
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1error_1no
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
23
LibusbJava/error.h
Normal file
23
LibusbJava/error.h
Normal file
@@ -0,0 +1,23 @@
|
||||
// copied from libusb-win32.sourceforge.net
|
||||
#ifndef __ERROR_H__
|
||||
#define __ERROR_H__
|
||||
|
||||
/* Connection timed out */
|
||||
#define ETIMEDOUT 116
|
||||
|
||||
typedef enum {
|
||||
USB_ERROR_TYPE_NONE = 0,
|
||||
USB_ERROR_TYPE_STRING,
|
||||
USB_ERROR_TYPE_ERRNO,
|
||||
} usb_error_type_t;
|
||||
|
||||
|
||||
void usb_error(char *format, ...);
|
||||
void usb_message(char *format, ...);
|
||||
const char *usb_win_error_to_string(void);
|
||||
int usb_win_error_to_errno(void);
|
||||
|
||||
|
||||
|
||||
#endif /* _ERROR_H_ */
|
||||
|
||||
Reference in New Issue
Block a user