| 1 | /* |
| 2 | * File: SynchronizedQueue.h |
| 3 | * |
| 4 | * Author: Jacob Dekel |
| 5 | * Created on: Aug 7, 2009 |
| 6 | * |
| 7 | * Copyright (c) 2009-2013 Jacob Dekel |
| 8 | * $Id$ |
| 9 | * |
| 10 | * This object implements a queue to which access is serialized |
| 11 | * |
| 12 | * This program is free software: you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation, either version 3 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #ifndef SYNCHRONIZEDQUEUE_H_ |
| 28 | #define SYNCHRONIZEDQUEUE_H_ |
| 29 | #include <QMutex> |
| 30 | #include <QByteArray> |
| 31 | #include <deque> |
| 32 | |
| 33 | typedef std::deque<QByteArray> HercQueue; |
| 34 | |
| 35 | class SynchronizedQueue |
| 36 | { |
| 37 | public: |
| 38 | SynchronizedQueue(); |
| 39 | virtual ~SynchronizedQueue(); |
| 40 | |
| 41 | bool empty ( ) const; |
| 42 | QByteArray& front ( ) ; |
| 43 | void pop_front ( ); |
| 44 | void push_back(const QByteArray& charBuff); |
| 45 | void push_back(QByteArray&& charBuff); |
| 46 | int size( ); |
| 47 | void clear( ); |
| 48 | |
| 49 | private: |
| 50 | HercQueue mQueue; |
| 51 | QMutex mMutex; |
| 52 | }; |
| 53 | |
| 54 | #endif /* SYNCHRONIZEDHERCULESQUEUE_H_ */ |