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 | |
8 | using namespace std::chrono_literals; |
9 | |
10 | QT_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 | |
24 | class QOpcUaConnectionSettingsData : public QSharedData |
25 | { |
26 | public: |
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 | }; |
34 | QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QOpcUaConnectionSettingsData) |
35 | |
36 | /*! |
37 | Constructs a connection settings object. |
38 | */ |
39 | QOpcUaConnectionSettings::QOpcUaConnectionSettings() |
40 | : data(new QOpcUaConnectionSettingsData) |
41 | { |
42 | } |
43 | |
44 | /*! |
45 | Constructs a connection settings object with the values of \a other. |
46 | */ |
47 | QOpcUaConnectionSettings::QOpcUaConnectionSettings(const QOpcUaConnectionSettings &other) |
48 | = default; |
49 | |
50 | /*! |
51 | Sets the values from \a rhs in this connection settings object. |
52 | */ |
53 | QOpcUaConnectionSettings &QOpcUaConnectionSettings::operator=(const QOpcUaConnectionSettings &rhs) |
54 | = default; |
55 | |
56 | /*! |
57 | Destroys this connection settings object. |
58 | */ |
59 | QOpcUaConnectionSettings::~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 | \fn bool QOpcUaConnectionSettings::operator==(const QOpcUaConnectionSettings &lhs, |
91 | const QOpcUaConnectionSettings &rhs) |
92 | |
93 | Returns \c true if \a lhs contains the same connection settings as \a rhs; otherwise returns \c |
94 | false. |
95 | */ |
96 | bool operator==(const QOpcUaConnectionSettings &lhs, const QOpcUaConnectionSettings &rhs) noexcept |
97 | { |
98 | return lhs.data->sessionLocaleIds == rhs.data->sessionLocaleIds && |
99 | lhs.data->connectTimeout == rhs.data->connectTimeout && |
100 | lhs.data->secureChannelLifeTime == rhs.data->secureChannelLifeTime && |
101 | lhs.data->sessionTimeout == rhs.data->sessionTimeout && |
102 | lhs.data->requestTimeout == rhs.data->requestTimeout; |
103 | } |
104 | |
105 | /*! |
106 | \fn bool QOpcUaConnectionSettings::operator!=(const QOpcUaConnectionSettings &lhs, |
107 | const QOpcUaConnectionSettings &rhs) |
108 | |
109 | Returns \c true if \a lhs does not contain the same connection settings as \a rhs; otherwise |
110 | returns \c false. |
111 | */ |
112 | |
113 | /*! |
114 | Returns the session locale ids. |
115 | */ |
116 | QStringList QOpcUaConnectionSettings::sessionLocaleIds() const |
117 | { |
118 | return data->sessionLocaleIds; |
119 | } |
120 | |
121 | /*! |
122 | Sets \a localeIds as the new list of locale IDs. |
123 | This setting is currently not supported by the open62541 backend. |
124 | |
125 | For details, see \l{https://reference.opcfoundation.org/v105/Core/docs/Part4/5.6.3/#Table17} |
126 | */ |
127 | void QOpcUaConnectionSettings::setSessionLocaleIds(const QStringList &localeIds) |
128 | { |
129 | if (data->sessionLocaleIds == localeIds) |
130 | return; |
131 | data.detach(); |
132 | data->sessionLocaleIds = localeIds; |
133 | } |
134 | |
135 | /*! |
136 | Returns the secure channel lifetime. |
137 | */ |
138 | std::chrono::milliseconds QOpcUaConnectionSettings::secureChannelLifeTime() const |
139 | { |
140 | return data->secureChannelLifeTime; |
141 | } |
142 | |
143 | /*! |
144 | Sets \a lifeTime as the new secure channel lifetime. |
145 | |
146 | For details, see \l{https://reference.opcfoundation.org/v105/Core/docs/Part4/5.5.2/#Table11} |
147 | */ |
148 | void QOpcUaConnectionSettings::setSecureChannelLifeTime(std::chrono::milliseconds lifeTime) |
149 | { |
150 | if (data->secureChannelLifeTime == lifeTime) |
151 | return; |
152 | data.detach(); |
153 | data->secureChannelLifeTime = lifeTime; |
154 | } |
155 | |
156 | /*! |
157 | Returns the requested session timeout. |
158 | */ |
159 | std::chrono::milliseconds QOpcUaConnectionSettings::sessionTimeout() const |
160 | { |
161 | return data->sessionTimeout; |
162 | } |
163 | |
164 | /*! |
165 | Sets \a timeout as the new requested session timeout. |
166 | |
167 | For details, see \l{https://reference.opcfoundation.org/v105/Core/docs/Part4/5.6.2/#Table15} |
168 | */ |
169 | void QOpcUaConnectionSettings::setSessionTimeout(std::chrono::milliseconds timeout) |
170 | { |
171 | if (data->sessionTimeout == timeout) |
172 | return; |
173 | data.detach(); |
174 | data->sessionTimeout = timeout; |
175 | } |
176 | |
177 | /*! |
178 | Returns the request timeout. |
179 | |
180 | This value determines how long a synchronous service call will wait for a reply. |
181 | */ |
182 | std::chrono::milliseconds QOpcUaConnectionSettings::requestTimeout() const |
183 | { |
184 | return data->requestTimeout; |
185 | } |
186 | |
187 | /*! |
188 | Sets \a timeout as the new request timeout. |
189 | */ |
190 | void QOpcUaConnectionSettings::setRequestTimeout(std::chrono::milliseconds timeout) |
191 | { |
192 | if (data->requestTimeout == timeout) |
193 | return; |
194 | data.detach(); |
195 | data->requestTimeout = timeout; |
196 | } |
197 | |
198 | /*! |
199 | Returns the connect timeout. |
200 | |
201 | This value determines how long the connect will wait for a reply. |
202 | */ |
203 | std::chrono::milliseconds QOpcUaConnectionSettings::connectTimeout() const |
204 | { |
205 | return data->connectTimeout; |
206 | } |
207 | |
208 | /*! |
209 | Sets \a timeout as the new connect timeout. |
210 | */ |
211 | void QOpcUaConnectionSettings::setConnectTimeout(std::chrono::milliseconds timeout) |
212 | { |
213 | if (data->connectTimeout == timeout) |
214 | return; |
215 | data.detach(); |
216 | data->connectTimeout = timeout; |
217 | } |
218 | |
219 | QT_END_NAMESPACE |
220 | |