1 | // Copyright (C) 2015 basysKom GmbH, opensource@basyskom.com |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qopcuaexpandednodeid.h" |
5 | #include "qopcuatype.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | /*! |
10 | \class QOpcUaExpandedNodeId |
11 | \inmodule QtOpcUa |
12 | \brief The OPC UA ExpandedNodeId. |
13 | |
14 | An expanded node id is a node id where the namespace index can be given as index or as a string URI. |
15 | A list of namespaces and their indices on the server is provided by \l QOpcUaClient::namespaceArray(). |
16 | */ |
17 | |
18 | class QOpcUaExpandedNodeIdData : public QSharedData |
19 | { |
20 | public: |
21 | quint32 serverIndex{0}; |
22 | QString namespaceUri; |
23 | QString nodeId; |
24 | }; |
25 | |
26 | /*! |
27 | Default constructs an expanded node id with no parameters set. |
28 | */ |
29 | QOpcUaExpandedNodeId::QOpcUaExpandedNodeId() |
30 | : data(new QOpcUaExpandedNodeIdData) |
31 | { |
32 | } |
33 | |
34 | /*! |
35 | Constructs an expanded node id from \a rhs. |
36 | */ |
37 | QOpcUaExpandedNodeId::QOpcUaExpandedNodeId(const QOpcUaExpandedNodeId &rhs) |
38 | : data(rhs.data) |
39 | { |
40 | } |
41 | |
42 | /*! |
43 | Constructs an expanded node id from node id string \a nodeId. |
44 | */ |
45 | QOpcUaExpandedNodeId::QOpcUaExpandedNodeId(const QString &nodeId) |
46 | : data(new QOpcUaExpandedNodeIdData) |
47 | { |
48 | data->nodeId = nodeId; |
49 | } |
50 | |
51 | /*! |
52 | Constructs an expanded node id from namespace URI \a namespaceUri, node id string \a nodeId |
53 | and server index \a serverIndex. |
54 | |
55 | \sa setServerIndex |
56 | */ |
57 | QOpcUaExpandedNodeId::QOpcUaExpandedNodeId(const QString &namespaceUri, const QString &nodeId, quint32 serverIndex) |
58 | : data(new QOpcUaExpandedNodeIdData) |
59 | { |
60 | data->namespaceUri = namespaceUri; |
61 | data->nodeId = nodeId; |
62 | data->serverIndex = serverIndex; |
63 | } |
64 | |
65 | /*! |
66 | Sets the values from \a rhs in this expanded node id. |
67 | */ |
68 | QOpcUaExpandedNodeId &QOpcUaExpandedNodeId::operator=(const QOpcUaExpandedNodeId &rhs) |
69 | { |
70 | if (this != &rhs) |
71 | data.operator=(o: rhs.data); |
72 | return *this; |
73 | } |
74 | |
75 | /*! |
76 | Returns \c true if this expanded node id has the same value as \a rhs. |
77 | */ |
78 | bool QOpcUaExpandedNodeId::operator==(const QOpcUaExpandedNodeId &rhs) const |
79 | { |
80 | return data->namespaceUri == rhs.namespaceUri() && |
81 | QOpcUa::nodeIdEquals(first: data->nodeId, second: rhs.nodeId()) && |
82 | data->serverIndex == rhs.serverIndex(); |
83 | } |
84 | |
85 | /*! |
86 | Converts this expanded node id to \l QVariant. |
87 | */ |
88 | QOpcUaExpandedNodeId::operator QVariant() const |
89 | { |
90 | return QVariant::fromValue(value: *this); |
91 | } |
92 | |
93 | QOpcUaExpandedNodeId::~QOpcUaExpandedNodeId() |
94 | { |
95 | } |
96 | |
97 | /*! |
98 | Returns the index of the server containing the node. This index maps to an entry in the server's server table. |
99 | The index of the local server is always \c 0. All remote servers have indexes greater than \c 0. |
100 | */ |
101 | quint32 QOpcUaExpandedNodeId::serverIndex() const |
102 | { |
103 | return data->serverIndex; |
104 | } |
105 | |
106 | /*! |
107 | Sets the server index to \a serverIndex. |
108 | The index of the local server is always \c 0. All remote servers have indexes greater than \c 0. |
109 | */ |
110 | void QOpcUaExpandedNodeId::setServerIndex(quint32 serverIndex) |
111 | { |
112 | data->serverIndex = serverIndex; |
113 | } |
114 | |
115 | /*! |
116 | Returns the namespace URI of the node id. If this value is specified, the namespace index in |
117 | \l {QOpcUaExpandedNodeId::nodeId} {nodeId} is 0 and must be ignored. |
118 | */ |
119 | QString QOpcUaExpandedNodeId::namespaceUri() const |
120 | { |
121 | return data->namespaceUri; |
122 | } |
123 | |
124 | /*! |
125 | Sets the namespace URI to \a namespaceUri. |
126 | */ |
127 | void QOpcUaExpandedNodeId::setNamespaceUri(const QString &namespaceUri) |
128 | { |
129 | data->namespaceUri = namespaceUri; |
130 | } |
131 | |
132 | /*! |
133 | Returns the node id. If \l {QOpcUaExpandedNodeId::namespaceUri} {namespaceUri} is specified, the namespace index is invalid. |
134 | */ |
135 | QString QOpcUaExpandedNodeId::nodeId() const |
136 | { |
137 | return data->nodeId; |
138 | } |
139 | |
140 | /*! |
141 | Sets the node id to \a nodeId. |
142 | */ |
143 | void QOpcUaExpandedNodeId::setNodeId(const QString &nodeId) |
144 | { |
145 | data->nodeId = nodeId; |
146 | } |
147 | |
148 | QT_END_NAMESPACE |
149 | |