mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-25 10:15:43 +08:00
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:
committed by
Mathew Sutcliffe
parent
42a13fceff
commit
54b76d91ad
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user