Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.android.android_acm_serial;
00018
00019 import android.hardware.usb.UsbDeviceConnection;
00020 import android.hardware.usb.UsbEndpoint;
00021 import android.hardware.usb.UsbRequest;
00022 import android.util.Log;
00023 import org.ros.exception.RosRuntimeException;
00024
00025 import java.util.Queue;
00026 import java.util.concurrent.ConcurrentLinkedQueue;
00027
00031 class UsbRequestQueue {
00032
00033 private static final boolean DEBUG = false;
00034 private static final String TAG = "UsbRequestQueue";
00035
00036 private final UsbDeviceConnection connection;
00037 private final UsbEndpoint endpoint;
00038 private final UsbRequestCallback callback;
00039 private final Queue<UsbRequest> queue;
00040
00041 public UsbRequestQueue(UsbDeviceConnection connection, UsbEndpoint endpoint,
00042 UsbRequestCallback callback) {
00043 this.connection = connection;
00044 this.endpoint = endpoint;
00045 this.callback = callback;
00046 queue = new ConcurrentLinkedQueue<UsbRequest>();
00047 }
00048
00049 public void add(UsbRequest request) {
00050 if (callback != null) {
00051 callback.onRequestComplete(request);
00052 }
00053 queue.add(request);
00054 if (DEBUG) {
00055 Log.d(TAG, "USB request added.");
00056 }
00057 }
00058
00059 public UsbRequest poll() {
00060 UsbRequest request = queue.poll();
00061 if (request == null) {
00062 request = new UsbRequest();
00063 if (!request.initialize(connection, endpoint)) {
00064 throw new RosRuntimeException("Failed to open UsbRequest.");
00065 }
00066 }
00067 return request;
00068 }
00069 }