1// Copyright (C) 2023 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 "qopcuaconnectionsettings.h"
5
6#include <QtCore/qstringlist.h>
7
8using namespace std::chrono_literals;
9
10QT_BEGIN_NAMESPACE
11
12/*!
13 \class QOpcUaConnectionSettings
14 \inmodule QtOpcUa
15 \brief The common parameters for a connection to a server.
16 \since 6.6
17
18 This class stores common connection parameters like the session timeout, the
19 secure channel lifetime and the localeIds.
20
21 The information from this class is currently only used by the open62541 backend.
22*/
23
24class QOpcUaConnectionSettingsData : public QSharedData
25{
26public:
27 QStringList sessionLocaleIds;
28
29 std::chrono::milliseconds secureChannelLifeTime = 10min;
30 std::chrono::milliseconds sessionTimeout = 20min;
31 std::chrono::milliseconds requestTimeout = 5s;
32 std::chrono::milliseconds connectTimeout = 5s;
33};
34QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QOpcUaConnectionSettingsData)
35
36/*!
37 Constructs a connection settings object.
38*/
39QOpcUaConnectionSettings::QOpcUaConnectionSettings()
40 : data(new QOpcUaConnectionSettingsData)
41{
42}
43
44/*!
45 Constructs a connection settings object with the values of \a other.
46*/
47QOpcUaConnectionSettings::QOpcUaConnectionSettings(const QOpcUaConnectionSettings &other)
48 = default;
49
50/*!
51 Sets the values from \a rhs in this connection settings object.
52*/
53QOpcUaConnectionSettings &QOpcUaConnectionSettings::operator=(const QOpcUaConnectionSettings &rhs)
54 = default;
55
56/*!
57 Destroys this connection settings object.
58*/
59QOpcUaConnectionSettings::~QOpcUaConnectionSettings()
60 = default;
61
62/*!
63 \fn QOpcUaConnectionSettings::QOpcUaConnectionSettings(QOpcUaConnectionSettings &&other)
64
65 Move-constructs a new connection settings object from \a other.
66
67 \note The moved-from object \a other is placed in a
68 partially-formed state, in which the only valid operations are
69 destruction and assignment of a new value.
70*/
71
72/*!
73 \fn QOpcUaConnectionSettings &QOpcUaConnectionSettings::operator=(QOpcUaConnectionSettings &&other)
74
75 Move-assigns \a other to this QOpcUaConnectionSettings instance.
76
77 \note The moved-from object \a other is placed in a
78 partially-formed state, in which the only valid operations are
79 destruction and assignment of a new value.
80*/
81
82/*!
83 \fn void QOpcUaConnectionSettings::swap(QOpcUaConnectionSettings &other)
84
85 Swaps connection settings object \a other with this connection settings
86 object. This operation is very fast and never fails.
87*/
88
89/*!
90 Returns \c true if \a lhs contains the same connection settings as \l rhs; otherwise returns \c
91 false.
92*/
93bool operator==(const QOpcUaConnectionSettings &lhs, const QOpcUaConnectionSettings &rhs) noexcept
94{
95 return lhs.data->sessionLocaleIds == rhs.data->sessionLocaleIds &&
96 lhs.data->connectTimeout == rhs.data->connectTimeout &&
97 lhs.data->secureChannelLifeTime == rhs.data->secureChannelLifeTime &&
98 lhs.data->sessionTimeout == rhs.data->sessionTimeout &&
99 lhs.data->requestTimeout == rhs.data->requestTimeout;
100}
101
102/*!
103 \fn bool QOpcUaConnectionSettings::operator!=(const QOpcUaConnectionSettings &rhs, const
104 QOpcUaConnectionSettings &rhs)
105
106 Returns \c true if \a lhs does not contain the same connection settings as \l rhs; otherwise
107 returns \c false.
108*/
109
110/*!
111 Returns the session locale ids.
112*/
113QStringList QOpcUaConnectionSettings::sessionLocaleIds() const
114{
115 return data->sessionLocaleIds;
116}
117
118/*!
119 Sets \a localeIds as the new list of locale IDs.
120 This setting is currently not supported by the open62541 backend.
121
122 For details, see \l{https://reference.opcfoundation.org/v104/Core/docs/Part4/5.6.3/#Table17}
123*/
124void QOpcUaConnectionSettings::setSessionLocaleIds(const QStringList &localeIds)
125{
126 if (data->sessionLocaleIds == localeIds)
127 return;
128 data.detach();
129 data->sessionLocaleIds = localeIds;
130}
131
132/*!
133 Returns the secure channel lifetime.
134*/
135std::chrono::milliseconds QOpcUaConnectionSettings::secureChannelLifeTime() const
136{
137 return data->secureChannelLifeTime;
138}
139
140/*!
141 Sets \a lifeTime as the new secure channel lifetime.
142
143 For details, see \l{https://reference.opcfoundation.org/v104/Core/docs/Part4/5.5.2/#Table11}
144*/
145void QOpcUaConnectionSettings::setSecureChannelLifeTime(std::chrono::milliseconds lifeTime)
146{
147 if (data->secureChannelLifeTime == lifeTime)
148 return;
149 data.detach();
150 data->secureChannelLifeTime = lifeTime;
151}
152
153/*!
154 Returns the requested session timeout.
155*/
156std::chrono::milliseconds QOpcUaConnectionSettings::sessionTimeout() const
157{
158 return data->sessionTimeout;
159}
160
161/*!
162 Sets \a timeout as the new requested session timeout.
163
164 For details, see \l{https://reference.opcfoundation.org/v104/Core/docs/Part4/5.6.2/#Table15}
165*/
166void QOpcUaConnectionSettings::setSessionTimeout(std::chrono::milliseconds timeout)
167{
168 if (data->sessionTimeout == timeout)
169 return;
170 data.detach();
171 data->sessionTimeout = timeout;
172}
173
174/*!
175 Returns the request timeout.
176
177 This value determines how long a synchronous service call will wait for a reply.
178*/
179std::chrono::milliseconds QOpcUaConnectionSettings::requestTimeout() const
180{
181 return data->requestTimeout;
182}
183
184/*!
185 Sets \a timeout as the new request timeout.
186*/
187void QOpcUaConnectionSettings::setRequestTimeout(std::chrono::milliseconds timeout)
188{
189 if (data->requestTimeout == timeout)
190 return;
191 data.detach();
192 data->requestTimeout = timeout;
193}
194
195/*!
196 Returns the connect timeout.
197
198 This value determines how long the connect will wait for a reply.
199*/
200std::chrono::milliseconds QOpcUaConnectionSettings::connectTimeout() const
201{
202 return data->connectTimeout;
203}
204
205/*!
206 Sets \a timeout as the new connect timeout.
207*/
208void QOpcUaConnectionSettings::setConnectTimeout(std::chrono::milliseconds timeout)
209{
210 if (data->connectTimeout == timeout)
211 return;
212 data.detach();
213 data->connectTimeout = timeout;
214}
215
216QT_END_NAMESPACE
217

source code of qtopcua/src/opcua/client/qopcuaconnectionsettings.cpp