6 #include <QCoreApplication>
8 #include <QStringBuilder>
30 const QString &cachedEscapedApplicationName()
37 const QString &cachedLocalHostName()
45 UuidStringLen =
sizeof(
"00000000-0000-0000-0000-000000000000")
51 return machineUniqueId;
56 CIdentifier::CIdentifier(
const QString &name)
57 : m_name(name.trimmed()), m_machineIdBase64(cachedMachineUniqueId().toBase64(
QByteArray::OmitTrailingEquals)),
58 m_machineName(cachedLocalHostName()), m_processName(cachedEscapedApplicationName()),
73 const QString &processName, qint64 processId)
74 : m_name(name), m_machineIdBase64(machineId), m_machineName(machineName), m_processName(processName),
75 m_processId(processId)
94 "fake machine",
"fake process", 0);
103 baseData.
append(
reinterpret_cast<const char *
>(&m_processId),
sizeof(m_processId));
112 if (m_name.
endsWith(name)) {
return; }
113 if (name.
isEmpty()) {
return; }
115 if (index >= 0) { m_name = m_name.
left(index); }
116 m_name += QStringLiteral(
":") + name;
121 if (!
object) {
return; }
134 path +=
'/' % toDBusPathElement(m_machineName) %
"__" % toDBusPathElement(m_machineIdBase64);
135 path +=
'/' % toDBusPathElement(m_processName) %
"__" %
QString::number(m_processId);
137 const QString name = toDBusPath(m_name);
139 if (!name.
isEmpty()) { path +=
'/' % name; }
151 result.m_machineIdBase64 = fromDBusPathElement(machine.
section(
"__", 1, 1));
152 result.m_machineName = fromDBusPathElement(machine.
section(
"__", 0, 0));
153 result.m_processId = process.
section(
"__", 1, 1).
toInt();
154 result.m_processName = fromDBusPathElement(process.
section(
"__", 0, 0));
165 return !m_machineIdBase64.
isEmpty() && m_machineIdBase64 == other.m_machineIdBase64;
186 return cachedEscapedApplicationName() == toDBusPathElement(
getProcessName());
196 m_machineName = cachedLocalHostName();
208 const QString s = m_name % u
' ' % m_machineIdBase64 % u
' ' % m_machineName % u
' ' %
236 if (index.
isMyself()) {
return Compare::compare(m_processId, compareValue.m_processId); }
243 case IndexMachineIdBase64:
return m_machineIdBase64.
compare(compareValue.m_machineIdBase64);
246 case IndexProcessId:
return Compare::compare(m_processId, compareValue.m_processId);
248 case IndexIsFromLocalMachine:
250 case IndexIsFromSameProcess:
252 case IndexIsFromSameProcessName:
Value object encapsulating information identifying a component of a modular distributed swift process...
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool hasApplicationProcessName() const
Check if originating from the same process name.
static const CIdentifier & anonymous()
Returns an anonymous identifier, which is a valid identifier without name.
bool hasSameMachineId(const CIdentifier &other) const
Check if other identifier is from the same machine id.
void appendName(const QString &name)
Set name or append name.
bool isNull() const
Null identifier (no name, ids etc)
ColumnIndex
Properties by index.
bool isAnonymous() const
Check if it is anonymous identifier.
qint64 getProcessId() const
Get process id.
QUuid toUuid() const
Produces a UUID generated from the identifier.
QByteArray getMachineId() const
Get machine id.
bool hasApplicationProcessId() const
Check if originating from the same process id.
const QString & getProcessName() const
Get process name.
const QString & getName() const
Name.
static CIdentifier fromDBusObjectPath(const QString &path, const QString &root={})
Reconstruct an identifier from a DBus object path.
static const CIdentifier & fake()
Returns a fake identifier.
const QString & getMachineName() const
Machine name.
bool hasSameMachineName(const CIdentifier &other) const
Check if the other identifier has the same machine name.
void updateToCurrentProcess()
Update to current process.
bool isFromLocalMachine() const
Check if originating from the same local machine.
void updateToCurrentMachine()
Update to current machine.
void linkWithQObjectName(QObject *object)
Reflect changes of QObject::
bool hasSameMachineNameOrId(const CIdentifier &other) const
Same machine or id?
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
static const CIdentifier & null()
Null (empty) identifier.
QString toUuidString() const
UUID string.
QString convertToQString(bool i18n=false) const
Cast as QString.
QString toDBusObjectPath(const QString &root={}) const
Produces a DBus object path from the identifier.
int comparePropertyByIndex(CPropertyIndexRef index, const CIdentifier &compareValue) const
Compare for index.
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
int comparePropertyByIndex(CPropertyIndexRef index, const Derived &compareValue) const
Compare for index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Free functions in swift::misc.
SWIFT_MISC_EXPORT QByteArray utfToPercentEncoding(const QString &s, const QByteArray &allow={}, char percent='%')
Extended percent encoding supporting UTF-16.
SWIFT_MISC_EXPORT QString utfFromPercentEncoding(const QByteArray &ba, char percent='%')
Reverse utfFromPercentEncoding.
QByteArray & append(QByteArrayView data)
int compare(QByteArrayView bv, Qt::CaseSensitivity cs) const const
QByteArray::FromBase64Result fromBase64Encoding(QByteArray &&base64, QByteArray::Base64Options options)
QByteArray toBase64(QByteArray::Base64Options options) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void objectNameChanged(const QString &objectName)
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
QString left(qsizetype n) &&
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) &&
QString number(double n, char format, int precision)
QString section(QChar sep, qsizetype start, qsizetype end, QString::SectionFlags flags) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
int toInt(bool *ok, int base) const const
QByteArray toLatin1() const const
QByteArray toLocal8Bit() const const
QByteArray machineUniqueId()
QUuid createUuidV5(QUuid ns, QByteArrayView baseData)
QString toString(QUuid::StringFormat mode) const const
QVariant fromValue(T &&value)
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.