1// Copyright (C) 2019 The Qt Company Ltd.
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 "qopcuaerrorstate.h"
5
6QT_BEGIN_NAMESPACE
7
8class QOpcUaErrorStateData : public QSharedData
9{
10public:
11 QOpcUaErrorStateData() {}
12
13 QOpcUaErrorState::ConnectionStep m_connectionStep = QOpcUaErrorState::ConnectionStep::CertificateValidation;
14 QOpcUa::UaStatusCode m_errorCode = QOpcUa::Good;
15 bool m_clientSideError = false;
16 bool m_ignoreError = false;
17};
18
19/*!
20 \class QOpcUaErrorState
21 \inmodule QtOpcUa
22 \since QtOpcUa 5.13
23 \brief QOpcUaErrorState allows investigation and interaction with error state from backends.
24
25 There is not need to instantiate this class in your code.
26 A client will emit an error state via \l QOpcUaClient::connectError in case an error has happened
27 while establishing a connection.
28
29 The error can be caused by the backend itself or by the server rejecting the connection.
30 If case of errors issued by the local backend, they can be ignored by calling the function
31 \l setIgnoreError().
32*/
33
34/*!
35 \enum QOpcUaErrorState::ConnectionStep
36
37 Specifies at which step during the connection establishment the error occurred.
38
39 \value Unknown The connection step is unknown.
40 \value CertificateValidation Error happened in the certificate validation step.
41 \value OpenSecureChannel Error happened when opening the secure channel.
42 \value CreateSession Error happened when creating the session.
43 \value ActivateSession Error happened during session acivation.
44*/
45
46QOpcUaErrorState::QOpcUaErrorState()
47 : data(new QOpcUaErrorStateData())
48{
49}
50
51/*!
52 Constructs an error state from \a other.
53*/
54QOpcUaErrorState::QOpcUaErrorState(const QOpcUaErrorState &other)
55 : data(other.data)
56{}
57
58/*!
59 Sets the values of \a rhs in this error state.
60*/
61QOpcUaErrorState &QOpcUaErrorState::operator=(const QOpcUaErrorState &rhs)
62{
63 if (this != &rhs)
64 data = rhs.data;
65 return *this;
66}
67
68QOpcUaErrorState::~QOpcUaErrorState()
69{
70
71}
72
73/*!
74 Returns the connection step in which the error occurred.
75*/
76QOpcUaErrorState::ConnectionStep QOpcUaErrorState::connectionStep() const
77{
78 return data->m_connectionStep;
79}
80
81/*!
82 Sets the connection step in which the error occurred to \a step.
83*/
84void QOpcUaErrorState::setConnectionStep(QOpcUaErrorState::ConnectionStep step)
85{
86 data->m_connectionStep = step;
87}
88
89/*!
90 Returns the OPC UA status code of the error occurred.
91*/
92QOpcUa::UaStatusCode QOpcUaErrorState::errorCode() const
93{
94 return data->m_errorCode;
95}
96
97/*!
98 Sets the OPC UA status code of the error occurred to \a error.
99*/
100void QOpcUaErrorState::setErrorCode(QOpcUa::UaStatusCode error)
101{
102 data->m_errorCode = error;
103}
104
105/*!
106 Returns if the occurred error is a client side error.
107*/
108bool QOpcUaErrorState::isClientSideError() const
109{
110 return data->m_clientSideError;
111}
112
113/*!
114 Sets if the occurred error is a client side error to \a clientSideError.
115*/
116void QOpcUaErrorState::setClientSideError(bool clientSideError)
117{
118 data->m_clientSideError = clientSideError;
119}
120
121/*!
122 Sets if this client side error should be ignored to \a ignore.
123
124 Setting this flag does only work if the error is actually a client side error.
125*/
126void QOpcUaErrorState::setIgnoreError(bool ignore)
127{
128 data->m_ignoreError = ignore;
129}
130
131/*!
132 Returns if this client side error should be ignored.
133*/
134bool QOpcUaErrorState::ignoreError() const
135{
136 return data->m_ignoreError;
137}
138
139QT_END_NAMESPACE
140

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