Issue #77 Break dependency of worker on identifiable

This commit is contained in:
Mat Sutcliffe
2020-08-27 18:12:43 +01:00
parent 89659fdeaa
commit 479210957a
15 changed files with 18 additions and 51 deletions

View File

@@ -57,6 +57,7 @@ namespace BlackCore
CAfvClient::CAfvClient(const QString &apiServer, QObject *owner) :
CContinuousWorker(owner, "CAfvClient"),
CIdentifiable("CAfvClient"),
m_connection(new CClientConnection(apiServer, this)),
m_input(new CInput(SampleRate, this)),
m_output(new COutput(this)),

View File

@@ -45,7 +45,7 @@ namespace BlackCore
namespace Clients
{
//! AFV client
class BLACKCORE_EXPORT CAfvClient final : public BlackMisc::CContinuousWorker
class BLACKCORE_EXPORT CAfvClient final : public BlackMisc::CContinuousWorker, public BlackMisc::CIdentifiable
{
Q_OBJECT

View File

@@ -130,19 +130,12 @@ namespace BlackCore
{
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << application; }
CIdentifier identifier(application);
identifier.setCurrentUtcTime();
if (!m_registeredApplications.contains(identifier))
if (!m_registeredApplications.contains(application))
{
m_registeredApplications.push_back(identifier);
m_registeredApplications.push_back(application);
emit this->registrationChanged();
emit this->hotkeyActionsRegistered(sApp->getInputManager()->allAvailableActions(), {});
}
else
{
m_registeredApplications.replace(application, identifier);
}
this->cleanupRegisteredApplications();
return application;
@@ -158,15 +151,16 @@ namespace BlackCore
void CContextApplication::cleanupRegisteredApplications()
{
static const int outdatedMs = qRound(1.5 * PingIdentifiersMs);
m_registeredApplications.removeOlderThanNowMinusOffset(outdatedMs);
//static const int outdatedMs = qRound(1.5 * PingIdentifiersMs);
//m_registeredApplications.removeOlderThanNowMinusOffset(outdatedMs);
}
CIdentifierList CContextApplication::getRegisteredApplications() const
{
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
static const int outdatedMs = qRound(1.5 * PingIdentifiersMs);
return m_registeredApplications.findAfterNowMinusOffset(outdatedMs);
//static const int outdatedMs = qRound(1.5 * PingIdentifiersMs);
//return m_registeredApplications.findAfterNowMinusOffset(outdatedMs);
return m_registeredApplications;
}
CIdentifier CContextApplication::getApplicationIdentifier() const

View File

@@ -26,7 +26,6 @@ namespace BlackGui
this->m_columns.addColumn(CColumn::standardString("machine", CIdentifier::IndexMachineName));
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("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("same p.", "same process", CIdentifier::IndexIsFromSameProcess, new CBoolIconFormatter("same process", "other process")));
this->m_columns.addColumn(CColumn::standardString("m.id", "machine id", CIdentifier::IndexMachineIdBase64));

View File

@@ -10,13 +10,6 @@
namespace BlackMisc
{
CIdentifier CIdentifiable::getCurrentTimestampIdentifier() const
{
CIdentifier o(m_identifier);
o.setCurrentUtcTime();
return o;
}
CIdentifiable::CIdentifiable(QObject *object) : m_identifier(object->objectName())
{
// if the object name changes we update our originator

View File

@@ -34,9 +34,6 @@ namespace BlackMisc
//! Set identifier, allows to set an external identifier
void setIdentifier(const CIdentifier &identifier) { m_identifier = identifier; }
//! Identifier with current timestamp
CIdentifier getCurrentTimestampIdentifier() const;
//! My identifier?
bool isMyIdentifier(const CIdentifier &otherIdentifier) const { return m_identifier == otherIdentifier; }

View File

@@ -9,6 +9,7 @@
#include "blackmisc/identifier.h"
#include "blackmisc/comparefunctions.h"
#include "blackmisc/stringutils.h"
#include "blackmisc/propertyindex.h"
#include <QCoreApplication>
#include <QHostInfo>
@@ -108,8 +109,7 @@ QByteArray cachedMachineUniqueId()
namespace BlackMisc
{
CIdentifier::CIdentifier(const QString &name)
: ITimestampBased(QDateTime::currentMSecsSinceEpoch()),
m_name(name.trimmed()),
: m_name(name.trimmed()),
m_machineIdBase64(cachedMachineUniqueId().toBase64(QByteArray::OmitTrailingEquals)),
m_machineName(cachedLocalHostName()),
m_processName(cachedEscapedApplicationName()),
@@ -128,7 +128,6 @@ namespace BlackMisc
CIdentifier::CIdentifier(const QString &name, const QString &machineId, const QString &machineName,
const QString &processName, qint64 processId) :
ITimestampBased(QDateTime::currentMSecsSinceEpoch()),
m_name(name), m_machineIdBase64(machineId), m_machineName(machineName),
m_processName(processName), m_processId(processId)
{ }
@@ -157,7 +156,6 @@ namespace BlackMisc
QByteArray baseData;
baseData.append(getMachineId());
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());
return QUuid::createUuidV5(ns, baseData);
}
@@ -283,7 +281,6 @@ namespace BlackMisc
if (index.isMyself()) { return CVariant::from(*this); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
switch (i)
{
@@ -305,7 +302,6 @@ namespace BlackMisc
if (index.isMyself()) { return Compare::compare(m_processId, compareValue.m_processId); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::comparePropertyByIndex(index, compareValue); }
switch (i)
{

View File

@@ -13,10 +13,7 @@
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/metaclass.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/timestampbased.h"
#include "blackmisc/valueobject.h"
#include "blackmisc/variant.h"
#include <QByteArray>
#include <QMetaType>
@@ -30,9 +27,7 @@ namespace BlackMisc
/*!
* Value object encapsulating information identifying a component of a modular distributed swift process (core, GUI, audio)
*/
class BLACKMISC_EXPORT CIdentifier :
public CValueObject<CIdentifier>,
public ITimestampBased
class BLACKMISC_EXPORT CIdentifier : public CValueObject<CIdentifier>
{
public:
//! Properties by index
@@ -172,8 +167,7 @@ namespace BlackMisc
BLACK_METAMEMBER(machineIdBase64),
BLACK_METAMEMBER(machineName, 0, DisabledForComparison | DisabledForHashing),
BLACK_METAMEMBER(processName),
BLACK_METAMEMBER(processId),
BLACK_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForComparison | DisabledForHashing)
BLACK_METAMEMBER(processId)
);
};
} // namespace

View File

@@ -25,8 +25,7 @@ namespace BlackMisc
*/
class BLACKMISC_EXPORT CIdentifierList :
public CSequence<CIdentifier>,
public Mixin::MetaType<CIdentifierList>,
public ITimestampObjectList<CIdentifier, CIdentifierList>
public Mixin::MetaType<CIdentifierList>
{
public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CIdentifierList)

View File

@@ -747,7 +747,6 @@ namespace BlackMisc
// see here for the reason of thess forward instantiations
// 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::CIdentifier, BlackMisc::CIdentifierList>;
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::CAircraftCategory, BlackMisc::Aviation::CAircraftCategoryList>;

View File

@@ -329,8 +329,6 @@ namespace BlackMisc
class CStatusMessage;
class CStatusMessageList;
class CIdentifier;
class CIdentifierList;
class CCountry;
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::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::CIdentifier, BlackMisc::CIdentifierList>;
extern template class BLACKMISC_EXPORT_DECLARE_TEMPLATE ITimestampObjectList<BlackMisc::CCountry, BlackMisc::CCountryList>;
// for the derived version both templates are required

View File

@@ -21,6 +21,8 @@
namespace BlackMisc
{
class CIdentifier;
namespace Weather
{
//! Direct threadsafe in memory access to weather grid

View File

@@ -149,7 +149,6 @@ namespace BlackMisc
}
CContinuousWorker::CContinuousWorker(QObject *owner, const QString &name) :
CIdentifiable(name),
m_owner(owner), m_name(name)
{
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Empty name");

View File

@@ -17,7 +17,6 @@
#include "blackmisc/invoke.h"
#include "blackmisc/promise.h"
#include "blackmisc/stacktrace.h"
#include "blackmisc/identifiable.h"
#include "blackmisc/variant.h"
#include <QFuture>
@@ -266,9 +265,7 @@ namespace BlackMisc
/*!
* Base class for a long-lived worker object which lives in its own thread.
*/
class BLACKMISC_EXPORT CContinuousWorker :
public CWorkerBase,
public CIdentifiable
class BLACKMISC_EXPORT CContinuousWorker : public CWorkerBase
{
Q_OBJECT

View File

@@ -313,7 +313,7 @@ void SwiftGuiStd::setContextAvailability()
if (!isShuttingDown && sGui->getIContextApplication() && !sGui->getIContextApplication()->isEmptyObject())
{
// 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
{