dataexchange.cpp
1 /********************************************************************************
2  * FARSA Utilities Library *
3  * Copyright (C) 2007-2012 *
4  * Gianluca Massera <emmegian@yahoo.it> *
5  * Stefano Nolfi <stefano.nolfi@istc.cnr.it> *
6  * Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
21  ********************************************************************************/
22 
23 #include "dataexchange.h"
24 
25 namespace farsa {
26 
28  {
29  getInstance().internalStopAllDataExchanges();
30  }
31 
32  GlobalUploaderDownloader::GlobalUploaderDownloader()
33  : m_queueHolders()
34  , m_mutex()
35  {
36  // Nothing to do here
37  }
38 
39  GlobalUploaderDownloader& GlobalUploaderDownloader::getInstance()
40  {
41  // The meyer singleton
42  static GlobalUploaderDownloader instance;
43 
44  return instance;
45  }
46 
47  void GlobalUploaderDownloader::internalStopAllDataExchanges()
48  {
49  QMutexLocker locker(&m_mutex);
50 
51  // For each queue holder we have to set its dataExchangeStopped member to true and then call
52  // wakeAll() on the wait condition
53  foreach (__DataExchange_internal::QueueHolderBase* q, m_queueHolders) {
54  q->dataExchangeStopped = true;
55  q->waitCondition.wakeAll();
56  }
57  }
58 
59  void GlobalUploaderDownloader::addQueueHolder(__DataExchange_internal::QueueHolderBase* queueHolder)
60  {
61  QMutexLocker locker(&m_mutex);
62 
63  // Adding the queue holder to the set
64  m_queueHolders.insert(queueHolder);
65  }
66 
67  void GlobalUploaderDownloader::removeQueueHolder(__DataExchange_internal::QueueHolderBase* queueHolder)
68  {
69  // Here we don't acquire the mutex because this function is only called when an uploader or a
70  // downloader is destroyed and the functions called when one of those things happends already take
71  // the lock (we could have made the mutex recursive, but it is not needed here)
72 
73  // Removing the queue holder from the set
74  m_queueHolders.remove(queueHolder);
75  }
76 
77 } // end namespace farsa
static void stopAllDataExchanges()
Stops all data exchanges.
A macro to deprecate functions.
A set of utility classes to exchange data across threads.