@@ -0,0 +1,1928 @@
+// vim: et sw=4 sts=4 tabstop=4%0Apackage com.issc.impl;%0A%0Aimport com.issc.Bluebit;%0Aimport com.issc.util.Log;%0A%0Aimport java.util.ArrayDeque;%0Aimport java.util.ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0A%0Aimport android.content.Context;%0A%0Aimport com.samsung.android.sdk.bt.gatt.BluetoothGattCallback;%0Aimport com.samsung.android.sdk.bt.gatt.BluetoothGattCharacteristic;%0Aimport com.samsung.android.sdk.bt.gatt.BluetoothGattDescriptor;%0A%0Apublic class GattQueue %7B%0A%0A    private Object mLock;%0A    private Consumer mConsumer;%0A%0A    private ArrayDeque%3CTransaction%3E mQueue;%0A    private Transaction mWorkingTransaction;%0A%0A    public GattQueue(Consumer consumer) %7B%0A        mLock = new Object();%0A        mQueue = new ArrayDeque%3CTransaction%3E();%0A        mConsumer = consumer;%0A    %7D%0A%0A    public void add(BluetoothGattCharacteristic chr, byte%5B%5D value) %7B%0A        Transaction t = new Transaction();%0A        t.chr = chr;%0A        t.value = value;%0A        addTransaction(t);%0A    %7D%0A%0A    private void addTransaction(Transaction trans) %7B%0A        synchronized(mQueue) %7B%0A            mQueue.add(trans);%0A        %7D%0A    %7D%0A%0A    public void consume() %7B%0A        synchronized(mQueue) %7B%0A            if (mWorkingTransaction == null) %7B%0A                mWorkingTransaction = mQueue.poll();%0A                if (mWorkingTransaction != null) %7B%0A                    // found transaction%0A                    BluetoothGattCharacteristic chr = mWorkingTransaction.chr;%0A                    byte%5B%5D value = mWorkingTransaction.value;%0A                    mConsumer.onTransact(chr, value);%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void consumedOne() %7B%0A        synchronized(mQueue) %7B%0A            mWorkingTransaction = null;%0A        %7D%0A    %7D%0A%0A    class Transaction %7B%0A        BluetoothGattCharacteristic chr;%0A        byte%5B%5D value;%0A    %7D%0A%0A    public interface Consumer %7B%0A        public void onTransact(BluetoothGattCharacteristic chr, byte%5B%5D value);%0A    %7D%0A%7D%0A

add standalone queue