28 #ifndef SHAREDSTRUCTURES_QT_H 29 #define SHAREDSTRUCTURES_QT_H 31 #include "commonGlobal.h" 33 #include <qsemaphore.h> 35 #include <qeventloop.h> 39 #include "sharedStructures.h" 46 #define ITOM_PYNOTACCESSIBLE 49 #if !defined(Q_MOC_RUN) || defined(ITOMCOMMONQT_MOC) //only moc this file in itomCommonQtLib but not in other libraries or executables linking against this itomCommonQtLib 51 typedef QMap<QString, ito::Param> ParamMap;
52 typedef ParamMap::iterator ParamMapIterator;
77 inline ItomSharedSemaphore(
int numberOfListeners = 1) : m_numOfListeners(numberOfListeners), m_instCounter(numberOfListeners + 1), m_enableDelete(false), m_callerStillWaiting(true), returnValue(
ito::retOk)
80 m_pSemaphore =
new QSemaphore(m_numOfListeners);
81 m_pSemaphore->acquire(m_numOfListeners);
82 internalMutex.unlock();
91 Q_ASSERT_X(m_enableDelete,
"~ItomSharedSemaphore",
"it is not allowed to directly destroy ItomSharedSemaphore. Always use ItomSharedSemaphore::deleteSemaphore(...)");
93 if(m_pSemaphore->available() < m_numOfListeners)
95 m_pSemaphore->release( m_numOfListeners - m_pSemaphore->available());
96 qDebug(
"ItomSharedSemaphore is not fully available at moment of destruction");
119 temp = m_pSemaphore->tryAcquire(m_numOfListeners, timeout);
121 QMutexLocker mutexLocker(&internalMutex);
124 qDebug() <<
"ItomSharedSemaphore run into a timeout. Number of attempted listeners: " << m_numOfListeners <<
", already freed: " << m_pSemaphore->available();
128 m_pSemaphore->release(m_numOfListeners);
131 m_callerStillWaiting =
false;
153 bool waitAndProcessEvents(
int timeout, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
159 inline void release() { m_pSemaphore->release(1); }
165 inline int available()
const {
return m_pSemaphore->available(); }
192 QMutexLocker mutexLocker(&internalMutex);
195 if(m_instCounter <= 0)
197 m_enableDelete =
true;
198 mutexLocker.unlock();
231 m_semaphore->deleteSemaphore();
253 m_semaphore = newSemaphoreInstance;
265 #endif //#if !defined(Q_MOC_RUN) || defined(ITOMCOMMONQT_MOC) ~ItomSharedSemaphore()
destructor (do not call directly, instead free the semaphore by ItomSharedSemaphore::deleteSemaphore ...
Definition: sharedStructuresQt.h:89
Locker-class for ItomSharedSemaphore. The functionality is equal to QMutexLocker in Qt...
Definition: sharedStructuresQt.h:217
QSemaphore * m_pSemaphore
Definition: sharedStructuresQt.h:60
void deleteSemaphore(void)
static method to decrease the reference counter of any ItomSharedSemaphore or delete it if the refere...
Definition: sharedStructuresQt.h:190
~ItomSharedSemaphoreLocker()
destructor.
Definition: sharedStructuresQt.h:227
Class for managing status values (like errors or warning)
Definition: retVal.h:54
ItomSharedSemaphoreLocker(ItomSharedSemaphore *semaphore)
constructor with ItomSharedSemaphore-pointer as parameter. This semaphore will be guarded by this loc...
Definition: sharedStructuresQt.h:221
ItomSharedSemaphore * getSemaphore() const
returns the pointer to the guarded ItomSharedSemaphore.
Definition: sharedStructuresQt.h:237
Definition: apiFunctionsGraph.cpp:39
int m_instCounter
Definition: sharedStructuresQt.h:61
bool m_enableDelete
Definition: sharedStructuresQt.h:62
bool isCallerStillWaiting()
indicates whether caller-method is still waiting that the lock is released by the listener(s)...
Definition: sharedStructuresQt.h:175
semaphore which can be used for asychronous thread communication. By using this class it is possible ...
Definition: sharedStructuresQt.h:57
QMutex internalMutex
Definition: sharedStructuresQt.h:65
ItomSharedSemaphoreLocker()
empty constructor. The locker will not guard any semaphore yet.
Definition: sharedStructuresQt.h:224
ItomSharedSemaphore(int numberOfListeners=1)
constructor
Definition: sharedStructuresQt.h:77
ItomSharedSemaphore * m_semaphore
Definition: sharedStructuresQt.h:260
int m_numOfListeners
Definition: sharedStructuresQt.h:63
int available() const
checks whether the semaphore is still locked or not
Definition: sharedStructuresQt.h:165
void release()
decreases the number of locks by one
Definition: sharedStructuresQt.h:159
ito::RetVal returnValue
Definition: sharedStructuresQt.h:206
bool m_callerStillWaiting
Definition: sharedStructuresQt.h:64
bool wait(int timeout)
The call of this method returns if a certain timeout has been expired or every listener released the ...
Definition: sharedStructuresQt.h:116