diff --git a/src/blackmisc/identifier.cpp b/src/blackmisc/identifier.cpp index 09a5a3348..0e5c78685 100644 --- a/src/blackmisc/identifier.cpp +++ b/src/blackmisc/identifier.cpp @@ -38,6 +38,19 @@ namespace BlackMisc return id; } + CIdentifier CIdentifier::fake() + { + static CIdentifier id; + if (id.m_processId) + { + id.m_processId = 0; + id.m_processName = "fake process"; + id.m_machineName = "fake machine"; + id.m_machineIdBase64 = QByteArrayLiteral("0").repeated(32).toBase64(); + } + return id; + } + QUuid CIdentifier::toUuid() const { static const QUuid ns = QUuid::createUuid(); @@ -59,6 +72,11 @@ namespace BlackMisc return QDBusConnection::localMachineId() == getMachineId(); } + bool CIdentifier::isFromSameMachine(const CIdentifier &other) const + { + return getMachineIdBase64() == other.getMachineIdBase64(); + } + bool CIdentifier::isFromSameProcess() const { return QCoreApplication::applicationPid() == getProcessId() && isFromLocalMachine(); diff --git a/src/blackmisc/identifier.h b/src/blackmisc/identifier.h index baf470253..312993519 100644 --- a/src/blackmisc/identifier.h +++ b/src/blackmisc/identifier.h @@ -55,6 +55,9 @@ namespace BlackMisc //! Returns an anonymous identifier. static CIdentifier anonymous(); + //! Returns a fake identifier. + static CIdentifier fake(); + //! Produces a UUID generated from the identifier. QUuid toUuid() const; @@ -82,6 +85,9 @@ namespace BlackMisc //! Check if originating from the same local machine bool isFromLocalMachine() const; + //! Check if other identifier is from the same machine + bool isFromSameMachine(const CIdentifier &other) const; + //! Check if originating from the same process id bool isFromSameProcess() const;