1// Copyright (C) 2017 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#ifndef QOPEN62541UTILS_H
5#define QOPEN62541UTILS_H
6
7#include <QtOpcUa/qopcuamonitoringparameters.h>
8
9#include "qopen62541.h"
10
11#include <QString>
12
13#include <functional>
14
15QT_BEGIN_NAMESPACE
16
17template <typename T>
18class UaDeleter
19{
20public:
21 UaDeleter(T *data, std::function<void(T *value)> f)
22 : m_data(data)
23 , m_function(f)
24 {
25 }
26 ~UaDeleter()
27 {
28 if (m_data)
29 m_function(m_data);
30 }
31 void release()
32 {
33 m_data = nullptr;
34 m_function = nullptr;
35 }
36private:
37 T *m_data {nullptr};
38 std::function<void(T *attribute)> m_function;
39};
40
41template <uint TYPEINDEX>
42class UaArrayDeleter
43{
44public:
45 UaArrayDeleter(void *data, size_t arrayLength)
46 : m_data(data)
47 , m_arrayLength(arrayLength)
48 {
49 static_assert (TYPEINDEX < UA_TYPES_COUNT, "Invalid index outside the UA_TYPES array.");
50 }
51 ~UaArrayDeleter()
52 {
53 if (m_data && m_arrayLength > 0)
54 UA_Array_delete(p: m_data, size: m_arrayLength, type: &UA_TYPES[TYPEINDEX]);
55 }
56 void release() {
57 m_data = nullptr;
58 m_arrayLength = 0;
59 }
60private:
61 void *m_data {nullptr};
62 size_t m_arrayLength {0};
63};
64
65namespace Open62541Utils {
66 UA_NodeId nodeIdFromQString(const QString &name);
67 QString nodeIdToQString(UA_NodeId id);
68
69 void createEventFilter(const QOpcUaMonitoringParameters::EventFilter &filter, UA_ExtensionObject *out);
70
71#ifdef UA_ENABLE_ENCRYPTION
72 bool checkSha1SignatureSupport();
73#endif
74}
75
76QT_END_NAMESPACE
77
78#endif // QOPEN62541UTILS_H
79

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtopcua/src/plugins/opcua/open62541/qopen62541utils.h