swift
identifier.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_IDENTIFIER_H
7 #define SWIFT_MISC_IDENTIFIER_H
8 
9 #include <QByteArray>
10 #include <QMetaType>
11 #include <QObject>
12 #include <QString>
13 #include <QUuid>
14 #include <QtGlobal>
15 
16 #include "misc/metaclass.h"
17 #include "misc/swiftmiscexport.h"
18 #include "misc/valueobject.h"
19 
21 
22 namespace swift::misc
23 {
28  class SWIFT_MISC_EXPORT CIdentifier : public CValueObject<CIdentifier>
29  {
30  public:
33  {
34  IndexName = CPropertyIndexRef::GlobalIndexCIdentifier,
35  IndexMachineId,
36  IndexMachineIdBase64,
37  IndexMachineName,
38  IndexProcessId,
39  IndexProcessName,
40  IndexIsFromLocalMachine,
41  IndexIsFromSameProcess,
42  IndexIsFromSameProcessName
43  };
44 
48  CIdentifier() : CIdentifier("") {}
49 
51  CIdentifier(const QString &name);
52 
55  CIdentifier(const QString &name, QObject *object);
56 
59  static const CIdentifier &anonymous();
60 
62  static const CIdentifier &null();
63 
65  static const CIdentifier &fake();
66 
68  QUuid toUuid() const;
69 
71  QString toUuidString() const;
72 
74  QString toDBusObjectPath(const QString &root = {}) const;
75 
77  static CIdentifier fromDBusObjectPath(const QString &path, const QString &root = {});
78 
80  const QString &getName() const { return m_name; }
81 
83  bool hasName() const { return !m_name.isEmpty(); }
84 
86  void setName(const QString &name) { m_name = name; }
87 
91  void appendName(const QString &name);
92 
94  void linkWithQObjectName(QObject *object);
95 
97  QByteArray getMachineId() const;
98 
100  const QString &getMachineIdBase64() const { return m_machineIdBase64; }
101 
103  const QString &getMachineName() const { return m_machineName; }
104 
106  bool hasSameMachineName(const CIdentifier &other) const;
107 
109  bool hasSameMachineId(const CIdentifier &other) const;
110 
112  bool hasSameMachineNameOrId(const CIdentifier &other) const;
113 
115  qint64 getProcessId() const { return m_processId; }
116 
118  const QString &getProcessName() const { return m_processName; }
119 
121  bool isFromLocalMachine() const;
122 
124  bool hasApplicationProcessId() const;
125 
127  bool hasApplicationProcessName() const;
128 
130  bool isAnonymous() const;
131 
133  bool isNull() const;
134 
136  void updateToCurrentMachine();
137 
139  void updateToCurrentProcess();
140 
142  QString convertToQString(bool i18n = false) const;
143 
145  QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const;
146 
148  void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
149 
151  int comparePropertyByIndex(CPropertyIndexRef index, const CIdentifier &compareValue) const;
152 
153  private:
155  CIdentifier(const QString &name, const QString &machineId, const QString &machineName,
156  const QString &processName, qint64 processId = 0);
157 
158  QString m_name;
159  QString m_machineIdBase64;
160  QString m_machineName;
161  QString m_processName;
162  qint64 m_processId;
163 
165  CIdentifier,
166  SWIFT_METAMEMBER(name),
167  SWIFT_METAMEMBER(machineIdBase64),
169  SWIFT_METAMEMBER(processName),
170  SWIFT_METAMEMBER(processId));
171  };
172 } // namespace swift::misc
173 
174 Q_DECLARE_METATYPE(swift::misc::CIdentifier)
175 
176 #endif // SWIFT_MISC_IDENTIFIER_H
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition: identifier.h:29
ColumnIndex
Properties by index.
Definition: identifier.h:33
qint64 getProcessId() const
Get process id.
Definition: identifier.h:115
const QString & getProcessName() const
Get process name.
Definition: identifier.h:118
bool hasName() const
Has name.
Definition: identifier.h:83
const QString & getName() const
Name.
Definition: identifier.h:80
const QString & getMachineName() const
Machine name.
Definition: identifier.h:103
const QString & getMachineIdBase64() const
Machine base64 encoded.
Definition: identifier.h:100
void setName(const QString &name)
Set the name.
Definition: identifier.h:86
Non-owning reference to a CPropertyIndex with a subset of its features.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
@ DisabledForComparison
Element will be ignored by compare() and comparison operators.
Definition: metaclass.h:202
@ DisabledForHashing
Element will be ignored by qHash()
Definition: metaclass.h:205
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition: valueobject.h:65