Home | History | Annotate | Download | only in gatt
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.bluetooth.gatt;
     18 
     19 import java.util.ArrayList;
     20 import java.util.Iterator;
     21 import java.util.List;
     22 
     23 /**
     24  * Helper class to store characteristics and descriptors that will be
     25  * queued up for future exploration.
     26  * @hide
     27  */
     28 /*package*/ class SearchQueue {
     29     class Entry {
     30         public int connId;
     31         public int srvcType;
     32         public int srvcInstId;
     33         public long srvcUuidLsb;
     34         public long srvcUuidMsb;
     35         public int charInstId;
     36         public long charUuidLsb;
     37         public long charUuidMsb;
     38     }
     39 
     40     private List<Entry> mEntries = new ArrayList<Entry>();
     41 
     42     void add(int connId, int srvcType,
     43             int srvcInstId, long srvcUuidLsb, long srvcUuidMsb) {
     44         Entry entry = new Entry();
     45         entry.connId = connId;
     46         entry.srvcType = srvcType;
     47         entry.srvcInstId = srvcInstId;
     48         entry.srvcUuidLsb = srvcUuidLsb;
     49         entry.srvcUuidMsb = srvcUuidMsb;
     50         entry.charUuidLsb = 0;
     51         mEntries.add(entry);
     52     }
     53 
     54     void add(int connId, int srvcType,
     55         int srvcInstId, long srvcUuidLsb, long srvcUuidMsb,
     56         int charInstId, long charUuidLsb, long charUuidMsb)
     57     {
     58         Entry entry = new Entry();
     59         entry.connId = connId;
     60         entry.srvcType = srvcType;
     61         entry.srvcInstId = srvcInstId;
     62         entry.srvcUuidLsb = srvcUuidLsb;
     63         entry.srvcUuidMsb = srvcUuidMsb;
     64         entry.charInstId = charInstId;
     65         entry.charUuidLsb = charUuidLsb;
     66         entry.charUuidMsb = charUuidMsb;
     67         mEntries.add(entry);
     68     }
     69 
     70     Entry pop() {
     71         Entry entry = mEntries.get(0);
     72         mEntries.remove(0);
     73         return entry;
     74     }
     75 
     76     void removeConnId(int connId) {
     77         for (Iterator<Entry> it = mEntries.iterator(); it.hasNext();) {
     78             Entry entry = it.next();
     79             if (entry.connId == connId) {
     80                 it.remove();
     81             }
     82         }
     83     }
     84 
     85     boolean isEmpty() {
     86         return mEntries.isEmpty();
     87     }
     88 
     89     void clear() {
     90         mEntries.clear();
     91     }
     92 }
     93