SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
syncmessenger.cpp
Go to the documentation of this file.
1 // Copyright (C) 2015 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include "util/syncmessenger.h"
20 #include "util/message.h"
21 
23  m_complete(0),
24  m_message(0),
25  m_result(0)
26 {
27  qRegisterMetaType<Message>("Message");
28 }
29 
31 {}
32 
33 int SyncMessenger::sendWait(Message& message, unsigned long msPollTime)
34 {
35  m_message = &message;
36  m_mutex.lock();
37  m_complete.store(0);
38 
39  emit messageSent();
40 
41  while (!m_complete.load())
42  {
43  m_waitCondition.wait(&m_mutex, msPollTime);
44  }
45 
46  int result = m_result;
47  m_mutex.unlock();
48 
49  return result;
50 }
51 
52 void SyncMessenger::done(int result)
53 {
54  m_result = result;
55  m_complete.store(1);
56  m_waitCondition.wakeAll();
57 }
58 
59 
60 
Message * m_message
Definition: syncmessenger.h:52
QAtomicInt m_complete
Definition: syncmessenger.h:51
QWaitCondition m_waitCondition
Definition: syncmessenger.h:49
void messageSent()
void done(int result=0)
Processing of the message is complete.
int sendWait(Message &message, unsigned long msPollTime=100)
Send message and waits for its process completion.