am 8046b5e0: Merge "UsbRequest: set ByteBuffer.position() upon success." into jb-mr1-dev
* commit '8046b5e00dc24fc5f5de86435e2e0d4b04520ac7': UsbRequest: set ByteBuffer.position() upon success.
This commit is contained in:
@@ -152,10 +152,14 @@ public class UsbRequest {
|
|||||||
|
|
||||||
/* package */ void dequeue() {
|
/* package */ void dequeue() {
|
||||||
boolean out = (mEndpoint.getDirection() == UsbConstants.USB_DIR_OUT);
|
boolean out = (mEndpoint.getDirection() == UsbConstants.USB_DIR_OUT);
|
||||||
|
int bytesRead;
|
||||||
if (mBuffer.isDirect()) {
|
if (mBuffer.isDirect()) {
|
||||||
native_dequeue_direct();
|
bytesRead = native_dequeue_direct();
|
||||||
} else {
|
} else {
|
||||||
native_dequeue_array(mBuffer.array(), mLength, out);
|
bytesRead = native_dequeue_array(mBuffer.array(), mLength, out);
|
||||||
|
}
|
||||||
|
if (bytesRead >= 0) {
|
||||||
|
mBuffer.position(Math.min(bytesRead, mLength));
|
||||||
}
|
}
|
||||||
mBuffer = null;
|
mBuffer = null;
|
||||||
mLength = 0;
|
mLength = 0;
|
||||||
@@ -174,8 +178,8 @@ public class UsbRequest {
|
|||||||
int ep_attributes, int ep_max_packet_size, int ep_interval);
|
int ep_attributes, int ep_max_packet_size, int ep_interval);
|
||||||
private native void native_close();
|
private native void native_close();
|
||||||
private native boolean native_queue_array(byte[] buffer, int length, boolean out);
|
private native boolean native_queue_array(byte[] buffer, int length, boolean out);
|
||||||
private native void native_dequeue_array(byte[] buffer, int length, boolean out);
|
private native int native_dequeue_array(byte[] buffer, int length, boolean out);
|
||||||
private native boolean native_queue_direct(ByteBuffer buffer, int length, boolean out);
|
private native boolean native_queue_direct(ByteBuffer buffer, int length, boolean out);
|
||||||
private native void native_dequeue_direct();
|
private native int native_dequeue_direct();
|
||||||
private native boolean native_cancel();
|
private native boolean native_cancel();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ android_hardware_UsbRequest_queue_array(JNIEnv *env, jobject thiz,
|
|||||||
request->buffer = malloc(length);
|
request->buffer = malloc(length);
|
||||||
if (!request->buffer)
|
if (!request->buffer)
|
||||||
return false;
|
return false;
|
||||||
|
memset(request->buffer, 0, length);
|
||||||
if (out) {
|
if (out) {
|
||||||
// copy data from Java buffer to native buffer
|
// copy data from Java buffer to native buffer
|
||||||
env->GetByteArrayRegion(buffer, 0, length, (jbyte *)request->buffer);
|
env->GetByteArrayRegion(buffer, 0, length, (jbyte *)request->buffer);
|
||||||
@@ -113,14 +114,14 @@ android_hardware_UsbRequest_queue_array(JNIEnv *env, jobject thiz,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
android_hardware_UsbRequest_dequeue_array(JNIEnv *env, jobject thiz,
|
android_hardware_UsbRequest_dequeue_array(JNIEnv *env, jobject thiz,
|
||||||
jbyteArray buffer, jint length, jboolean out)
|
jbyteArray buffer, jint length, jboolean out)
|
||||||
{
|
{
|
||||||
struct usb_request* request = get_request_from_object(env, thiz);
|
struct usb_request* request = get_request_from_object(env, thiz);
|
||||||
if (!request) {
|
if (!request) {
|
||||||
ALOGE("request is closed in native_dequeue");
|
ALOGE("request is closed in native_dequeue");
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer && length && request->buffer && !out) {
|
if (buffer && length && request->buffer && !out) {
|
||||||
@@ -129,7 +130,7 @@ android_hardware_UsbRequest_dequeue_array(JNIEnv *env, jobject thiz,
|
|||||||
}
|
}
|
||||||
free(request->buffer);
|
free(request->buffer);
|
||||||
env->DeleteGlobalRef((jobject)request->client_data);
|
env->DeleteGlobalRef((jobject)request->client_data);
|
||||||
|
return request->actual_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static jboolean
|
static jboolean
|
||||||
@@ -163,16 +164,17 @@ android_hardware_UsbRequest_queue_direct(JNIEnv *env, jobject thiz,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
android_hardware_UsbRequest_dequeue_direct(JNIEnv *env, jobject thiz)
|
android_hardware_UsbRequest_dequeue_direct(JNIEnv *env, jobject thiz)
|
||||||
{
|
{
|
||||||
struct usb_request* request = get_request_from_object(env, thiz);
|
struct usb_request* request = get_request_from_object(env, thiz);
|
||||||
if (!request) {
|
if (!request) {
|
||||||
ALOGE("request is closed in native_dequeue");
|
ALOGE("request is closed in native_dequeue");
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
// all we need to do is delete our global ref
|
// all we need to do is delete our global ref
|
||||||
env->DeleteGlobalRef((jobject)request->client_data);
|
env->DeleteGlobalRef((jobject)request->client_data);
|
||||||
|
return request->actual_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static jboolean
|
static jboolean
|
||||||
@@ -191,10 +193,10 @@ static JNINativeMethod method_table[] = {
|
|||||||
(void *)android_hardware_UsbRequest_init},
|
(void *)android_hardware_UsbRequest_init},
|
||||||
{"native_close", "()V", (void *)android_hardware_UsbRequest_close},
|
{"native_close", "()V", (void *)android_hardware_UsbRequest_close},
|
||||||
{"native_queue_array", "([BIZ)Z", (void *)android_hardware_UsbRequest_queue_array},
|
{"native_queue_array", "([BIZ)Z", (void *)android_hardware_UsbRequest_queue_array},
|
||||||
{"native_dequeue_array", "([BIZ)V", (void *)android_hardware_UsbRequest_dequeue_array},
|
{"native_dequeue_array", "([BIZ)I", (void *)android_hardware_UsbRequest_dequeue_array},
|
||||||
{"native_queue_direct", "(Ljava/nio/ByteBuffer;IZ)Z",
|
{"native_queue_direct", "(Ljava/nio/ByteBuffer;IZ)Z",
|
||||||
(void *)android_hardware_UsbRequest_queue_direct},
|
(void *)android_hardware_UsbRequest_queue_direct},
|
||||||
{"native_dequeue_direct", "()V", (void *)android_hardware_UsbRequest_dequeue_direct},
|
{"native_dequeue_direct", "()I", (void *)android_hardware_UsbRequest_dequeue_direct},
|
||||||
{"native_cancel", "()Z", (void *)android_hardware_UsbRequest_cancel},
|
{"native_cancel", "()Z", (void *)android_hardware_UsbRequest_cancel},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user