mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
refs #526, network
* signal when data have been published * parsing of publishing JSON object * utility functions
This commit is contained in:
@@ -54,7 +54,7 @@ namespace BlackMisc
|
||||
{
|
||||
QStringList ips;
|
||||
if (!CNetworkUtils::hasConnectedInterface(false)) return ips;
|
||||
foreach(const QHostAddress & address, QNetworkInterface::allAddresses())
|
||||
foreach (const QHostAddress &address, QNetworkInterface::allAddresses())
|
||||
{
|
||||
if (address.isLoopback() || address.isNull()) continue;
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost))
|
||||
@@ -207,13 +207,24 @@ namespace BlackMisc
|
||||
qurl.addQueryItem("XDEBUG_SESSION_START", "ECLIPSE_DBGP");
|
||||
}
|
||||
|
||||
QHttpPart CNetworkUtils::getJsonTextMutlipart(const QJsonObject &json)
|
||||
QHttpPart CNetworkUtils::getJsonTextMultipart(const QJsonObject &json)
|
||||
{
|
||||
const QByteArray bytes(QJsonDocument(json).toJson(QJsonDocument::Compact));
|
||||
return getJsonTextMultipart(bytes);
|
||||
}
|
||||
|
||||
QHttpPart CNetworkUtils::getJsonTextMultipart(const QJsonArray &json)
|
||||
{
|
||||
const QByteArray bytes(QJsonDocument(json).toJson(QJsonDocument::Compact));
|
||||
return getJsonTextMultipart(bytes);
|
||||
}
|
||||
|
||||
QHttpPart CNetworkUtils::getJsonTextMultipart(const QByteArray &bytes)
|
||||
{
|
||||
const QByteArray jsonData(QJsonDocument(json).toJson(QJsonDocument::Compact));
|
||||
QHttpPart textPart;
|
||||
QString name("form-data; name=\"swiftjson\"");
|
||||
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(name));
|
||||
textPart.setBody(jsonData);
|
||||
textPart.setBody(bytes);
|
||||
return textPart;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,13 @@ namespace BlackMisc
|
||||
static void addDebugFlag(QUrlQuery &qurl);
|
||||
|
||||
//! Multipart for JSON
|
||||
static QHttpPart getJsonTextMutlipart(const QJsonObject &json);
|
||||
static QHttpPart getJsonTextMultipart(const QJsonObject &json);
|
||||
|
||||
//! Multipart for JSON
|
||||
static QHttpPart getJsonTextMultipart(const QJsonArray &json);
|
||||
|
||||
//! Multipart for JSON
|
||||
static QHttpPart getJsonTextMultipart(const QByteArray &bytes);
|
||||
|
||||
//! Our tweakes network request
|
||||
static QNetworkRequest getNetworkRequest(const CUrl &url, RequestType type = Get);
|
||||
|
||||
@@ -261,11 +261,11 @@ namespace BlackMisc
|
||||
return this->m_webDataReaderProvider->updateWithVatsimDataFileData(aircraftToBeUdpated);
|
||||
}
|
||||
|
||||
CStatusMessageList CWebDataServicesAware::asyncWriteModel(const CAircraftModel &model) const
|
||||
CStatusMessageList CWebDataServicesAware::asyncPublishModels(const CAircraftModelList &models) const
|
||||
{
|
||||
Q_ASSERT_X(this->m_webDataReaderProvider, Q_FUNC_INFO, "Missing provider");
|
||||
if (!hasProvider()) { return CStatusMessageList(); }
|
||||
return this->m_webDataReaderProvider->asyncWriteModel(model);
|
||||
return this->m_webDataReaderProvider->asyncPublishModels(models);
|
||||
}
|
||||
|
||||
void CWebDataServicesAware::setProvider(IWebDataServicesProvider *webDataReaderProvider)
|
||||
@@ -296,6 +296,16 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
void CWebDataServicesAware::connectDataPublishSignal(QObject *receiver, std::function<void (const CAircraftModelList &, const CAircraftModelList &, const CStatusMessageList &)> dataPublished)
|
||||
{
|
||||
Q_ASSERT_X(this->m_webDataReaderProvider, Q_FUNC_INFO, "Missing provider");
|
||||
if (!hasProvider()) { return; }
|
||||
if (receiver)
|
||||
{
|
||||
this->m_swiftConnections.append(this->m_webDataReaderProvider->connectDataPublishSignal(receiver, dataPublished));
|
||||
}
|
||||
}
|
||||
|
||||
CEntityFlags::Entity CWebDataServicesAware::triggerRead(CEntityFlags::Entity whatToRead)
|
||||
{
|
||||
Q_ASSERT_X(this->m_webDataReaderProvider, Q_FUNC_INFO, "Missing provider");
|
||||
|
||||
@@ -184,10 +184,10 @@ namespace BlackMisc
|
||||
//! \threadsafe
|
||||
virtual int getMetarsCount() const = 0;
|
||||
|
||||
//! Write directly to database
|
||||
virtual BlackMisc::CStatusMessageList asyncWriteModel(const BlackMisc::Simulation::CAircraftModel &model) const = 0;
|
||||
//! Publish models to database
|
||||
virtual BlackMisc::CStatusMessageList asyncPublishModels(const BlackMisc::Simulation::CAircraftModelList &models) const = 0;
|
||||
|
||||
//! Relay signals for swift data
|
||||
//! Relay signals for read swift data
|
||||
//! Connect signals to slot receiver. As the interface is no QObject, slots can not be connected directly.
|
||||
//! In order to disconnect a list of connections is provided, which have to be disconnected manually.
|
||||
//! \note receiver is required for connection type
|
||||
@@ -195,16 +195,24 @@ namespace BlackMisc
|
||||
QObject *receiver,
|
||||
std::function<void(BlackMisc::Network::CEntityFlags::Entity, BlackMisc::Network::CEntityFlags::ReadState, int)> dataRead) = 0;
|
||||
|
||||
//! Relay signals for published swift data
|
||||
//! Connect signals to slot receiver. As the interface is no QObject, slots can not be connected directly.
|
||||
//! In order to disconnect a list of connections is provided, which have to be disconnected manually.
|
||||
//! \note receiver is required for connection type
|
||||
virtual QList<QMetaObject::Connection> connectDataPublishSignal(
|
||||
QObject *receiver,
|
||||
std::function<void(const BlackMisc::Simulation::CAircraftModelList &, const BlackMisc::Simulation::CAircraftModelList &, const BlackMisc::CStatusMessageList &)> dataPublished) = 0;
|
||||
|
||||
//! Trigger read of new data
|
||||
virtual BlackMisc::Network::CEntityFlags::Entity triggerRead(BlackMisc::Network::CEntityFlags::Entity whatToRead) = 0;
|
||||
|
||||
//! Can connect to swift DB?
|
||||
virtual bool canConnectSwiftDb() const = 0;
|
||||
|
||||
//! Write data to disk
|
||||
//! Write data to disk (mainly for testing scenarios)
|
||||
virtual bool writeDbDataToDisk(const QString &dir) const = 0;
|
||||
|
||||
//! Load DB data from disk
|
||||
//! Load DB data from disk (mainly for testing scenarios)
|
||||
virtual bool readDbDataFromDisk(const QString &dir, bool inBackground) = 0;
|
||||
};
|
||||
|
||||
@@ -322,8 +330,8 @@ namespace BlackMisc
|
||||
//! \copydoc IWebDataServicesProvider::updateWithVatsimDataFileData
|
||||
void updateWithVatsimDataFileData(BlackMisc::Simulation::CSimulatedAircraft &aircraftToBeUdpated) const;
|
||||
|
||||
//! \copydoc IWebDataServicesProvider::asyncWriteModel
|
||||
BlackMisc::CStatusMessageList asyncWriteModel(const BlackMisc::Simulation::CAircraftModel &model) const;
|
||||
//! \copydoc IWebDataServicesProvider::asyncPublishModels
|
||||
BlackMisc::CStatusMessageList asyncPublishModels(const BlackMisc::Simulation::CAircraftModelList &models) const;
|
||||
|
||||
//! Set the provider
|
||||
virtual void setProvider(IWebDataServicesProvider *webDataReaderProvider);
|
||||
@@ -339,6 +347,11 @@ namespace BlackMisc
|
||||
QObject *receiver,
|
||||
std::function<void(BlackMisc::Network::CEntityFlags::Entity, BlackMisc::Network::CEntityFlags::ReadState, int)> dataRead);
|
||||
|
||||
//! \copydoc IWebDataServicesProvider::connectDataPublishSignal
|
||||
virtual void connectDataPublishSignal(
|
||||
QObject *receiver,
|
||||
std::function<void(const BlackMisc::Simulation::CAircraftModelList &, const BlackMisc::Simulation::CAircraftModelList &, const BlackMisc::CStatusMessageList &)> dataPublished);
|
||||
|
||||
//! \copydoc IWebDataServicesProvider::triggerRead
|
||||
BlackMisc::Network::CEntityFlags::Entity triggerRead(BlackMisc::Network::CEntityFlags::Entity whatToRead);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user