mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 13:36:48 +08:00
106 lines
3.9 KiB
C++
106 lines
3.9 KiB
C++
/* Copyright (C) 2015
|
|
* swift project Community / Contributors
|
|
*
|
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
|
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
|
* or distributed except according to the terms contained in the LICENSE file.
|
|
*/
|
|
|
|
//! \file
|
|
|
|
#ifndef BLACKCORE_DATABASE_WRITER_H
|
|
#define BLACKCORE_DATABASE_WRITER_H
|
|
|
|
#include "blackcore/blackcoreexport.h"
|
|
#include "blackmisc/simulation/aircraftmodellist.h"
|
|
#include "blackmisc/network/urlloglist.h"
|
|
#include "blackmisc/network/url.h"
|
|
#include "blackmisc/statusmessagelist.h"
|
|
|
|
#include <QByteArray>
|
|
#include <QList>
|
|
#include <QObject>
|
|
|
|
class QNetworkReply;
|
|
|
|
namespace BlackMisc { namespace Simulation { class CAutoPublishData; }}
|
|
namespace BlackCore
|
|
{
|
|
namespace Db
|
|
{
|
|
//! Write to the swift DB
|
|
class BLACKCORE_EXPORT CDatabaseWriter : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
//! Constructor
|
|
CDatabaseWriter(const BlackMisc::Network::CUrl &baseUrl, QObject *parent);
|
|
|
|
//! Write model to DB
|
|
BlackMisc::CStatusMessageList asyncPublishModel(const BlackMisc::Simulation::CAircraftModel &model);
|
|
|
|
//! Write models to DB
|
|
BlackMisc::CStatusMessageList asyncPublishModels(const BlackMisc::Simulation::CAircraftModelList &models);
|
|
|
|
//! Write auto publis data
|
|
BlackMisc::CStatusMessageList asyncAutoPublish(const BlackMisc::Simulation::CAutoPublishData &data);
|
|
|
|
//! Shutdown
|
|
void gracefulShutdown();
|
|
|
|
//! Shutting down?
|
|
bool isShuttingDown() const { return m_shutdown; }
|
|
|
|
//! Name of the worker
|
|
const QString &getName();
|
|
|
|
//! Write log
|
|
const BlackMisc::Network::CUrlLogList &getWriteLog() const { return m_writeLog; }
|
|
|
|
signals:
|
|
//! Published models, the response to \sa asyncPublishModels
|
|
void publishedModels(const BlackMisc::Simulation::CAircraftModelList &modelsPublished,
|
|
const BlackMisc::Simulation::CAircraftModelList &modelsSkipped,
|
|
const BlackMisc::CStatusMessageList &messages,
|
|
bool sendingSuccessful, bool directWrite);
|
|
|
|
//! Published models, simplified version of publishedModels
|
|
void publishedModelsSimplified(const BlackMisc::Simulation::CAircraftModelList &modelsPublished, bool directWrite);
|
|
|
|
private:
|
|
BlackMisc::Network::CUrlLogList m_writeLog;
|
|
BlackMisc::Network::CUrl m_modelPublishUrl; //!< model publishing
|
|
BlackMisc::Network::CUrl m_autoPublishUrl; //!< auto publish data
|
|
QNetworkReply *m_pendingModelPublishReply = nullptr;
|
|
QNetworkReply *m_pendingAutoPublishReply = nullptr;
|
|
qint64 m_modelReplyPendingSince = -1;
|
|
qint64 m_autoPublishReplyPendingSince = -1;
|
|
bool m_shutdown = false;
|
|
|
|
//! Post response for models
|
|
void postedModelsResponse(QNetworkReply *nwReplyPtr);
|
|
|
|
//! Post response for auto publish
|
|
void postedAutoPublishResponse(QNetworkReply *nwReplyPtr);
|
|
|
|
//! Kill the pending reply
|
|
bool killPendingModelReply();
|
|
|
|
//! Reply timed out?
|
|
bool isModelReplyOverdue() const;
|
|
|
|
//! URL model web service
|
|
static BlackMisc::Network::CUrl getModelPublishUrl(const BlackMisc::Network::CUrl &baseUrl);
|
|
|
|
//! URL auto publish web service
|
|
static BlackMisc::Network::CUrl getAutoPublishUrl(const BlackMisc::Network::CUrl &baseUrl);
|
|
|
|
//! Split data array
|
|
static QList<QByteArray> splitData(const QByteArray &data, int size);
|
|
};
|
|
} // ns
|
|
} // ns
|
|
|
|
#endif // guard
|