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 | QOpcUaExpandedNodeId::QOpcUaExpandedNodeId() |
27 | : data(new QOpcUaExpandedNodeIdData) |
28 | { |
29 | } |
30 | |
31 | /*! |
32 | Constructs an expanded node id from \a rhs. |
33 | */ |
34 | QOpcUaExpandedNodeId::QOpcUaExpandedNodeId(const QOpcUaExpandedNodeId &rhs) |
35 | : data(rhs.data) |
36 | { |
37 | } |
38 | |
39 | /*! |
40 | Constructs an expanded node id from node id string \a nodeId. |
41 | */ |
42 | QOpcUaExpandedNodeId::QOpcUaExpandedNodeId(const QString &nodeId) |
43 | : data(new QOpcUaExpandedNodeIdData) |
44 | { |
45 | data->nodeId = nodeId; |
46 | } |
47 | |
48 | /*! |
49 | Constructs an expanded node id from namespace URI \a namespaceUri, node id string \a nodeId |
50 | and server index \a serverIndex. |
51 | |
52 | \sa setServerIndex |
53 | */ |
54 | QOpcUaExpandedNodeId::QOpcUaExpandedNodeId(const QString &namespaceUri, const QString &nodeId, quint32 serverIndex) |
55 | : data(new QOpcUaExpandedNodeIdData) |
56 | { |
57 | data->namespaceUri = namespaceUri; |
58 | data->nodeId = nodeId; |
59 | data->serverIndex = serverIndex; |
60 | } |
61 | |
62 | /*! |
63 | Sets the values from \a rhs in this expanded node id. |
64 | */ |
65 | QOpcUaExpandedNodeId &QOpcUaExpandedNodeId::operator=(const QOpcUaExpandedNodeId &rhs) |
66 | { |
67 | if (this != &rhs) |
68 | data.operator=(o: rhs.data); |
69 | return *this; |
70 | } |
71 | |
72 | /*! |
73 | Returns \c true if this expanded node id has the same value as \a rhs. |
74 | */ |
75 | bool QOpcUaExpandedNodeId::operator==(const QOpcUaExpandedNodeId &rhs) const |
76 | { |
77 | return data->namespaceUri == rhs.namespaceUri() && |
78 | QOpcUa::nodeIdEquals(first: data->nodeId, second: rhs.nodeId()) && |
79 | data->serverIndex == rhs.serverIndex(); |
80 | } |
81 | |
82 | /*! |
83 | Converts this expanded node id to \l QVariant. |
84 | */ |
85 | QOpcUaExpandedNodeId::operator QVariant() const |
86 | { |
87 | return QVariant::fromValue(value: *this); |
88 | } |
89 | |
90 | QOpcUaExpandedNodeId::~QOpcUaExpandedNodeId() |
91 | { |
92 | } |
93 | |
94 | /*! |
95 | Returns the index of the server containing the node. This index maps to an entry in the server's server table. |
96 | The index of the local server is always \c 0. All remote servers have indexes greater than \c 0. |
97 | */ |
98 | quint32 QOpcUaExpandedNodeId::serverIndex() const |
99 | { |
100 | return data->serverIndex; |
101 | } |
102 | |
103 | /*! |
104 | Sets the server index to \a serverIndex. |
105 | The index of the local server is always \c 0. All remote servers have indexes greater than \c 0. |
106 | */ |
107 | void QOpcUaExpandedNodeId::setServerIndex(quint32 serverIndex) |
108 | { |
109 | data->serverIndex = serverIndex; |
110 | } |
111 | |
112 | /*! |
113 | Returns the namespace URI of the node id. If this value is specified, the namespace index in |
114 | \l {QOpcUaExpandedNodeId::nodeId} {nodeId} is 0 and must be ignored. |
115 | */ |
116 | QString QOpcUaExpandedNodeId::namespaceUri() const |
117 | { |
118 | return data->namespaceUri; |
119 | } |
120 | |
121 | /*! |
122 | Sets the namespace URI to \a namespaceUri. |
123 | */ |
124 | void QOpcUaExpandedNodeId::setNamespaceUri(const QString &namespaceUri) |
125 | { |
126 | data->namespaceUri = namespaceUri; |
127 | } |
128 | |
129 | /*! |
130 | Returns the node id. If \l {QOpcUaExpandedNodeId::namespaceUri} {namespaceUri} is specified, the namespace index is invalid. |
131 | */ |
132 | QString QOpcUaExpandedNodeId::nodeId() const |
133 | { |
134 | return data->nodeId; |
135 | } |
136 | |
137 | /*! |
138 | Sets the node id to \a nodeId. |
139 | */ |
140 | void QOpcUaExpandedNodeId::setNodeId(const QString &nodeId) |
141 | { |
142 | data->nodeId = nodeId; |
143 | } |
144 | |
145 | QT_END_NAMESPACE |
146 |