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