| 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 |  | 
| 6 | QT_BEGIN_NAMESPACE | 
| 7 |  | 
| 8 | class QOpcUaErrorStateData : public QSharedData | 
| 9 | { | 
| 10 | public: | 
| 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 |  | 
| 46 | /*! | 
| 47 |     Default constructs an error state with no parameters set. | 
| 48 | */ | 
| 49 | QOpcUaErrorState::QOpcUaErrorState() | 
| 50 |     : data(new QOpcUaErrorStateData()) | 
| 51 | { | 
| 52 | } | 
| 53 |  | 
| 54 | /*! | 
| 55 |     Constructs an error state from \a other. | 
| 56 | */ | 
| 57 | QOpcUaErrorState::QOpcUaErrorState(const QOpcUaErrorState &other) | 
| 58 |     : data(other.data) | 
| 59 | {} | 
| 60 |  | 
| 61 | /*! | 
| 62 |     Sets the values of \a rhs in this error state. | 
| 63 | */ | 
| 64 | QOpcUaErrorState &QOpcUaErrorState::operator=(const QOpcUaErrorState &rhs) | 
| 65 | { | 
| 66 |     if (this != &rhs) | 
| 67 |         data = rhs.data; | 
| 68 |     return *this; | 
| 69 | } | 
| 70 |  | 
| 71 | QOpcUaErrorState::~QOpcUaErrorState() | 
| 72 | { | 
| 73 |  | 
| 74 | } | 
| 75 |  | 
| 76 | /*! | 
| 77 |     Returns the connection step in which the error occurred. | 
| 78 | */ | 
| 79 | QOpcUaErrorState::ConnectionStep QOpcUaErrorState::connectionStep() const | 
| 80 | { | 
| 81 |     return data->m_connectionStep; | 
| 82 | } | 
| 83 |  | 
| 84 | /*! | 
| 85 |     Sets the connection step in which the error occurred to \a step. | 
| 86 | */ | 
| 87 | void QOpcUaErrorState::setConnectionStep(QOpcUaErrorState::ConnectionStep step) | 
| 88 | { | 
| 89 |     data->m_connectionStep = step; | 
| 90 | } | 
| 91 |  | 
| 92 | /*! | 
| 93 |     Returns the OPC UA status code of the error occurred. | 
| 94 | */ | 
| 95 | QOpcUa::UaStatusCode QOpcUaErrorState::errorCode() const | 
| 96 | { | 
| 97 |     return data->m_errorCode; | 
| 98 | } | 
| 99 |  | 
| 100 | /*! | 
| 101 |     Sets the OPC UA status code of the error occurred to \a error. | 
| 102 | */ | 
| 103 | void QOpcUaErrorState::setErrorCode(QOpcUa::UaStatusCode error) | 
| 104 | { | 
| 105 |     data->m_errorCode = error; | 
| 106 | } | 
| 107 |  | 
| 108 | /*! | 
| 109 |     Returns if the occurred error is a client side error. | 
| 110 | */ | 
| 111 | bool QOpcUaErrorState::isClientSideError() const | 
| 112 | { | 
| 113 |     return data->m_clientSideError; | 
| 114 | } | 
| 115 |  | 
| 116 | /*! | 
| 117 |     Sets if the occurred error is a client side error to \a clientSideError. | 
| 118 | */ | 
| 119 | void QOpcUaErrorState::setClientSideError(bool clientSideError) | 
| 120 | { | 
| 121 |     data->m_clientSideError = clientSideError; | 
| 122 | } | 
| 123 |  | 
| 124 | /*! | 
| 125 |     Sets if this client side error should be ignored to \a ignore. | 
| 126 |  | 
| 127 |     Setting this flag does only work if the error is actually a client side error. | 
| 128 | */ | 
| 129 | void QOpcUaErrorState::setIgnoreError(bool ignore) | 
| 130 | { | 
| 131 |     data->m_ignoreError = ignore; | 
| 132 | } | 
| 133 |  | 
| 134 | /*! | 
| 135 |     Returns if this client side error should be ignored. | 
| 136 | */ | 
| 137 | bool QOpcUaErrorState::ignoreError() const | 
| 138 | { | 
| 139 |     return data->m_ignoreError; | 
| 140 | } | 
| 141 |  | 
| 142 | QT_END_NAMESPACE | 
| 143 |  |