1 | // Copyright (C) 2019 The Qt Company Ltd. |
---|---|
2 | // Copyright (C) 2018 Unified Automation GmbH |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
4 | |
5 | #include "qopcuaapplicationidentity.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | /*! |
10 | \class QOpcUaApplicationIdentity |
11 | \inmodule QtOpcUa |
12 | \since QtOpcUa 5.13 |
13 | \brief QOpcUaApplicationIdentity defines the identity of the application. |
14 | |
15 | This info must be configured using \l QOpcUaClient::setApplicationIdentity. |
16 | The application identity can be set up manually or derived from a certificate. |
17 | |
18 | \code |
19 | QOpcUaApplicationIdentity identity; |
20 | |
21 | const QString applicationUri = QStringLiteral("urn:%1:%2:%3") |
22 | .arg(QHostInfo::localHostName()) |
23 | .arg(QCoreApplication::organizationName()) |
24 | .arg(QCoreApplication::applicationName()); |
25 | const QString productUri = QStringLiteral("urn:%1:%2") |
26 | .arg(QCoreApplication::organizationName()) |
27 | .arg(QCoreApplication::applicationName()); |
28 | |
29 | identity.setProductUri(productUri); |
30 | identity.setApplicationUri(applicationUri); |
31 | identity.setApplicationName(QCoreApplication::applicationName()); |
32 | identity.setApplicationType(QOpcUaApplicationDescription::Client); |
33 | |
34 | client->setApplicationIdentity(identity); |
35 | \endcode |
36 | |
37 | In case your application authenticates using certificates the application identity has to match |
38 | the used certificate. In this case all information is extracted from the certificate given in the |
39 | PKI configuration. |
40 | |
41 | \code |
42 | QOpcUaApplicationIdentity identity; |
43 | identity = pkiConfig.applicationIdentity(); |
44 | \endcode |
45 | */ |
46 | |
47 | class QOpcUaApplicationIdentityData : public QSharedData |
48 | { |
49 | public: |
50 | QOpcUaApplicationIdentityData() {} |
51 | |
52 | QOpcUaApplicationDescription::ApplicationType m_applicationType |
53 | {QOpcUaApplicationDescription::ApplicationType::Client}; |
54 | QString m_applicationUri; |
55 | QString m_applicationName; |
56 | QString m_productUri; |
57 | }; |
58 | |
59 | QOpcUaApplicationIdentity::QOpcUaApplicationIdentity() |
60 | : data(new QOpcUaApplicationIdentityData()) |
61 | {} |
62 | |
63 | QOpcUaApplicationIdentity::~QOpcUaApplicationIdentity() |
64 | {} |
65 | |
66 | /*! |
67 | Constructs an application identity from \a other. |
68 | */ |
69 | QOpcUaApplicationIdentity::QOpcUaApplicationIdentity(const QOpcUaApplicationIdentity &other) |
70 | : data(other.data) |
71 | {} |
72 | |
73 | /*! |
74 | Sets the values of \a rhs in this \l QOpcUaApplicationIdentity. |
75 | */ |
76 | QOpcUaApplicationIdentity &QOpcUaApplicationIdentity::operator=(const QOpcUaApplicationIdentity &rhs) |
77 | { |
78 | if (this != &rhs) |
79 | data.operator=(o: rhs.data); |
80 | return *this; |
81 | } |
82 | |
83 | /*! |
84 | Returns the application's application URI. |
85 | |
86 | This must be unique for each installation instance of the application and must match the ApplicationURI |
87 | in the application's certificate. |
88 | */ |
89 | QString QOpcUaApplicationIdentity::applicationUri() const |
90 | { |
91 | return data->m_applicationUri; |
92 | } |
93 | |
94 | /*! |
95 | Sets the applicationUri to \a value. |
96 | |
97 | \sa setApplicationName() |
98 | */ |
99 | void QOpcUaApplicationIdentity::setApplicationUri(const QString &value) |
100 | { |
101 | data->m_applicationUri = value; |
102 | } |
103 | |
104 | /*! |
105 | Returns the human readable name of the application. |
106 | This does not need to be unique. |
107 | */ |
108 | QString QOpcUaApplicationIdentity::applicationName() const |
109 | { |
110 | return data->m_applicationName; |
111 | } |
112 | |
113 | /*! |
114 | Sets the application name to \a value. |
115 | */ |
116 | void QOpcUaApplicationIdentity::setApplicationName(const QString &value) |
117 | { |
118 | data->m_applicationName = value; |
119 | } |
120 | |
121 | /*! |
122 | Returns the application's productUri. |
123 | |
124 | This uniquely identifies the product. |
125 | */ |
126 | QString QOpcUaApplicationIdentity::productUri() const |
127 | { |
128 | return data->m_productUri; |
129 | } |
130 | |
131 | /*! |
132 | Sets the productUri to \a value. |
133 | */ |
134 | void QOpcUaApplicationIdentity::setProductUri(const QString &value) |
135 | { |
136 | data->m_productUri = value; |
137 | } |
138 | |
139 | /*! |
140 | Returns the application's type. |
141 | */ |
142 | QOpcUaApplicationDescription::ApplicationType QOpcUaApplicationIdentity::applicationType() const |
143 | { |
144 | return data->m_applicationType; |
145 | } |
146 | |
147 | /*! |
148 | Sets the type of the application. |
149 | Client applications should set \a value to \l {QOpcUaApplicationDescription::Client}{Client}. |
150 | |
151 | The default value is \l{QOpcUaApplicationDescription::Client}{Client}. |
152 | */ |
153 | void QOpcUaApplicationIdentity::setApplicationType(QOpcUaApplicationDescription::ApplicationType value) |
154 | { |
155 | data->m_applicationType = value; |
156 | } |
157 | |
158 | /*! |
159 | Returns true if the application identity contains valid data. |
160 | */ |
161 | bool QOpcUaApplicationIdentity::isValid() const |
162 | { |
163 | return !data->m_applicationUri.isEmpty() && |
164 | !data->m_applicationName.isEmpty() && |
165 | !data->m_productUri.isEmpty(); |
166 | } |
167 | |
168 | QT_END_NAMESPACE |
169 |