CIdentifier utility classes

fake() returns a fake identifier, simulating an existing one.
isFromSameMachine() is a utility class to compare whether another
CIdentifier is from the same machine

refs #881
This commit is contained in:
Roland Winklmeier
2017-03-05 14:00:11 +01:00
committed by Mathew Sutcliffe
parent 42a13fceff
commit 54b76d91ad
2 changed files with 24 additions and 0 deletions

View File

@@ -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();