mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +08:00
@@ -37,11 +37,10 @@ namespace BlackSimTest
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
streamOut << "d .. direct, b .. background" << endl;
|
streamOut << "start reading" << endl;
|
||||||
QString input = streamIn.readLine();
|
QString input = streamIn.readLine();
|
||||||
|
Q_UNUSED(input);
|
||||||
|
|
||||||
if (!input.startsWith("b"))
|
|
||||||
{
|
|
||||||
streamOut << "reading directly" << endl;
|
streamOut << "reading directly" << endl;
|
||||||
QTime time;
|
QTime time;
|
||||||
time.start();
|
time.start();
|
||||||
@@ -68,25 +67,6 @@ namespace BlackSimTest
|
|||||||
streamOut << "read JSON array with size " << jsonArray.size() << endl;
|
streamOut << "read JSON array with size " << jsonArray.size() << endl;
|
||||||
streamOut << "read entries from disk: " << entriesList.size() << " in " << time.restart() << "ms" << endl;
|
streamOut << "read entries from disk: " << entriesList.size() << " in " << time.restart() << "ms" << endl;
|
||||||
tempFile.close();
|
tempFile.close();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
streamOut << "reading in background" << endl;
|
|
||||||
QFuture<int> f = mapper.readInBackground();
|
|
||||||
int i = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (i % 20 == 0)
|
|
||||||
{
|
|
||||||
streamOut << ".";
|
|
||||||
streamOut.flush();
|
|
||||||
}
|
|
||||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000 * 5);
|
|
||||||
}
|
|
||||||
while (!f.isFinished());
|
|
||||||
streamOut << endl << f.result() << " entries" << endl;
|
|
||||||
}
|
|
||||||
streamOut << "-----------------------------------------------" << endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -224,11 +224,11 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename ObjectType, typename ContainerType>
|
template <typename ObjectType, typename ContainerType>
|
||||||
BlackMisc::CWorker *CListModelBase<ObjectType, ContainerType>::updateAsync(const ContainerType &container, bool sort)
|
CWorker *CListModelBase<ObjectType, ContainerType>::updateAsync(const ContainerType &container, bool sort)
|
||||||
{
|
{
|
||||||
auto sortColumn = this->getSortColumn();
|
auto sortColumn = this->getSortColumn();
|
||||||
auto sortOrder = this->getSortOrder();
|
auto sortOrder = this->getSortOrder();
|
||||||
BlackMisc::CWorker *worker = BlackMisc::CWorker::fromTask(this, "ModelSort", [this, container, sort, sortColumn, sortOrder]()
|
CWorker *worker = BlackMisc::CWorker::fromTask(this, "ModelSort", [this, container, sort, sortColumn, sortOrder]()
|
||||||
{
|
{
|
||||||
ContainerType sortedContainer = this->sortContainerByColumn(container, sortColumn, sortOrder);
|
ContainerType sortedContainer = this->sortContainerByColumn(container, sortColumn, sortOrder);
|
||||||
QMetaObject::invokeMethod(this, "ps_updateContainer",
|
QMetaObject::invokeMethod(this, "ps_updateContainer",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "aircraftmapper.h"
|
#include "aircraftmapper.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
#include "blackmisc/worker.h"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
@@ -45,27 +46,13 @@ namespace BlackSim
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<int> &CAircraftMapper::readInBackground(const QString &simObjectDir)
|
void CAircraftMapper::initCompletelyInBackground(const QString &simObjectDir)
|
||||||
{
|
{
|
||||||
if (!isRunningInBackground())
|
if (this->m_initWorker) { return; }
|
||||||
|
this->m_initWorker = BlackMisc::CWorker::fromTask(this, "CAircraftMapper::initCompletely", [this, simObjectDir]()
|
||||||
{
|
{
|
||||||
this->m_backgroundRead = QtConcurrent::run(this, &CAircraftMapper::readSimObjects, simObjectDir);
|
this->initCompletely(simObjectDir);
|
||||||
}
|
});
|
||||||
return this->m_backgroundRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFuture<bool> &CAircraftMapper::initCompletelyInBackground(const QString &simObjectDir)
|
|
||||||
{
|
|
||||||
if (!isRunningInBackground())
|
|
||||||
{
|
|
||||||
this->m_backgroundInit = QtConcurrent::run(this, &CAircraftMapper::initCompletely, simObjectDir);
|
|
||||||
}
|
|
||||||
return this->m_backgroundInit;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CAircraftMapper::isRunningInBackground() const
|
|
||||||
{
|
|
||||||
return this->m_backgroundInit.isRunning() || this->m_backgroundRead.isRunning();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CAircraftMapper::isInitialized() const
|
bool CAircraftMapper::isInitialized() const
|
||||||
@@ -106,13 +93,9 @@ namespace BlackSim
|
|||||||
void CAircraftMapper::gracefulShutdown()
|
void CAircraftMapper::gracefulShutdown()
|
||||||
{
|
{
|
||||||
// when running, force re-init
|
// when running, force re-init
|
||||||
if (isRunningInBackground())
|
|
||||||
{
|
|
||||||
m_init = false;
|
|
||||||
this->m_entries.cancelRead();
|
this->m_entries.cancelRead();
|
||||||
this->m_backgroundInit.cancel();
|
this->m_initInProgress = false;
|
||||||
this->m_backgroundRead.cancel();
|
this->m_init = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const CAircraftModel &CAircraftMapper::getDefaultModel()
|
const CAircraftModel &CAircraftMapper::getDefaultModel()
|
||||||
@@ -129,10 +112,13 @@ namespace BlackSim
|
|||||||
bool CAircraftMapper::initCompletely(QString simObjectDir)
|
bool CAircraftMapper::initCompletely(QString simObjectDir)
|
||||||
{
|
{
|
||||||
if (this->m_init) { return true; }
|
if (this->m_init) { return true; }
|
||||||
|
if (this->m_initInProgress) { return false; }
|
||||||
|
this->m_initInProgress = true;
|
||||||
if (!this->m_mappings)
|
if (!this->m_mappings)
|
||||||
{
|
{
|
||||||
CLogMessage(this).error("Missing mapping defintions");
|
CLogMessage(this).error("Missing mapping defintions");
|
||||||
emit initCompleted(false);
|
emit initCompleted(false);
|
||||||
|
this->m_initInProgress = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,6 +126,7 @@ namespace BlackSim
|
|||||||
{
|
{
|
||||||
CLogMessage(this).error("Mapping engine, cannot read Flight Simulator directory: %1") << simObjectDir;
|
CLogMessage(this).error("Mapping engine, cannot read Flight Simulator directory: %1") << simObjectDir;
|
||||||
emit initCompleted(false);
|
emit initCompleted(false);
|
||||||
|
this->m_initInProgress = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +140,7 @@ namespace BlackSim
|
|||||||
{
|
{
|
||||||
CLogMessage(this).error("Reading mapping rules failed or empty");
|
CLogMessage(this).error("Reading mapping rules failed or empty");
|
||||||
emit initCompleted(false);
|
emit initCompleted(false);
|
||||||
|
this->m_initInProgress = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,6 +155,7 @@ namespace BlackSim
|
|||||||
{
|
{
|
||||||
CLogMessage(this).error("No SimObjects found in %1") << simObjectDir;
|
CLogMessage(this).error("No SimObjects found in %1") << simObjectDir;
|
||||||
emit initCompleted(false);
|
emit initCompleted(false);
|
||||||
|
this->m_initInProgress = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,6 +169,7 @@ namespace BlackSim
|
|||||||
// finish
|
// finish
|
||||||
CLogMessage(this).info("Mapping system: %1 definitions for %2 entries") << this->m_mappings->size() << this->m_entries.size();
|
CLogMessage(this).info("Mapping system: %1 definitions for %2 entries") << this->m_mappings->size() << this->m_entries.size();
|
||||||
emit initCompleted(true);
|
emit initCompleted(true);
|
||||||
|
this->m_initInProgress = false;
|
||||||
this->m_init = true;
|
this->m_init = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "aircraftcfgentrieslist.h"
|
#include "aircraftcfgentrieslist.h"
|
||||||
#include "../simulatormodelmappings.h"
|
#include "../simulatormodelmappings.h"
|
||||||
|
#include "blackmisc/worker.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
@@ -61,14 +62,8 @@ namespace BlackSim
|
|||||||
//! Read for directory or re-read
|
//! Read for directory or re-read
|
||||||
int readSimObjects(const QString &simObjectDir = "");
|
int readSimObjects(const QString &simObjectDir = "");
|
||||||
|
|
||||||
//! Read in background
|
|
||||||
QFuture<int> &readInBackground(const QString &simObjectDir = "");
|
|
||||||
|
|
||||||
//! Init in background
|
//! Init in background
|
||||||
QFuture<bool> &initCompletelyInBackground(const QString &simObjectDir = "");
|
void initCompletelyInBackground(const QString &simObjectDir = "");
|
||||||
|
|
||||||
//! Running in background
|
|
||||||
bool isRunningInBackground() const;
|
|
||||||
|
|
||||||
//! Init completed?
|
//! Init completed?
|
||||||
bool isInitialized() const;
|
bool isInitialized() const;
|
||||||
@@ -110,10 +105,9 @@ namespace BlackSim
|
|||||||
private:
|
private:
|
||||||
QScopedPointer<BlackSim::ISimulatorModelMappings> m_mappings; //!< all mapping definitions
|
QScopedPointer<BlackSim::ISimulatorModelMappings> m_mappings; //!< all mapping definitions
|
||||||
CAircraftCfgEntriesList m_entries; //!< all entries
|
CAircraftCfgEntriesList m_entries; //!< all entries
|
||||||
QFuture<bool> m_backgroundInit;
|
|
||||||
QFuture<int> m_backgroundRead;
|
|
||||||
bool m_init = false;
|
bool m_init = false;
|
||||||
|
bool m_initInProgress = false;
|
||||||
|
BlackMisc::CWorker *m_initWorker = nullptr;
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user