UsbRequestQueue.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
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 }


android_core
Author(s): Damon Kohler
autogenerated on Thu Jun 6 2019 21:20:07