00001 /*************************************************************************** 00002 ** 00003 ** This file is part of DinverCore. 00004 ** 00005 ** This file may be distributed and/or modified under the terms of the 00006 ** GNU General Public License version 2 or 3 as published by the Free 00007 ** Software Foundation and appearing in the file LICENSE.GPL included 00008 ** in the packaging of this file. 00009 ** 00010 ** This file is distributed in the hope that it will be useful, but WITHOUT 00011 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00013 ** more details. 00014 ** 00015 ** You should have received a copy of the GNU General Public License 00016 ** along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 ** 00018 ** See http://www.geopsy.org for more information. 00019 ** 00020 ** Created : 2009-05-21 00021 ** Authors: 00022 ** Marc Wathelet 00023 ** Marc Wathelet (LGIT, Grenoble, France) 00024 ** 00025 ***************************************************************************/ 00026 00027 #ifndef FORWARDSIGNAL_H 00028 #define FORWARDSIGNAL_H 00029 00030 #include <QtCore> 00031 00032 namespace DinverCore { 00033 00034 class AbstractForward; 00035 00036 class ForwardSignal 00037 { 00038 public: 00039 ForwardSignal() {_forward=0;} 00040 ~ForwardSignal() {} 00041 00042 void lock() {_mutex.lock();} 00043 void unlock() {_mutex.unlock();} 00044 inline AbstractForward * wait(); 00045 inline void finished(AbstractForward * f); 00046 private: 00047 QWaitCondition _condition; 00048 QMutex _mutex; 00049 AbstractForward * _forward; 00050 }; 00051 00052 AbstractForward * ForwardSignal::wait() 00053 { 00054 _condition.wait(&_mutex); 00055 AbstractForward * f=_forward; 00056 _forward=0; 00057 _mutex.unlock(); 00058 return f; 00059 } 00060 00061 inline void ForwardSignal::finished(AbstractForward * f) 00062 { 00063 _mutex.lock(); 00064 _forward=f; 00065 _condition.wakeOne(); 00066 _mutex.unlock(); 00067 } 00068 00069 00070 } // namespace DinverCore 00071 00072 #endif // FORWARDSIGNAL_H