mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 11:25:33 +08:00
Issue #77 Break dependency of worker on identifiable
This commit is contained in:
@@ -57,6 +57,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
CAfvClient::CAfvClient(const QString &apiServer, QObject *owner) :
|
CAfvClient::CAfvClient(const QString &apiServer, QObject *owner) :
|
||||||
CContinuousWorker(owner, "CAfvClient"),
|
CContinuousWorker(owner, "CAfvClient"),
|
||||||
|
CIdentifiable("CAfvClient"),
|
||||||
m_connection(new CClientConnection(apiServer, this)),
|
m_connection(new CClientConnection(apiServer, this)),
|
||||||
m_input(new CInput(SampleRate, this)),
|
m_input(new CInput(SampleRate, this)),
|
||||||
m_output(new COutput(this)),
|
m_output(new COutput(this)),
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace BlackCore
|
|||||||
namespace Clients
|
namespace Clients
|
||||||
{
|
{
|
||||||
//! AFV client
|
//! AFV client
|
||||||
class BLACKCORE_EXPORT CAfvClient final : public BlackMisc::CContinuousWorker
|
class BLACKCORE_EXPORT CAfvClient final : public BlackMisc::CContinuousWorker, public BlackMisc::CIdentifiable
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|||||||
@@ -130,19 +130,12 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << application; }
|
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << application; }
|
||||||
|
|
||||||
CIdentifier identifier(application);
|
if (!m_registeredApplications.contains(application))
|
||||||
identifier.setCurrentUtcTime();
|
|
||||||
|
|
||||||
if (!m_registeredApplications.contains(identifier))
|
|
||||||
{
|
{
|
||||||
m_registeredApplications.push_back(identifier);
|
m_registeredApplications.push_back(application);
|
||||||
emit this->registrationChanged();
|
emit this->registrationChanged();
|
||||||
emit this->hotkeyActionsRegistered(sApp->getInputManager()->allAvailableActions(), {});
|
emit this->hotkeyActionsRegistered(sApp->getInputManager()->allAvailableActions(), {});
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
m_registeredApplications.replace(application, identifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->cleanupRegisteredApplications();
|
this->cleanupRegisteredApplications();
|
||||||
return application;
|
return application;
|
||||||
@@ -158,15 +151,16 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CContextApplication::cleanupRegisteredApplications()
|
void CContextApplication::cleanupRegisteredApplications()
|
||||||
{
|
{
|
||||||
static const int outdatedMs = qRound(1.5 * PingIdentifiersMs);
|
//static const int outdatedMs = qRound(1.5 * PingIdentifiersMs);
|
||||||
m_registeredApplications.removeOlderThanNowMinusOffset(outdatedMs);
|
//m_registeredApplications.removeOlderThanNowMinusOffset(outdatedMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
CIdentifierList CContextApplication::getRegisteredApplications() const
|
CIdentifierList CContextApplication::getRegisteredApplications() const
|
||||||
{
|
{
|
||||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||||
static const int outdatedMs = qRound(1.5 * PingIdentifiersMs);
|
//static const int outdatedMs = qRound(1.5 * PingIdentifiersMs);
|
||||||
return m_registeredApplications.findAfterNowMinusOffset(outdatedMs);
|
//return m_registeredApplications.findAfterNowMinusOffset(outdatedMs);
|
||||||
|
return m_registeredApplications;
|
||||||
}
|
}
|
||||||
|
|
||||||
CIdentifier CContextApplication::getApplicationIdentifier() const
|
CIdentifier CContextApplication::getApplicationIdentifier() const
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ namespace BlackGui
|
|||||||
this->m_columns.addColumn(CColumn::standardString("machine", CIdentifier::IndexMachineName));
|
this->m_columns.addColumn(CColumn::standardString("machine", CIdentifier::IndexMachineName));
|
||||||
this->m_columns.addColumn(CColumn::standardString("process", CIdentifier::IndexProcessName));
|
this->m_columns.addColumn(CColumn::standardString("process", CIdentifier::IndexProcessName));
|
||||||
this->m_columns.addColumn(CColumn::standardString("p.id", "process id", CIdentifier::IndexProcessId));
|
this->m_columns.addColumn(CColumn::standardString("p.id", "process id", CIdentifier::IndexProcessId));
|
||||||
this->m_columns.addColumn(CColumn("time", "received", CIdentifier::IndexUtcTimestamp, new CDateTimeFormatter(CDateTimeFormatter::formatHms())));
|
|
||||||
this->m_columns.addColumn(CColumn("lcl m.", "local machine", CIdentifier::IndexIsFromLocalMachine, new CBoolIconFormatter("local", "remote")));
|
this->m_columns.addColumn(CColumn("lcl m.", "local machine", CIdentifier::IndexIsFromLocalMachine, new CBoolIconFormatter("local", "remote")));
|
||||||
this->m_columns.addColumn(CColumn("same p.", "same process", CIdentifier::IndexIsFromSameProcess, new CBoolIconFormatter("same process", "other process")));
|
this->m_columns.addColumn(CColumn("same p.", "same process", CIdentifier::IndexIsFromSameProcess, new CBoolIconFormatter("same process", "other process")));
|
||||||
this->m_columns.addColumn(CColumn::standardString("m.id", "machine id", CIdentifier::IndexMachineIdBase64));
|
this->m_columns.addColumn(CColumn::standardString("m.id", "machine id", CIdentifier::IndexMachineIdBase64));
|
||||||
|
|||||||
@@ -10,13 +10,6 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
CIdentifier CIdentifiable::getCurrentTimestampIdentifier() const
|
|
||||||
{
|
|
||||||
CIdentifier o(m_identifier);
|
|
||||||
o.setCurrentUtcTime();
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
CIdentifiable::CIdentifiable(QObject *object) : m_identifier(object->objectName())
|
CIdentifiable::CIdentifiable(QObject *object) : m_identifier(object->objectName())
|
||||||
{
|
{
|
||||||
// if the object name changes we update our originator
|
// if the object name changes we update our originator
|
||||||
|
|||||||
@@ -34,9 +34,6 @@ namespace BlackMisc
|
|||||||
//! Set identifier, allows to set an external identifier
|
//! Set identifier, allows to set an external identifier
|
||||||
void setIdentifier(const CIdentifier &identifier) { m_identifier = identifier; }
|
void setIdentifier(const CIdentifier &identifier) { m_identifier = identifier; }
|
||||||
|
|
||||||
//! Identifier with current timestamp
|
|
||||||
CIdentifier getCurrentTimestampIdentifier() const;
|
|
||||||
|
|
||||||
//! My identifier?
|
//! My identifier?
|
||||||
bool isMyIdentifier(const CIdentifier &otherIdentifier) const { return m_identifier == otherIdentifier; }
|
bool isMyIdentifier(const CIdentifier &otherIdentifier) const { return m_identifier == otherIdentifier; }
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "blackmisc/identifier.h"
|
#include "blackmisc/identifier.h"
|
||||||
#include "blackmisc/comparefunctions.h"
|
#include "blackmisc/comparefunctions.h"
|
||||||
#include "blackmisc/stringutils.h"
|
#include "blackmisc/stringutils.h"
|
||||||
|
#include "blackmisc/propertyindex.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QHostInfo>
|
#include <QHostInfo>
|
||||||
@@ -108,8 +109,7 @@ QByteArray cachedMachineUniqueId()
|
|||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
CIdentifier::CIdentifier(const QString &name)
|
CIdentifier::CIdentifier(const QString &name)
|
||||||
: ITimestampBased(QDateTime::currentMSecsSinceEpoch()),
|
: m_name(name.trimmed()),
|
||||||
m_name(name.trimmed()),
|
|
||||||
m_machineIdBase64(cachedMachineUniqueId().toBase64(QByteArray::OmitTrailingEquals)),
|
m_machineIdBase64(cachedMachineUniqueId().toBase64(QByteArray::OmitTrailingEquals)),
|
||||||
m_machineName(cachedLocalHostName()),
|
m_machineName(cachedLocalHostName()),
|
||||||
m_processName(cachedEscapedApplicationName()),
|
m_processName(cachedEscapedApplicationName()),
|
||||||
@@ -128,7 +128,6 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CIdentifier::CIdentifier(const QString &name, const QString &machineId, const QString &machineName,
|
CIdentifier::CIdentifier(const QString &name, const QString &machineId, const QString &machineName,
|
||||||
const QString &processName, qint64 processId) :
|
const QString &processName, qint64 processId) :
|
||||||
ITimestampBased(QDateTime::currentMSecsSinceEpoch()),
|
|
||||||
m_name(name), m_machineIdBase64(machineId), m_machineName(machineName),
|
m_name(name), m_machineIdBase64(machineId), m_machineName(machineName),
|
||||||
m_processName(processName), m_processId(processId)
|
m_processName(processName), m_processId(processId)
|
||||||
{ }
|
{ }
|
||||||
@@ -157,7 +156,6 @@ namespace BlackMisc
|
|||||||
QByteArray baseData;
|
QByteArray baseData;
|
||||||
baseData.append(getMachineId());
|
baseData.append(getMachineId());
|
||||||
baseData.append(reinterpret_cast<const char *>(&m_processId), sizeof(m_processId));
|
baseData.append(reinterpret_cast<const char *>(&m_processId), sizeof(m_processId));
|
||||||
baseData.append(reinterpret_cast<const char *>(&m_timestampMSecsSinceEpoch), sizeof(m_timestampMSecsSinceEpoch));
|
|
||||||
baseData.append(getName());
|
baseData.append(getName());
|
||||||
return QUuid::createUuidV5(ns, baseData);
|
return QUuid::createUuidV5(ns, baseData);
|
||||||
}
|
}
|
||||||
@@ -283,7 +281,6 @@ namespace BlackMisc
|
|||||||
if (index.isMyself()) { return CVariant::from(*this); }
|
if (index.isMyself()) { return CVariant::from(*this); }
|
||||||
|
|
||||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
|
|
||||||
|
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
@@ -305,7 +302,6 @@ namespace BlackMisc
|
|||||||
if (index.isMyself()) { return Compare::compare(m_processId, compareValue.m_processId); }
|
if (index.isMyself()) { return Compare::compare(m_processId, compareValue.m_processId); }
|
||||||
|
|
||||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::comparePropertyByIndex(index, compareValue); }
|
|
||||||
|
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,10 +13,7 @@
|
|||||||
|
|
||||||
#include "blackmisc/blackmiscexport.h"
|
#include "blackmisc/blackmiscexport.h"
|
||||||
#include "blackmisc/metaclass.h"
|
#include "blackmisc/metaclass.h"
|
||||||
#include "blackmisc/propertyindex.h"
|
|
||||||
#include "blackmisc/timestampbased.h"
|
|
||||||
#include "blackmisc/valueobject.h"
|
#include "blackmisc/valueobject.h"
|
||||||
#include "blackmisc/variant.h"
|
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
@@ -30,9 +27,7 @@ namespace BlackMisc
|
|||||||
/*!
|
/*!
|
||||||
* Value object encapsulating information identifying a component of a modular distributed swift process (core, GUI, audio)
|
* Value object encapsulating information identifying a component of a modular distributed swift process (core, GUI, audio)
|
||||||
*/
|
*/
|
||||||
class BLACKMISC_EXPORT CIdentifier :
|
class BLACKMISC_EXPORT CIdentifier : public CValueObject<CIdentifier>
|
||||||
public CValueObject<CIdentifier>,
|
|
||||||
public ITimestampBased
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Properties by index
|
//! Properties by index
|
||||||
@@ -172,8 +167,7 @@ namespace BlackMisc
|
|||||||
BLACK_METAMEMBER(machineIdBase64),
|
BLACK_METAMEMBER(machineIdBase64),
|
||||||
BLACK_METAMEMBER(machineName, 0, DisabledForComparison | DisabledForHashing),
|
BLACK_METAMEMBER(machineName, 0, DisabledForComparison | DisabledForHashing),
|
||||||
BLACK_METAMEMBER(processName),
|
BLACK_METAMEMBER(processName),
|
||||||
BLACK_METAMEMBER(processId),
|
BLACK_METAMEMBER(processId)
|
||||||
BLACK_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForComparison | DisabledForHashing)
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
class BLACKMISC_EXPORT CIdentifierList :
|
class BLACKMISC_EXPORT CIdentifierList :
|
||||||
public CSequence<CIdentifier>,
|
public CSequence<CIdentifier>,
|
||||||
public Mixin::MetaType<CIdentifierList>,
|
public Mixin::MetaType<CIdentifierList>
|
||||||
public ITimestampObjectList<CIdentifier, CIdentifierList>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CIdentifierList)
|
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CIdentifierList)
|
||||||
|
|||||||
@@ -747,7 +747,6 @@ namespace BlackMisc
|
|||||||
// see here for the reason of thess forward instantiations
|
// see here for the reason of thess forward instantiations
|
||||||
// https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
|
// https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
|
||||||
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::CCountry, BlackMisc::CCountryList>;
|
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::CCountry, BlackMisc::CCountryList>;
|
||||||
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::CIdentifier, BlackMisc::CIdentifierList>;
|
|
||||||
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
||||||
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList>;
|
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftIcaoCode, BlackMisc::Aviation::CAircraftIcaoCodeList>;
|
||||||
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftCategory, BlackMisc::Aviation::CAircraftCategoryList>;
|
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE ITimestampObjectList<BlackMisc::Aviation::CAircraftCategory, BlackMisc::Aviation::CAircraftCategoryList>;
|
||||||
|
|||||||
@@ -329,8 +329,6 @@ namespace BlackMisc
|
|||||||
|
|
||||||
class CStatusMessage;
|
class CStatusMessage;
|
||||||
class CStatusMessageList;
|
class CStatusMessageList;
|
||||||
class CIdentifier;
|
|
||||||
class CIdentifierList;
|
|
||||||
class CCountry;
|
class CCountry;
|
||||||
class CCountryList;
|
class CCountryList;
|
||||||
|
|
||||||
@@ -349,7 +347,6 @@ namespace BlackMisc
|
|||||||
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CRawFsdMessage, BlackMisc::Network::CRawFsdMessageList>;
|
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CRawFsdMessage, BlackMisc::Network::CRawFsdMessageList>;
|
||||||
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CUrlLog, BlackMisc::Network::CUrlLogList>;
|
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::Network::CUrlLog, BlackMisc::Network::CUrlLogList>;
|
||||||
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
||||||
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CIdentifier, BlackMisc::CIdentifierList>;
|
|
||||||
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CCountry, BlackMisc::CCountryList>;
|
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CCountry, BlackMisc::CCountryList>;
|
||||||
|
|
||||||
// for the derived version both templates are required
|
// for the derived version both templates are required
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
class CIdentifier;
|
||||||
|
|
||||||
namespace Weather
|
namespace Weather
|
||||||
{
|
{
|
||||||
//! Direct threadsafe in memory access to weather grid
|
//! Direct threadsafe in memory access to weather grid
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
|
|
||||||
CContinuousWorker::CContinuousWorker(QObject *owner, const QString &name) :
|
CContinuousWorker::CContinuousWorker(QObject *owner, const QString &name) :
|
||||||
CIdentifiable(name),
|
|
||||||
m_owner(owner), m_name(name)
|
m_owner(owner), m_name(name)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Empty name");
|
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Empty name");
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
#include "blackmisc/invoke.h"
|
#include "blackmisc/invoke.h"
|
||||||
#include "blackmisc/promise.h"
|
#include "blackmisc/promise.h"
|
||||||
#include "blackmisc/stacktrace.h"
|
#include "blackmisc/stacktrace.h"
|
||||||
#include "blackmisc/identifiable.h"
|
|
||||||
#include "blackmisc/variant.h"
|
#include "blackmisc/variant.h"
|
||||||
|
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
@@ -266,9 +265,7 @@ namespace BlackMisc
|
|||||||
/*!
|
/*!
|
||||||
* Base class for a long-lived worker object which lives in its own thread.
|
* Base class for a long-lived worker object which lives in its own thread.
|
||||||
*/
|
*/
|
||||||
class BLACKMISC_EXPORT CContinuousWorker :
|
class BLACKMISC_EXPORT CContinuousWorker : public CWorkerBase
|
||||||
public CWorkerBase,
|
|
||||||
public CIdentifiable
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ void SwiftGuiStd::setContextAvailability()
|
|||||||
if (!isShuttingDown && sGui->getIContextApplication() && !sGui->getIContextApplication()->isEmptyObject())
|
if (!isShuttingDown && sGui->getIContextApplication() && !sGui->getIContextApplication()->isEmptyObject())
|
||||||
{
|
{
|
||||||
// ping to check if core is still alive
|
// ping to check if core is still alive
|
||||||
m_coreAvailable = this->isMyIdentifier(sGui->getIContextApplication()->registerApplication(getCurrentTimestampIdentifier()));
|
m_coreAvailable = this->isMyIdentifier(sGui->getIContextApplication()->registerApplication(identifier()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user