kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Written by Thomas Tsou <ttsou@vt.edu> |
| 3 | * Based on code by Harvind S Samra <hssamra@kestrelsp.com> |
| 4 | * |
| 5 | * Copyright 2011 Free Software Foundation, Inc. |
| 6 | * |
| 7 | * This program is free software: you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation, either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * See the COPYING file in the main directory for details. |
| 20 | */ |
| 21 | |
| 22 | #include "radioVector.h" |
| 23 | |
| 24 | radioVector::radioVector(const signalVector& wVector, GSM::Time& wTime) |
| 25 | : signalVector(wVector), mTime(wTime) |
| 26 | { |
| 27 | } |
| 28 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 29 | GSM::Time radioVector::getTime() const |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 30 | { |
| 31 | return mTime; |
| 32 | } |
| 33 | |
| 34 | void radioVector::setTime(const GSM::Time& wTime) |
| 35 | { |
| 36 | mTime = wTime; |
| 37 | } |
| 38 | |
| 39 | bool radioVector::operator>(const radioVector& other) const |
| 40 | { |
| 41 | return mTime > other.mTime; |
| 42 | } |
| 43 | |
| 44 | unsigned VectorFIFO::size() |
| 45 | { |
| 46 | return mQ.size(); |
| 47 | } |
| 48 | |
| 49 | void VectorFIFO::put(radioVector *ptr) |
| 50 | { |
| 51 | mQ.put((void*) ptr); |
| 52 | } |
| 53 | |
| 54 | radioVector *VectorFIFO::get() |
| 55 | { |
| 56 | return (radioVector*) mQ.get(); |
| 57 | } |
| 58 | |
| 59 | GSM::Time VectorQueue::nextTime() const |
| 60 | { |
| 61 | GSM::Time retVal; |
| 62 | mLock.lock(); |
| 63 | |
| 64 | while (mQ.size()==0) |
| 65 | mWriteSignal.wait(mLock); |
| 66 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 67 | retVal = mQ.top()->getTime(); |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 68 | mLock.unlock(); |
| 69 | |
| 70 | return retVal; |
| 71 | } |
| 72 | |
| 73 | radioVector* VectorQueue::getStaleBurst(const GSM::Time& targTime) |
| 74 | { |
| 75 | mLock.lock(); |
| 76 | if ((mQ.size()==0)) { |
| 77 | mLock.unlock(); |
| 78 | return NULL; |
| 79 | } |
| 80 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 81 | if (mQ.top()->getTime() < targTime) { |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 82 | radioVector* retVal = mQ.top(); |
| 83 | mQ.pop(); |
| 84 | mLock.unlock(); |
| 85 | return retVal; |
| 86 | } |
| 87 | mLock.unlock(); |
| 88 | |
| 89 | return NULL; |
| 90 | } |
| 91 | |
| 92 | radioVector* VectorQueue::getCurrentBurst(const GSM::Time& targTime) |
| 93 | { |
| 94 | mLock.lock(); |
| 95 | if ((mQ.size()==0)) { |
| 96 | mLock.unlock(); |
| 97 | return NULL; |
| 98 | } |
| 99 | |
kurtis.heimerl | 0628613 | 2011-11-26 03:18:43 +0000 | [diff] [blame] | 100 | if (mQ.top()->getTime() == targTime) { |
kurtis.heimerl | 8aea56e | 2011-11-26 03:18:30 +0000 | [diff] [blame] | 101 | radioVector* retVal = mQ.top(); |
| 102 | mQ.pop(); |
| 103 | mLock.unlock(); |
| 104 | return retVal; |
| 105 | } |
| 106 | mLock.unlock(); |
| 107 | |
| 108 | return NULL; |
| 109 | } |