- Bugfix: LibusbJava.cpp, Ln 1288 removed the manipulation of the return value
- Bugfix: Guaranteeing '\0'-Termination of the retrieved C-Strings for all libusb_get_string_descriptor* calls - Change: The whole interface makes now use of exceptions to pass errors into the java environment instead encoding them into return values. - Change: Allowing Descriptor strings to have a length of 0 git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@292 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
129
java/src/ch/ntb/inf/libusbJava/exceptions/LibusbError.java
Normal file
129
java/src/ch/ntb/inf/libusbJava/exceptions/LibusbError.java
Normal file
@@ -0,0 +1,129 @@
|
||||
package ch.ntb.inf.libusbJava.exceptions;
|
||||
|
||||
public class LibusbError extends Exception {
|
||||
private static final long serialVersionUID = 9096323614080207236L;
|
||||
|
||||
/**
|
||||
* libusb error codes
|
||||
*/
|
||||
public static final int ERROR_NONE = 0;
|
||||
public static final int ERROR_IO = -1;
|
||||
public static final int ERROR_INVALID_PARAM = -2;
|
||||
public static final int ERROR_ACCESS = -3;
|
||||
public static final int ERROR_NO_DEVICE = -4;
|
||||
public static final int ERROR_NOT_FOUND = -5;
|
||||
public static final int ERROR_BUSY = -6;
|
||||
public static final int ERROR_TIMEOUT = -7;
|
||||
public static final int ERROR_OVERFLOW = -8;
|
||||
public static final int ERROR_PIPE = -9;
|
||||
public static final int ERROR_INTERRUPTED = -10;
|
||||
public static final int ERROR_NO_MEM = -11;
|
||||
public static final int ERROR_NOT_SUPPORTED = -12;
|
||||
public static final int ERROR_OTHER = -99;
|
||||
|
||||
private int code = ERROR_NONE;
|
||||
|
||||
public LibusbError(int code)
|
||||
{
|
||||
super("libusb result: " + getStringFromCode(code));
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getErrorCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public static String getStringFromCode(int code)
|
||||
{
|
||||
String result;
|
||||
|
||||
switch (code)
|
||||
{
|
||||
case ERROR_IO:
|
||||
{
|
||||
result = "ERROR_IO";
|
||||
break;
|
||||
}
|
||||
case ERROR_INVALID_PARAM:
|
||||
{
|
||||
result = "ERROR_INVALID_PARAM";
|
||||
break;
|
||||
}
|
||||
case ERROR_ACCESS:
|
||||
{
|
||||
result = "ERROR_ACCESS";
|
||||
break;
|
||||
}
|
||||
case ERROR_NO_DEVICE:
|
||||
{
|
||||
result = "ERROR_NO_DEVICE";
|
||||
break;
|
||||
}
|
||||
case ERROR_NOT_FOUND:
|
||||
{
|
||||
result = "ERROR_NOT_FOUND";
|
||||
break;
|
||||
}
|
||||
case ERROR_BUSY:
|
||||
{
|
||||
result = "ERROR_BUSY";
|
||||
break;
|
||||
}
|
||||
|
||||
case ERROR_TIMEOUT:
|
||||
{
|
||||
result = "ERROR_TIMEOUT";
|
||||
break;
|
||||
}
|
||||
|
||||
case ERROR_OVERFLOW:
|
||||
{
|
||||
result = "ERROR_OVERFLOW";
|
||||
break;
|
||||
}
|
||||
|
||||
case ERROR_PIPE:
|
||||
{
|
||||
result = "ERROR_PIPE";
|
||||
break;
|
||||
}
|
||||
|
||||
case ERROR_INTERRUPTED:
|
||||
{
|
||||
result = "ERROR_INTERRUPTED";
|
||||
break;
|
||||
}
|
||||
|
||||
case ERROR_NO_MEM:
|
||||
{
|
||||
result = "ERROR_NO_MEM";
|
||||
break;
|
||||
}
|
||||
|
||||
case ERROR_NOT_SUPPORTED:
|
||||
{
|
||||
result = "ERROR_NOT_SUPPORTED";
|
||||
break;
|
||||
}
|
||||
|
||||
case ERROR_OTHER:
|
||||
{
|
||||
result = "ERROR_OTHER";
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
result = "ERROR_UNKNWON (" + code + ")";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getErrorString() {
|
||||
return getStringFromCode(getErrorCode());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user