1// Copyright (C) 2017 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 <private/qopcuabackend_p.h>
5
6QT_BEGIN_NAMESPACE
7
8QOpcUaBackend::QOpcUaBackend()
9 : QObject()
10{}
11
12QOpcUaBackend::~QOpcUaBackend()
13{}
14
15// All attributes except Value have a fixed type.
16// A mapping between attribute id and type can be used to simplify the API for writing multiple attributes at once.
17QOpcUa::Types QOpcUaBackend::attributeIdToTypeId(QOpcUa::NodeAttribute attr)
18{
19 switch (attr) {
20 case QOpcUa::NodeAttribute::NodeId:
21 case QOpcUa::NodeAttribute::DataType:
22 return QOpcUa::Types::NodeId;
23// case QOpcUa::NodeAttribute::NodeClass: TODO: Add support for the NodeClass type
24// return QOpcUa::Types::NodeClass;
25 case QOpcUa::NodeAttribute::BrowseName:
26 return QOpcUa::Types::QualifiedName;
27 case QOpcUa::NodeAttribute::DisplayName:
28 case QOpcUa::NodeAttribute::Description:
29 case QOpcUa::NodeAttribute::InverseName:
30 return QOpcUa::Types::LocalizedText;
31 case QOpcUa::NodeAttribute::WriteMask:
32 case QOpcUa::NodeAttribute::UserWriteMask:
33 case QOpcUa::NodeAttribute::ValueRank:
34 case QOpcUa::NodeAttribute::ArrayDimensions:
35 return QOpcUa::Types::UInt32;
36 case QOpcUa::NodeAttribute::IsAbstract:
37 case QOpcUa::NodeAttribute::Symmetric:
38 case QOpcUa::NodeAttribute::ContainsNoLoops:
39 case QOpcUa::NodeAttribute::Historizing:
40 case QOpcUa::NodeAttribute::Executable:
41 case QOpcUa::NodeAttribute::UserExecutable:
42 return QOpcUa::Types::Boolean;
43 case QOpcUa::NodeAttribute::EventNotifier:
44 case QOpcUa::NodeAttribute::AccessLevel:
45 case QOpcUa::NodeAttribute::UserAccessLevel:
46 return QOpcUa::Types::Byte;
47 case QOpcUa::NodeAttribute::MinimumSamplingInterval:
48 return QOpcUa::Types::Double;
49 default:
50 return QOpcUa::Types::Undefined;
51 }
52}
53
54double QOpcUaBackend::revisePublishingInterval(double requestedValue, double minimumValue)
55{
56 return (std::max)(a: requestedValue, b: minimumValue);
57}
58
59/*!
60 This function returns if a given endpoint description is valid.
61 If \a message is not \nullptr, an error message will be assigned to it, in case
62 the endpoint description is invalid.
63 */
64bool QOpcUaBackend::verifyEndpointDescription(const QOpcUaEndpointDescription &endpoint, QString *message)
65{
66 if (endpoint.endpointUrl().isEmpty()) {
67 if (message)
68 *message = QLatin1String("Endpoint description is invalid because endpoint URL is empty");
69 return false;
70 }
71
72 if (endpoint.securityPolicy().isEmpty()) {
73 if (message)
74 *message = QLatin1String("Endpoint description is invalid because security policy is empty");
75 return false;
76 }
77
78 if (endpoint.securityMode() != QOpcUaEndpointDescription::MessageSecurityMode::None &&
79 endpoint.securityMode() != QOpcUaEndpointDescription::MessageSecurityMode::Sign &&
80 endpoint.securityMode() != QOpcUaEndpointDescription::MessageSecurityMode::SignAndEncrypt)
81 {
82 if (message)
83 *message = QLatin1String("Endpoint description contains an invalid message security mode");
84 return false;
85 }
86
87 return true;
88}
89
90QT_END_NAMESPACE
91

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