summaryrefslogtreecommitdiffstats
path: root/src/opcua/client/qopcuaclient.cpp
blob: f484df75483fddfe69a06113ee1dabaf7e6c4e4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
/****************************************************************************
**
** Copyright (C) 2015 basysKom GmbH, opensource@basyskom.com
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtOpcUa module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qopcuaclient.h"
#include <private/qopcuaclient_p.h>

#include <QtCore/qloggingcategory.h>

QT_BEGIN_NAMESPACE

Q_DECLARE_LOGGING_CATEGORY(QT_OPCUA)

/*!
    \class QOpcUaClient
    \inmodule QtOpcUa

    \brief QOpcUaClient allows interaction with an OPC UA server.

    \section1 QOpcUaClient

    QOpcUaClient implements basic client capabilities to communicate with
    OPC UA enabled devices and applications. This includes querying a discovery server
    for known servers, requesting a list of endpoints from a server, connecting and
    disconnecting.

    After successfully connecting to a server, QOpcUaClient allows getting \l QOpcUaNode
    objects which enable further interaction with nodes on the OPC UA server.
    For operations that concern multiple nodes, QOpcUaClient offers a batch API which supports
    reading multiple attributes of multiple nodes in a single request to the server.

    QOpcUaClient also keeps a local copy of the server's namespace array which is created after
    a successful connect. This information can be queried or updated while the connection lasts.
    The copy of the namespace array is also used for the resolution of expanded node ids and the
    creation of qualified names from a namespace URI.

    \section1 Addressing Nodes

    For an introduction to nodes and node ids, see \l QOpcUaNode.

    \section1 Usage
    Create a \l QOpcUaClient using \l QOpcUaProvider and call \l connectToEndpoint() to connect to a server.
    After the connection is established, a \l QOpcUaNode object for the root node is requested.
    \code
    QOpcUaProvider provider;
    if (provider.availableBackends().isEmpty())
        return;
    QOpcUaClient *client = provider.createClient(provider.availableBackends()[0]);
    if (!client)
        return;
    // Connect to the stateChanged signal. Compatible slots of QObjects can be used instead of a lambda.
    QObject::connect(client, &QOpcUaClient::stateChanged, [client](QOpcUaClient::ClientState state) {
        qDebug() << "Client state changed:" << state;
        if (state == QOpcUaClient::ClientState::Connected) {
            QOpcUaNode *node = client->node("ns=0;i=84");
            if (node)
                qDebug() << "A node object has been created";
        }
    });
    client->connectToEndpoint(QUrl("opc.tcp://127.0.0.1:4840")); // Connect the client to the server
    \endcode
*/

/*!
    \enum QOpcUaClient::ClientState

    This enum type specifies the connection state of the client.

    \value Disconnected
           The client is not connected to a server.
    \value Connecting
           The client is currently connecting to a server.
    \value Connected
           The client is connected to a server.
    \value Closing
           The client has been connected and requests a disconnect from the server.
*/

/*!
    \enum QOpcUaClient::ClientError

    This enum type specifies the current error state of the client.

    \value NoError
           No error occurred.
    \value InvalidUrl
           The url to connect to has been wrongly specified or a connection to this url failed.
    \value AccessDenied
           An attempt to connect to a server using username/password failed due to wrong credentials.
    \value ConnectionError
           An error occurred with the connection.
    \value UnknownError
           An unknown error occurred.
*/

/*!
    \property QOpcUaClient::error
    \brief Specifies the current error state of the client.
*/

/*!
    \property QOpcUaClient::state
    \brief Specifies the current connection state of the client.
*/

/*!
    \fn QOpcUaClient::connected()

    This signal is emitted when a connection has been established.
*/

/*!
    \fn QOpcUaClient::disconnected()

    This signal is emitted when a connection has been closed following to a close request.
*/

/*!
    \fn void QOpcUaClient::namespaceArrayUpdated(QStringList namespaces)

    This signal is emitted after an updateNamespaceArray operation has finished.
    \a namespaces contains the content of the server's namespace table. The index
    of an entry in \a namespaces corresponds to the namespace index used in the node id.

    If the namespace array content stays the same after the update this signal is emitted nevertheless.

    \sa namespaceArrayChanged() updateNamespaceArray()
*/

/*!
    \fn void QOpcUaClient::namespaceArrayChanged(QStringList namespaces)

    This signal is emitted after the namespace array has changed.
    \a namespaces contains the content of the server's namespace table. The index
    of an entry in \a namespaces corresponds to the namespace index used in the node id.

    \sa namespaceArrayUpdated() updateNamespaceArray()
*/

/*!
    \fn void QOpcUaClient::endpointsRequestFinished(QVector<QOpcUa::QEndpointDescription> endpoints, QOpcUa::UaStatusCode statusCode)

    This signal is emitted after a \l requestEndpoints() operation has finished.
    \a statusCode contains the result of the operation. If the result is \l {QOpcUa::UaStatusCode} {Good},
    \a endpoints contains the descriptions of all endpoints that are available on the server.
*/

/*!
    \fn void QOpcUaClient::findServersFinished(QVector<QOpcUa::QApplicationDescription> servers, QOpcUa::UaStatusCode statusCode);

    This signal is emitted after a \l findServers() operation has finished.
    \a statusCode contains the result of the operation. If the result is \l {QOpcUa::UaStatusCode} {Good},
    \a servers contains the application descriptions of all servers known to the queried server that matched the filter criteria.
*/

/*!
    \fn void QOpcUaClient::batchReadFinished(QVector<QOpcUaReadResult> results, QOpcUa::UaStatusCode serviceResult)

    This signal is emitted after a \l batchRead() operation has finished.

    The elements in \a results have the same order as the elements in the request. For each requested element,
    there is a value together with timestamps and the status code in \a results.
    \a serviceResult contains the status code from the OPC UA Read service.

    \sa batchRead() QOpcUaReadResult QOpcUaReadItem
*/

/*!
    \fn void QOpcUaClient::batchWriteFinished(QVector<QOpcUaWriteResult> results, QOpcUa::UaStatusCode serviceResult)

    This signal is emitted after a \l batchWrite() operation has finished.

    The elements in \a results have the same order as the elements in the batch write request.
    They contain the value, timestamps and status code received from the server as well as the node id,
    attribute and index range from the write item. This facilitates matching the result with the request.

    \a serviceResult is the status code from the the OPC UA Write service. If \a serviceResult is not
    \l {QOpcUa::UaStatusCode} {Good}, the entries in \a results also have an invalid status code and must
    not be used.

    \sa batchWrite() QOpcUaWriteResult
*/

/*!
    \fn void QOpcUaClient::addNodeFinished(QOpcUa::QExpandedNodeId requestedNodeId, QString assignedNodeId, QOpcUa::UaStatusCode statusCode)

    This signal is emitted after an \l addNode() operation has finished.
    \a requestedNodeId is the requested node id from the \l addNode() call, \a assignedNodeId is the node id the server has assigned to the new node.
    \a statusCode contains the result of the operation. If the result is \l {QOpcUa::UaStatusCode} {Bad}, \a assignedNodeId is empty and no node
    has been added to the server's address space.
*/

/*!
    \fn void QOpcUaClient::deleteNodeFinished(QString nodeId, QOpcUa::UaStatusCode statusCode)

    This signal is emitted after a \l deleteNode() operation has finished.
    \a nodeId is the node id from the \l deleteNode() call.
    \a statusCode contains the result of the operation.
*/

/*!
    \fn void QOpcUaClient::addReferenceFinished(QString sourceNodeId, QString referenceTypeId, QOpcUa::QExpandedNodeId targetNodeId, bool isForward, QOpcUa::UaStatusCode statusCode)

    This signal is emitted after an \l addReference() operation has finished.
    \a sourceNodeId, \a referenceTypeId, \a targetNodeId and \a isForward are the values from the \l addReference() call.
    \a statusCode contains the result of the operation.
*/

/*!
    \fn void QOpcUaClient::deleteReferenceFinished(QString sourceNodeId, QString referenceTypeId, QOpcUa::QExpandedNodeId targetNodeId, bool isForward, QOpcUa::UaStatusCode statusCode)

    This signal is emitted after a \l deleteReference() operation has finished.
    \a sourceNodeId, \a referenceTypeId, \a targetNodeId and \a isForward are the values from the \l deleteReference() call.
    \a statusCode contains the result of the operation.
*/

/*!
    \internal QOpcUaClientImpl is an opaque type (as seen from the public API).
    This prevents users of the public API to use this constructor (eventhough
    it is public).
*/
QOpcUaClient::QOpcUaClient(QOpcUaClientImpl *impl, QObject *parent)
    : QObject(*(new QOpcUaClientPrivate(impl)), parent)
{
    impl->m_client = this;
}

/*!
    Destroys the \l QOpcUaClient instance.
*/
QOpcUaClient::~QOpcUaClient()
{
}

/*!
    Connects to the OPC UA endpoint given in \a url.

    If the endpoint requires username and password, they must be included in \a url.

    \code
    QUrl url("opc.tcp://localhost:4840");
    url.setUserName("user");
    url.setPassword("password");

    m_client->connectToEndpoint(url);
    \endcode

    \sa disconnectFromEndpoint()
*/
void QOpcUaClient::connectToEndpoint(const QUrl &url)
{
    Q_D(QOpcUaClient);
    d->connectToEndpoint(url);
}

/*!
    Disconnects from the server.
    \sa connectToEndpoint()
*/
void QOpcUaClient::disconnectFromEndpoint()
{
    Q_D(QOpcUaClient);
    d->disconnectFromEndpoint();
}

/*!
    Returns the URL of the OPC UA server the client is currently connected to
    or was last connected to.
*/
QUrl QOpcUaClient::url() const
{
    Q_D(const QOpcUaClient);
    return d->m_url;
}

QOpcUaClient::ClientState QOpcUaClient::state() const
{
    Q_D(const QOpcUaClient);
    return d->m_state;
}

/*!
    Returns the current error state of the client.
*/
QOpcUaClient::ClientError QOpcUaClient::error() const
{
    Q_D(const QOpcUaClient);
    return d->m_error;
}

/*!
    Returns a \l QOpcUaNode object associated with the OPC UA node identified
    by \a nodeId. The caller becomes owner of the node object.

    If the client is not connected, \c nullptr is returned. The backends may also
    return \c nullptr for other error cases (for example for a malformed node id).
*/
QOpcUaNode *QOpcUaClient::node(const QString &nodeId)
{
    if (state() != QOpcUaClient::Connected)
       return nullptr;

    Q_D(QOpcUaClient);
    return d->m_impl->node(nodeId);
}

/*!
    Returns a \l QOpcUaNode object associated with the OPC UA node identified
    by \a expandedNodeId. The caller becomes owner of the node object.

    If the node is not on the currently connected server, the namespace can't be resolved,
    the node id is malformed or the client is not connected, \c nullptr is returned.

    \sa updateNamespaceArray()
*/
QOpcUaNode *QOpcUaClient::node(const QOpcUa::QExpandedNodeId &expandedNodeId)
{
    if (expandedNodeId.serverIndex()) {
        qCWarning(QT_OPCUA) << "Can't create a QOpcuaNode for a node on a different server.";
        return nullptr;
    }

    const QString nodeId = resolveExpandedNodeId(expandedNodeId);

    if (!nodeId.isEmpty())
        return node(nodeId);
    else
        return nullptr;
}

/*!
    Requests an update of the namespace array from the server.
    Returns \c true if the operation has been successfully dispatched.

    The \l namespaceArrayUpdated() signal is emitted after the operation is finished.

    \sa namespaceArray() namespaceArrayUpdated()
*/
bool QOpcUaClient::updateNamespaceArray()
{
    if (state() != QOpcUaClient::Connected)
       return false;

    Q_D(QOpcUaClient);
    return d->updateNamespaceArray();
}

/*!
    Returns the cached value of the namespace array.

    The value is only valid after the \l namespaceArrayUpdated() signal has been emitted.

    \sa updateNamespaceArray() namespaceArrayUpdated()
*/
QStringList QOpcUaClient::namespaceArray() const
{
    Q_D(const QOpcUaClient);
    return d->namespaceArray();
}

/*!
    Attempts to resolve \a expandedNodeId to a node id string with numeric namespace index.
    Returns the node id string if the conversion was successful.

    An empty string is returned if the namespace index can't be resolved or if the identifier part
    of the expanded node id is malformed. \a ok will be set to \c true if the conversion has been successful.
    If the expanded node id could not be resolved, \a ok will be set to \c false.
*/
QString QOpcUaClient::resolveExpandedNodeId(const QOpcUa::QExpandedNodeId &expandedNodeId, bool *ok) const
{
    if (expandedNodeId.serverIndex() && !expandedNodeId.namespaceUri().isEmpty()) {
        qCWarning(QT_OPCUA) << "Can't resolve a namespace index on a different server.";
        if (ok)
            *ok = false;
        return QString();
    }

    if (expandedNodeId.namespaceUri().isEmpty()) {
        if (ok)
            *ok = true;
        return expandedNodeId.nodeId();
    } else {
        if (!namespaceArray().size()) {
            qCWarning(QT_OPCUA) << "Namespaces table missing, unable to resolve namespace URI.";
            if (ok)
                *ok = false;
            return QString();
        }

        int index = namespaceArray().indexOf(expandedNodeId.namespaceUri());

        if (index < 0) {
            qCWarning(QT_OPCUA) << "Failed to resolve namespace" << expandedNodeId.namespaceUri();
            if (ok)
                *ok = false;
            return QString();
        }

        QStringList splitId = expandedNodeId.nodeId().split(QLatin1String(";"));
        if (splitId.size() != 2) {
            qCWarning(QT_OPCUA) << "Failed to split node id" << expandedNodeId.nodeId();
            if (ok)
                *ok = false;
            return QString();
        }

        if (ok)
            *ok = true;
        return QStringLiteral("ns=%1;").arg(index).append(splitId.at(1));
    }
}

/*!
    Attempts to create a qualified name from \a namespaceUri and the name string \a name.
    Returns the resulting qualified name. An empty qualified name is returned if
    \a namespaceUri can't be resolved.

    \a ok will be set to \c true if the namespace URI resolution has been successful.
    If the namespace URI could not be resolved, \a ok will be set to \c false.
*/
QOpcUa::QQualifiedName QOpcUaClient::qualifiedNameFromNamespaceUri(const QString &namespaceUri, const QString &name, bool *ok) const
{
    if (namespaceArray().isEmpty()) {
        qCWarning(QT_OPCUA) << "Namespaces table missing, unable to resolve namespace URI.";
        if (ok)
            *ok = false;
        return QOpcUa::QQualifiedName();
    }

    int index = namespaceArray().indexOf(namespaceUri);

    if (index < 0) {
        qCWarning(QT_OPCUA) << "Failed to resolve namespace" << namespaceUri;
        if (ok)
            *ok = false;
        return QOpcUa::QQualifiedName();
    }

    if (ok)
        *ok = true;

    return QOpcUa::QQualifiedName(index, name);
};

/*!
    Adds the node described by \a nodeToAdd on the server.

    Returns \c true if the asynchronous call has been successfully dispatched.

    The success of the operation is returned in the \l addNodeFinished() signal.

    The following example code adds new a Variable node on the server:

    \code
    QOpcUaNodeCreationAttributes attributes;
    attributes.setDisplayName(QOpcUa::QLocalizedText("en", "My new Variable node"));
    attributes.setDescription(QOpcUa::QLocalizedText("en", "A node which has been added at runtime"));
    attributes.setValue(23.0, QOpcUa::Types::Double);
    attributes.setDataTypeId(QOpcUa::ns0ID(QOpcUa::NodeIds::NS0::Double));
    attributes.setValueRank(-2); // Scalar or array
    attributes.setAccessLevel(QOpcUa::AccessLevelBit::CurrentRead);
    attributes.setUserAccessLevel(QOpcUa::AccessLevelBit::CurrentRead);

    QOpcUaAddNodeItem item;
    item.setParentNodeId(QOpcUa::QExpandedNodeId("ns=3;s=TestFolder"));
    item.setReferenceTypeId(QOpcUa::nodeIdFromReferenceType(QOpcUa::ReferenceTypeId::Organizes));
    item.setRequestedNewNodeId(QOpcUa::QExpandedNodeId("ns=3;s=MyNewVariableNode"));
    item.setBrowseName(QOpcUa::QQualifiedName(3, "MyNewVariableNode"));
    item.setNodeClass(QOpcUa::NodeClass::Variable);
    item.setNodeAttributes(attributes);

    m_client->addNode(item);
    \endcode

    \sa deleteNode() addNodeFinished() QOpcUaAddNodeItem
*/
bool QOpcUaClient::addNode(const QOpcUaAddNodeItem &nodeToAdd)
{
    if (state() != QOpcUaClient::Connected)
       return false;

    Q_D(QOpcUaClient);
    return d->m_impl->addNode(nodeToAdd);
}

/*!
    Deletes the node with node id \a nodeId from the server.
    If \a deleteTargetReferences is \c false, only the references with source node \a nodeId are deleted.
    If \a deleteTargetReferences is \c true, references with \a nodeId as target are deleted too.

    Returns \c true if the asynchronous call has been successfully dispatched.

    The success of the operation is returned in the \l deleteNodeFinished() signal.

    The following example code deletes a node and all references to it from the server:

    \code
    m_client->deleteNode(QOpcUa::QExpandedNodeId("ns=3;s=MyNewVariableNode"), true);
    \endcode

    \sa addNode() deleteNodeFinished()
*/
bool QOpcUaClient::deleteNode(const QString &nodeId, bool deleteTargetReferences)
{
    if (state() != QOpcUaClient::Connected)
       return false;

    Q_D(QOpcUaClient);
    return d->m_impl->deleteNode(nodeId, deleteTargetReferences);
}

/*!
    Adds the reference described by \a referenceToAdd to the server.

    Returns \c true if the asynchronous call has been successfully dispatched.

    The success of the operation is returned in the \l addReferenceFinished() signal.

    The following example code adds a reference to a node to the "Objects" folder:

    \code
    QOpcUaAddReferenceItem item;
    item.setSourceNodeId(QOpcUa::ns0ID(QOpcUa::NodeIds::NS0::ObjectsFolder));
    item.setReferenceTypeId(QOpcUa::nodeIdFromInteger(0, static_cast<quint32>(QOpcUa::ReferenceTypeId::Organizes)));
    item.setIsForward(true);
    item.setTargetNodeId(QOpcUa::QExpandedNodeId("ns=3;s=MyNewVariableNode"));
    item.setTargetNodeClass(QOpcUa::NodeClass::Variable);

    m_client->addReference(item);
    \endcode

    \sa deleteReference() addReferenceFinished() QOpcUaAddReferenceItem
*/
bool QOpcUaClient::addReference(const QOpcUaAddReferenceItem &referenceToAdd)
{
    if (state() != QOpcUaClient::Connected)
       return false;

    Q_D(QOpcUaClient);
    return d->m_impl->addReference(referenceToAdd);
}

/*!
    Deletes the reference described by \a referenceToDelete from the server.

    Returns \c true if the asynchronous call has been successfully dispatched.

    The success of the operation is returned in the \l deleteReferenceFinished() signal.

    The following example code deletes a reference to a node from the "Objects" folder:

    \code
    QOpcUaDeleteReferenceItem item;
    item.setSourceNodeId(QOpcUa::ns0ID(QOpcUa::NodeIds::NS0::ObjectsFolder));
    item.setReferenceTypeId(QOpcUa::nodeIdFromInteger(0, static_cast<quint32>(QOpcUa::ReferenceTypeId::Organizes)));
    item.setIsForward(true);
    item.setTargetNodeId(QOpcUa::QExpandedNodeId("ns=3;s=MyNewVariableNode"));
    item.setDeleteBidirectional(true);

    m_client->deleteReference(item);
    \endcode

    \sa addReference() deleteReferenceFinished() QOpcUaDeleteReferenceItem
*/
bool QOpcUaClient::deleteReference(const QOpcUaDeleteReferenceItem &referenceToDelete)
{
    if (state() != QOpcUaClient::Connected)
       return false;

    Q_D(QOpcUaClient);
    return d->m_impl->deleteReference(referenceToDelete);
}

/*!
    Starts an asynchronous \c GetEndpoints request to read a list of available endpoints
    from the server at \a url.
    Returns \c true if the asynchronous call has been successfully dispatched.

    The endpoint information is returned in the \l endpointsRequestFinished() signal.
*/
bool QOpcUaClient::requestEndpoints(const QUrl &url)
{
    Q_D(QOpcUaClient);
    return d->m_impl->requestEndpoints(url);
}

/*!
    Starts an asynchronous FindServers request to read a list of known servers from a server or
    discovery server at \a url.
    Returns \c true if the asynchronous call has been successfully dispatched.

    \a localeIds can be used to select the language of the application names returned by the request.
    The format is specified in OPC-UA part 3, 8.4, for example "en" for English, or "de-DE" for
    German (Germany). If more than one locale ID is specified, the server uses the first match. If there
    is no match or \a localeIds is empty, a default locale is chosen by the server.

    \a serverUris may be used to restrict the results to servers with a matching applicationUri in their
    application description. For example, finding the current URL of the server with the applicationUri
    "MyPLC", the following call can be used:

    \code
        client->findServers(discoveryServerUrl, QStringList(), QStringList({"MyPLC"}));
    \endcode

    The results are returned in the \l findServersFinished() signal.
*/
bool QOpcUaClient::findServers(const QUrl &url, const QStringList &localeIds, const QStringList &serverUris)
{
    Q_D(QOpcUaClient);
    return d->m_impl->findServers(url, localeIds, serverUris);
}

/*!
    Starts a batch read of multiple attributes on different nodes.
    The node id, the attribute and an index range can be specified for every entry in \a nodesToRead.

    Returns true if the asynchronous request has been successfully dispatched.
    The results are returned in the \l batchReadFinished() signal.

    The batch read API offers an alternative way to read attributes of nodes which can be used
    for scenarios where the values of a large number of node attributes on different nodes must be read
    without requiring the other features of the \l QOpcUaNode based API like monitoring for value changes.
    All read items in the request are sent to the server in a single request and are answered in a single
    response which generates a single \l batchReadFinished() signal. This reduces the network overhead and
    the number of signal slot connections if many different nodes are involved.

    In the following example, the display name attribute and the two index ranges "0:2" and "5:7" of the value
    attribute of the same node and the entire value attribute of a second node are read using a single service call:
    \code
    QVector<QOpcUaReadItem> request;
    request.push_back(QOpcUaReadItem("ns=1;s=MyArrayNode",
                                     QOpcUa::NodeAttribute::DisplayName));
    request.push_back(QOpcUaReadItem("ns=1;s=MyArrayNode",
                                     QOpcUa::NodeAttribute::Value, "0:2"));
    request.push_back(QOpcUaReadItem("ns=1;s=MyArrayNode",
                                     QOpcUa::NodeAttribute::Value, "5:7"));
    request.push_back(QOpcUaReadItem("ns=1;s=MyScalarNode));
    m_client->batchRead(request);
    \endcode

    \sa QOpcUaReadItem batchReadFinished()
*/
bool QOpcUaClient::batchRead(const QVector<QOpcUaReadItem> &nodesToRead)
{
    if (state() != QOpcUaClient::Connected)
       return false;

    Q_D(QOpcUaClient);
    return d->m_impl->batchRead(nodesToRead);
}

/*!
    Starts a batch write for multiple attributes on different nodes.
    The node id, the attribute, the value, the value type and an index range can be specified
    for every entry in \a nodesToWrite.

    Returns \c true if the asynchronous request has been successfully dispatched.
    The results are returned in the \l batchWriteFinished() signal.

    The batch write API offers an alternative way to write attributes of nodes which can be used
    for scenarios where the values of a large number of node attributes on different nodes must be written
    without requiring the other features of the \l QOpcUaNode based API like monitoring for value changes.
    All write items in the request are sent to the server in a single request and are answered in a single
    response which generates a single \l batchWriteFinished() signal. This reduces the network overhead and
    the number of signal slot connections if many different nodes are involved.

    In the following example, the Values attributes of two different nodes are written in one call.
    The second node has an array value of which only the first two elements are overwritten:

    \code
    QVector<QOpcUaWriteItem> request;

    request.append(QOpcUaWriteItem("ns=2;s=Demo.Static.Scalar.Double", QOpcUa::NodeAttribute::Value,
                                      23.0, QOpcUa::Types::Double));
    request.append(QOpcUaWriteItem("ns=2;s=Demo.Static.Arrays.UInt32", QOpcUa::NodeAttribute::Value,
                                      QVariantList({0, 1, 2}), QOpcUa::Types::UInt32, "0:2"));

    m_client->batchWrite(request);
    \endcode

    \sa QOpcUaWriteItem batchWriteFinished()
*/
bool QOpcUaClient::batchWrite(const QVector<QOpcUaWriteItem> &nodesToWrite)
{
    if (state() != QOpcUaClient::Connected)
       return false;

    Q_D(QOpcUaClient);
    return d->m_impl->batchWrite(nodesToWrite);
}

/*!
    Returns the name of the backend used by this instance of QOpcUaClient,
    e.g. "open62541".
*/
QString QOpcUaClient::backend() const
{
    Q_D(const QOpcUaClient);
    return d->m_impl->backend();
}

/*!
    Enables automatic update of the namespace table.

    A subscription will be made to the server node and \l namespaceArrayUpdated will be emitted
    when the array changed without calling \l updateNamespaceArray first.

    \a enable Determines whether to enable or disable the autoupdate functionality.

    \sa namespaceArray() namespaceArrayUpdated()
*/
void QOpcUaClient::setEnableNamespaceAutoupdate(bool enable)
{
    Q_D(QOpcUaClient);
    d->m_enableNamespaceArrayAutoupdate = enable;
    d->setupNamespaceArrayMonitoring();
}

/*!
    Returns whether autoupdate of the namespace array is activated.
*/
bool QOpcUaClient::namespaceAutoupdateEnabled() const
{
    Q_D(const QOpcUaClient);
    return d->m_enableNamespaceArrayAutoupdate;
}

/*!
    Sets the interval for the namespace table subscription.

    The subscription may be revised by the server.

    \a interval determines the interval to check for changes in milliseconds. The default is once per second.

    \sa QOpcUaClient::setEnableNamespaceAutoupdate(bool enable)
*/
void QOpcUaClient::setNamespaceAutoupdateInterval(int interval)
{
    Q_D(QOpcUaClient);
    d->m_namespaceArrayUpdateInterval = interval;
    d->setupNamespaceArrayMonitoring();
}

/*!
    Returns the current revised update inverval of the namespace array.

    \sa setNamespaceAutoupdateInterval(int interval)
*/
int QOpcUaClient::namespaceAutoupdateInterval() const
{
    Q_D(const QOpcUaClient);
    return d->m_namespaceArrayUpdateInterval;
}

QT_END_NAMESPACE