Commit 084bbbd328e081eb05e62fd932c942270db9ec66
- Diff rendering mode:
- inline
- side by side
src/shared/trk/trkdevice.cpp
(21 / 13)
|   | |||
| 40 | 40 | #include <QtCore/QWaitCondition> | |
| 41 | 41 | #include <QtCore/QSharedPointer> | |
| 42 | 42 | #include <QtCore/QMetaType> | |
| 43 | #include <QtCore/QScopedPointer> | ||
| 43 | 44 | ||
| 44 | 45 | #ifdef Q_OS_WIN | |
| 45 | 46 | # include <windows.h> | |
| … | … | ||
| 146 | 146 | void queueTrkInitialPing(); | |
| 147 | 147 | ||
| 148 | 148 | // Call this from the device read notification with the results. | |
| 149 | void slotHandleResult(const TrkResult &result); | ||
| 149 | void slotHandleResult(const TrkResult &result, QMutex *mutex = 0); | ||
| 150 | 150 | ||
| 151 | 151 | // pendingMessage() can be called periodically in a timer to retrieve | |
| 152 | 152 | // the pending messages to be sent. | |
| … | … | ||
| 253 | 253 | } | |
| 254 | 254 | } | |
| 255 | 255 | ||
| 256 | void TrkWriteQueue::slotHandleResult(const TrkResult &result) | ||
| 256 | void TrkWriteQueue::slotHandleResult(const TrkResult &result, QMutex *mutex) | ||
| 257 | 257 | { | |
| 258 | m_trkWriteBusy = false; | ||
| 259 | //if (result.code != TrkNotifyAck && result.code != TrkNotifyNak) | ||
| 260 | // return; | ||
| 261 | 258 | // Find which request the message belongs to and invoke callback | |
| 262 | 259 | // if ACK or on NAK if desired. | |
| 260 | if (mutex) | ||
| 261 | mutex->lock(); | ||
| 262 | m_trkWriteBusy = false; | ||
| 263 | 263 | const TokenMessageMap::iterator it = m_writtenTrkMessages.find(result.token); | |
| 264 | if (it == m_writtenTrkMessages.end()) | ||
| 264 | if (it == m_writtenTrkMessages.end()) { | ||
| 265 | if (mutex) | ||
| 266 | mutex->unlock(); | ||
| 265 | 267 | return; | |
| 266 | const bool invokeCB = it.value().callback; | ||
| 267 | if (invokeCB) { | ||
| 268 | TrkResult result1 = result; | ||
| 269 | result1.cookie = it.value().cookie; | ||
| 270 | it.value().callback(result1); | ||
| 271 | 268 | } | |
| 269 | TrkCallback callback = it.value().callback; | ||
| 270 | const QVariant cookie = it.value().cookie; | ||
| 272 | 271 | m_writtenTrkMessages.erase(it); | |
| 272 | if (mutex) | ||
| 273 | mutex->unlock(); | ||
| 274 | // Invoke callback | ||
| 275 | if (callback) { | ||
| 276 | TrkResult result1 = result; | ||
| 277 | result1.cookie = cookie; | ||
| 278 | callback(result1); | ||
| 279 | } | ||
| 273 | 280 | } | |
| 274 | 281 | ||
| 275 | 282 | void TrkWriteQueue::queueTrkInitialPing() | |
| 276 | 283 | { | |
| 277 | 284 | // Ping, reset sequence count | |
| 278 | 285 | m_trkWriteToken = 0; | |
| 279 | m_trkWriteQueue.append(TrkMessage(0, 0)); | ||
| 286 | m_trkWriteQueue.append(TrkMessage(TrkPing, 0)); | ||
| 280 | 287 | } | |
| 281 | 288 | ||
| 282 | 289 | /////////////////////////////////////////////////////////////////////// | |
| … | … | ||
| 504 | 504 | // Call this from the device read notification with the results. | |
| 505 | 505 | void WriterThread::slotHandleResult(const TrkResult &result) | |
| 506 | 506 | { | |
| 507 | m_queue.slotHandleResult(result); | ||
| 507 | m_queue.slotHandleResult(result, &m_dataMutex); | ||
| 508 | 508 | tryWrite(); // Have messages been enqueued in-between? | |
| 509 | 509 | } | |
| 510 | 510 |

