1// Copyright (C) 2018 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#pragma once
5
6#include <private/opcuanode_p.h>
7#include <private/opcuamethodargument_p.h>
8#include <private/opcuastatus_p.h>
9
10#include <QQmlListProperty>
11#include <QList>
12
13//
14// W A R N I N G
15// -------------
16//
17// This file is not part of the Qt API. It exists purely as an
18// implementation detail. This header file may change from version to
19// version without notice, or even be removed.
20//
21// We mean it.
22//
23
24QT_BEGIN_NAMESPACE
25
26class OpcUaNodeIdType;
27
28class OpcUaMethodNode : public OpcUaNode
29{
30 Q_OBJECT
31 Q_PROPERTY(OpcUaNodeIdType* objectNodeId READ objectNodeId WRITE setObjectNodeId NOTIFY objectNodeIdChanged)
32 Q_PROPERTY(QQmlListProperty<OpcUaMethodArgument> inputArguments READ inputArguments NOTIFY inputArgumentsChanged)
33 Q_PROPERTY(QVariantList outputArguments READ outputArguments NOTIFY outputArgumentsChanged)
34 Q_PROPERTY(OpcUaStatus resultStatus READ resultStatus NOTIFY resultStatusChanged)
35
36 QML_NAMED_ELEMENT(MethodNode)
37 QML_ADDED_IN_VERSION(5, 12)
38
39public:
40 OpcUaMethodNode(QObject *parent = nullptr);
41 OpcUaNodeIdType *objectNodeId() const;
42
43 QQmlListProperty<OpcUaMethodArgument> inputArguments();
44 QVariantList outputArguments();
45 OpcUaStatus resultStatus() const;
46
47public slots:
48 void setObjectNodeId(OpcUaNodeIdType *nodeId);
49 void callMethod();
50
51signals:
52 void objectNodeIdChanged();
53 void inputArgumentsChanged();
54 void outputArgumentsChanged();
55
56 void resultStatusChanged(OpcUaStatus status);
57
58private slots:
59 void handleObjectNodeIdChanged();
60 void handleMethodCallFinished(QString methodNodeId, QVariant result, QOpcUa::UaStatusCode statusCode);
61
62private:
63 void setupNode(const QString &absolutePath) override;
64 bool checkValidity() override;
65
66 static void appendArgument(QQmlListProperty<OpcUaMethodArgument>*, OpcUaMethodArgument *);
67 static qsizetype argumentCount(QQmlListProperty<OpcUaMethodArgument>*);
68 static OpcUaMethodArgument* argument(QQmlListProperty<OpcUaMethodArgument>*, qsizetype);
69 static void clearArguments(QQmlListProperty<OpcUaMethodArgument>*);
70
71private:
72 OpcUaNodeIdType *m_objectNodeId = nullptr;
73 OpcUaNode *m_objectNode = nullptr;
74 QList<OpcUaMethodArgument*> m_inputArguments;
75 QVariantList m_outputArguments;
76 OpcUaStatus m_resultStatus;
77};
78
79QT_END_NAMESPACE
80

source code of qtopcua/src/declarative_opcua/opcuamethodnode_p.h