refs #287 Thread safety, fix "memory access violation"

* some improved comments and information
* QMetaObject::invokeMethod in tool.cpp as thread safe invocation
* common base class for threaded readers
* removed event class, using QMetaObject::invoke instead for forcing calls in main event loop
* stop methods for readers, as used for graceful shutdown (preparing for thread safe destruction of objects)
* graceful shutdown for network context
* calls in tool now via inkoke for thread safety (only thread safe methods called directly)
This commit is contained in:
Klaus Basan
2014-07-01 19:11:25 +02:00
parent c03d45123d
commit d9a1c0cc8c
16 changed files with 522 additions and 229 deletions

View File

@@ -6,50 +6,42 @@
#ifndef BLACKCORE_VATSIMBOOKINGREADER_H
#define BLACKCORE_VATSIMBOOKINGREADER_H
//! \file
#include "blackmisc/threadedreader.h"
#include "blackmisc/avatcstationlist.h"
#include <QObject>
#include <QTimer>
#include <QNetworkReply>
#include <QReadWriteLock>
namespace BlackCore
{
/*!
* \brief Read bookings from VATSIM
* Read bookings from VATSIM
*/
class CVatsimBookingReader : public QObject
class CVatsimBookingReader : public QObject, public BlackMisc::CThreadedReader<void>
{
Q_OBJECT
public:
//! \brief Constructor
//! Constructor
explicit CVatsimBookingReader(const QString &url, QObject *parent = nullptr);
//! \brief Update timestamp
QDateTime getUpdateTimestamp() const { return this->m_updateTimestamp; }
//! \brief Read / re-read bookings
//! Read / re-read bookings
void read();
/*!
* \brief Set the update time
* \param updatePeriodMs 0 stops the timer
*/
void setInterval(int updatePeriodMs);
//! \brief Get the timer interval (ms)
int interval() const { return this->m_updateTimer->interval();}
private slots:
//! \brief Bookings have been read
//! Bookings have been read
void loadFinished(QNetworkReply *nwReply);
private:
QString m_serviceUrl; /*!< URL of the service */
QNetworkAccessManager *m_networkManager;
QDateTime m_updateTimestamp;
QTimer *m_updateTimer;
//! Parse received bookings
//! \threadsafe
void parseBookings(QNetworkReply *nwReply);
signals: