open62541pp 0.19.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
nodemanagement.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <functional>
5#include <string_view>
6#include <utility> // exchange, forward
7#include <variant>
8
10#include "open62541pp/common.hpp" // ModellingRule
11#include "open62541pp/config.hpp"
18#include "open62541pp/span.hpp"
19#include "open62541pp/types.hpp"
20#include "open62541pp/ua/nodeids.hpp" // *TypeId
22
23namespace opcua {
24class Client;
25class Session;
26} // namespace opcua
27
28namespace opcua::services {
29
30/**
31 * @defgroup NodeManagement NodeManagement service set
32 * Add/delete nodes and references.
33 *
34 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.8
35 * @ingroup Services
36 * @{
37 */
38
39/**
40 * @defgroup AddNodes AddNodes service
41 * Add nodes into the address space hierarchy.
42 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.8.2
43 * @{
44 */
45
46/**
47 * Add one or more nodes (client only).
48 * @param connection Instance of type Client
49 * @param request Add nodes request
50 */
51AddNodesResponse addNodes(Client& connection, const AddNodesRequest& request) noexcept;
52
53/**
54 * @copydoc addNodes
55 * @param token @completiontoken{void(AddNodesResponse&)}
56 * @return @asyncresult{AddNodesResponse}
57 */
58template <typename CompletionToken>
59auto addNodesAsync(Client& connection, const AddNodesRequest& request, CompletionToken&& token) {
60 return detail::sendRequestAsync<AddNodesRequest, AddNodesResponse>(
61 connection, request, std::forward<CompletionToken>(token)
62 );
63}
64
65/**
66 * Add a node.
67 * @param connection Instance of type Client (or Server)
68 * @param nodeClass Node class
69 * @param parentId Parent node
70 * @param id Requested NodeId of the node to add
71 * @param browseName Browse name
72 * @param nodeAttributes Node attributes
73 * @param typeDefinition NodeId of the type
74 * @param referenceType Hierarchical reference type from the parent node to the new node
75 */
76template <typename T>
78 T& connection,
79 NodeClass nodeClass,
80 const NodeId& parentId,
81 const NodeId& id,
82 std::string_view browseName,
83 const ExtensionObject& nodeAttributes,
84 const NodeId& typeDefinition,
85 const NodeId& referenceType
86) noexcept;
87
88/**
89 * @copydoc addNode
90 * @param token @completiontoken{void(Result<NodeId>&)}
91 * @return @asyncresult{Result<NodeId>}
92 */
93template <typename CompletionToken>
95 Client& connection,
96 NodeClass nodeClass,
97 const NodeId& parentId,
98 const NodeId& id,
99 std::string_view browseName,
100 const ExtensionObject& nodeAttributes,
101 const NodeId& typeDefinition,
102 const NodeId& referenceType,
103 CompletionToken&& token
104) {
105 auto item = detail::makeAddNodesItem(
106 parentId, referenceType, id, browseName, nodeClass, nodeAttributes, typeDefinition
107 );
108 const auto request = detail::makeAddNodesRequest(item);
109 return addNodesAsync(
110 connection,
111 asWrapper<AddNodesRequest>(request),
112 detail::TransformToken(
113 [](UA_AddNodesResponse& response) {
114 return detail::getSingleResultRef(response).andThen(detail::getAddedNodeId);
115 },
116 std::forward<CompletionToken>(token)
117 )
118 );
119}
120
121/**
122 * @}
123 * @defgroup AddReferences AddReferences service
124 * Add references to nodes.
125 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.8.3
126 * @{
127 */
128
129/**
130 * Add one or more references (client only).
131 * @param connection Instance of type Client
132 * @param request Add references request
133 */
135 Client& connection, const AddReferencesRequest& request
136) noexcept;
137
138/**
139 * @copydoc addReferences
140 * @param token @completiontoken{void(AddReferencesResponse&)}
141 * @return @asyncresult{AddReferencesReponse}
142 */
143template <typename CompletionToken>
145 Client& connection, const AddReferencesRequest& request, CompletionToken&& token
146) {
147 return detail::sendRequestAsync<AddReferencesRequest, AddReferencesResponse>(
148 connection, request, std::forward<CompletionToken>(token)
149 );
150}
151
152/**
153 * Add reference.
154 * @param connection Instance of type Client (or Server)
155 * @param sourceId Node to which the reference is to be added
156 * @param targetId Target node
157 * @param referenceType NodeId of the reference type that defines the reference
158 * @param forward Create a forward reference if `true` or a inverse reference if `false`
159 */
160template <typename T>
162 T& connection,
163 const NodeId& sourceId,
164 const NodeId& targetId,
165 const NodeId& referenceType,
166 bool forward
167) noexcept;
168
169/**
170 * @copydoc addReference
171 * @param token @completiontoken{void(StatusCode)}
172 * @return @asyncresult{StatusCode}
173 */
174template <typename CompletionToken>
176 Client& connection,
177 const NodeId& sourceId,
178 const NodeId& targetId,
179 const NodeId& referenceType,
180 bool forward,
181 CompletionToken&& token
182) {
183 auto item = detail::makeAddReferencesItem(sourceId, referenceType, forward, targetId);
184 const auto request = detail::makeAddReferencesRequest(item);
185 return addReferencesAsync(
186 connection,
187 asWrapper<AddReferencesRequest>(request),
188 detail::TransformToken(
189 detail::getSingleStatus<AddReferencesResponse>, std::forward<CompletionToken>(token)
190 )
191 );
192}
193
194/**
195 * @}
196 * @defgroup DeleteNodes DeleteNodes service
197 * Delete nodes from the address space.
198 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.8.4
199 * @{
200 */
201
202/**
203 * Delete one or more nodes (client only).
204 * @param connection Instance of type Client
205 * @param request Delete nodes request
206 */
207DeleteNodesResponse deleteNodes(Client& connection, const DeleteNodesRequest& request) noexcept;
208
209/**
210 * @copydoc deleteNodes
211 * @param token @completiontoken{void(DeleteNodesResponse&)}
212 * @return @asyncresult{DeleteNodesResponse}
213 */
214template <typename CompletionToken>
216 Client& connection, const DeleteNodesRequest& request, CompletionToken&& token
217) {
218 return detail::sendRequestAsync<DeleteNodesRequest, DeleteNodesResponse>(
219 connection, request, std::forward<CompletionToken>(token)
220 );
221}
222
223/**
224 * Delete node.
225 * @param connection Instance of type Client (or Server)
226 * @param id Node to delete
227 * @param deleteReferences Delete references in target nodes that reference the node to delete
228 */
229template <typename T>
230StatusCode deleteNode(T& connection, const NodeId& id, bool deleteReferences) noexcept;
231
232/**
233 * @copydoc deleteNode
234 * @param token @completiontoken{void(StatusCode)}
235 * @return @asyncresult{StatusCode}
236 */
237template <typename CompletionToken>
239 Client& connection, const NodeId& id, bool deleteReferences, CompletionToken&& token
240) {
241 auto item = detail::makeDeleteNodesItem(id, deleteReferences);
242 const auto request = detail::makeDeleteNodesRequest(item);
243 return deleteNodesAsync(
244 connection,
245 asWrapper<DeleteNodesRequest>(request),
246 detail::TransformToken(
247 detail::getSingleStatus<DeleteNodesResponse>, std::forward<CompletionToken>(token)
248 )
249 );
250}
251
252/**
253 * @}
254 * @defgroup DeleteReferences DeleteReferences service
255 * Delete references from nodes.
256 * @see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.8.5
257 * @{
258 */
259
260/**
261 * Delete one or more references (client only).
262 * @param connection Instance of type Client
263 * @param request Delete references request
264 */
266 Client& connection, const DeleteReferencesRequest& request
267) noexcept;
268
269/**
270 * @copydoc deleteReferences
271 * @param token @completiontoken{void(DeleteReferencesResponse&)}
272 * @return @asyncresult{DeleteReferencesResponse}
273 */
274template <typename CompletionToken>
276 Client& connection, const DeleteReferencesRequest& request, CompletionToken&& token
277) {
278 return detail::sendRequestAsync<DeleteReferencesRequest, DeleteReferencesResponse>(
279 connection, request, std::forward<CompletionToken>(token)
280 );
281}
282
283/**
284 * Delete reference.
285 * @param connection Instance of type Client (or Server)
286 * @param sourceId Node that contains the reference to delete
287 * @param targetId Target node of the reference to delete
288 * @param referenceType NodeId of the reference type that defines the reference to delete
289 * @param isForward Delete the forward reference if `true`, delete the inverse reference if `false`
290 * @param deleteBidirectional Delete the specified and opposite reference from the target node
291 */
292template <typename T>
294 T& connection,
295 const NodeId& sourceId,
296 const NodeId& targetId,
297 const NodeId& referenceType,
298 bool isForward,
299 bool deleteBidirectional
300) noexcept;
301
302/**
303 * @copydoc deleteReference
304 * @param token @completiontoken{void(StatusCode)}
305 * @return @asyncresult{StatusCode}
306 */
307template <typename CompletionToken>
309 Client& connection,
310 const NodeId& sourceId,
311 const NodeId& targetId,
312 const NodeId& referenceType,
313 bool isForward,
314 bool deleteBidirectional,
315 CompletionToken&& token
316) {
317 auto item = detail::makeDeleteReferencesItem(
318 sourceId, referenceType, isForward, targetId, deleteBidirectional
319 );
320 const auto request = detail::makeDeleteReferencesRequest(item);
322 connection,
323 asWrapper<DeleteReferencesRequest>(request),
324 detail::TransformToken(
325 detail::getSingleStatus<DeleteReferencesResponse>, std::forward<CompletionToken>(token)
326 )
327 );
328}
329
330/**
331 * @}
332 */
333
334/* ------------------------------- Specialized (inline) functions ------------------------------- */
335
336/**
337 * @addtogroup AddNodes
338 * @{
339 */
340
341/**
342 * Add object.
343 * @param connection Instance of type Client (or Server)
344 * @param parentId Parent node
345 * @param id Requested NodeId of the object node to add
346 * @param browseName Browse name
347 * @param attributes Object attributes
348 * @param objectType NodeId of the object type, e.g. ObjectTypeId::BaseObjectType
349 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
350 * ReferenceTypeId::HasComponent
351 */
352template <typename T>
354 T& connection,
355 const NodeId& parentId,
356 const NodeId& id,
357 std::string_view browseName,
358 const ObjectAttributes& attributes,
359 const NodeId& objectType,
360 const NodeId& referenceType
361) noexcept {
362 return addNode(
363 connection,
365 parentId,
366 id,
367 browseName,
368 detail::wrapNodeAttributes(attributes),
369 objectType,
370 referenceType
371 );
372}
373
374/**
375 * @copydoc addObject
376 * @param token @completiontoken{void(Result<NodeId>&)}
377 * @return @asyncresult{Result<NodeId>}
378 */
379template <typename CompletionToken>
381 Client& connection,
382 const NodeId& parentId,
383 const NodeId& id,
384 std::string_view browseName,
385 const ObjectAttributes& attributes,
386 const NodeId& objectType,
387 const NodeId& referenceType,
388 CompletionToken&& token
389) {
390 return addNodeAsync(
391 connection,
393 parentId,
394 id,
395 browseName,
396 detail::wrapNodeAttributes(attributes),
397 objectType,
398 referenceType,
399 std::forward<CompletionToken>(token)
400 );
401}
402
403/**
404 * Add folder.
405 * @param connection Instance of type Client (or Server)
406 * @param parentId Parent node
407 * @param id Requested NodeId of the node to add
408 * @param browseName Browse name
409 * @param attributes Object attributes
410 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
411 * ReferenceTypeId::HasComponent
412 */
413template <typename T>
415 T& connection,
416 const NodeId& parentId,
417 const NodeId& id,
418 std::string_view browseName,
419 const ObjectAttributes& attributes,
420 const NodeId& referenceType
421) noexcept {
422 return addObject(
423 connection, parentId, id, browseName, attributes, ObjectTypeId::FolderType, referenceType
424 );
425}
426
427/**
428 * @copydoc addFolder
429 * @param token @completiontoken{void(Result<NodeId>&)}
430 * @return @asyncresult{Result<NodeId>}
431 */
432template <typename CompletionToken>
434 Client& connection,
435 const NodeId& parentId,
436 const NodeId& id,
437 std::string_view browseName,
438 const ObjectAttributes& attributes,
439 const NodeId& referenceType,
440 CompletionToken&& token
441) {
442 return addObjectAsync(
443 connection,
444 parentId,
445 id,
446 browseName,
447 attributes,
448 ObjectTypeId::FolderType,
449 referenceType,
450 std::forward<CompletionToken>(token)
451 );
452}
453
454/**
455 * Add variable.
456 * @param connection Instance of type Client (or Server)
457 * @param parentId Parent node
458 * @param id Requested NodeId of the node to add
459 * @param browseName Browse name
460 * @param attributes Variable attributes
461 * @param variableType NodeId of the variable type, e.g. VariableTypeId::BaseDataVariableType
462 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
463 * ReferenceTypeId::HasComponent
464 */
465template <typename T>
467 T& connection,
468 const NodeId& parentId,
469 const NodeId& id,
470 std::string_view browseName,
471 const VariableAttributes& attributes,
472 const NodeId& variableType,
473 const NodeId& referenceType
474) noexcept {
475 return addNode(
476 connection,
478 parentId,
479 id,
480 browseName,
481 detail::wrapNodeAttributes(attributes),
482 variableType,
483 referenceType
484 );
485}
486
487/**
488 * @copydoc addVariable
489 * @param token @completiontoken{void(Result<NodeId>&)}
490 * @return @asyncresult{Result<NodeId>}
491 */
492template <typename CompletionToken>
494 Client& connection,
495 const NodeId& parentId,
496 const NodeId& id,
497 std::string_view browseName,
498 const VariableAttributes& attributes,
499 const NodeId& variableType,
500 const NodeId& referenceType,
501 CompletionToken&& token
502) {
503 return addNodeAsync(
504 connection,
506 parentId,
507 id,
508 browseName,
509 detail::wrapNodeAttributes(attributes),
510 variableType,
511 referenceType,
512 std::forward<CompletionToken>(token)
513 );
514}
515
516/**
517 * Add property.
518 * @param connection Instance of type Client (or Server)
519 * @param parentId Parent node
520 * @param id Requested NodeId of the node to add
521 * @param browseName Browse name
522 * @param attributes Property attributes
523 */
524template <typename T>
526 T& connection,
527 const NodeId& parentId,
528 const NodeId& id,
529 std::string_view browseName,
530 const VariableAttributes& attributes
531) noexcept {
532 return addVariable(
533 connection,
534 parentId,
535 id,
536 browseName,
537 attributes,
538 VariableTypeId::PropertyType,
539 ReferenceTypeId::HasProperty
540 );
541}
542
543/**
544 * @copydoc addProperty
545 * @param token @completiontoken{void(Result<NodeId>&)}
546 * @return @asyncresult{Result<NodeId>}
547 */
548template <typename CompletionToken>
550 Client& connection,
551 const NodeId& parentId,
552 const NodeId& id,
553 std::string_view browseName,
554 const VariableAttributes& attributes,
555 CompletionToken&& token
556) {
557 return addVariableAsync(
558 connection,
559 parentId,
560 id,
561 browseName,
562 attributes,
563 VariableTypeId::PropertyType,
564 ReferenceTypeId::HasProperty,
565 std::forward<CompletionToken>(token)
566 );
567}
568
569#ifdef UA_ENABLE_METHODCALLS
570/**
571 * Method callback.
572 * Two function signatures are supported:
573 *
574 * 1. Simple signature with `input` and `output` arguments:
575 * @code
576 * void(
577 * Span<const Variant> input,
578 * Span<Variant> output
579 * )
580 * @endcode
581 * The method call status code is implicitly set to `UA_STATUSCODE_GOOD`.
582 * A bad status code can be returned by throwing a BadStatus exception.
583 *
584 * 2. Full signature with `session`, `input`, `output`, `methodId` and `objectId`:
585 * @code
586 * StatusCode(
587 * Session& session,
588 * Span<const Variant> input,
589 * Span<Variant> output,
590 * const NodeId& methodId,
591 * const NodeId& objectId
592 * )
593 * @endcode
594 * The method call status code is explicitly returned by the function.
595 */
596using MethodCallback = std::variant<
597 std::function<void(Span<const Variant> input, Span<Variant> output)>,
598 std::function<StatusCode(
599 Session& session,
601 Span<Variant> output,
602 const NodeId& methodId,
603 const NodeId& objectId
604 )>>;
605
606/**
607 * Add method.
608 * Callbacks can not be set by clients. Servers can assign callbacks to method nodes afterwards.
609 * @param connection Instance of type Client (or Server)
610 * @param parentId Parent node
611 * @param id Requested NodeId of the node to add
612 * @param browseName Browse name
613 * @param callback Method callback
614 * @param inputArguments Input arguments
615 * @param outputArguments Output arguments
616 * @param attributes Method attributes
617 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
618 * ReferenceTypeId::HasComponent
619 */
620template <typename T>
622 T& connection,
623 const NodeId& parentId,
624 const NodeId& id,
625 std::string_view browseName,
626 MethodCallback callback,
627 Span<const Argument> inputArguments,
628 Span<const Argument> outputArguments,
629 const MethodAttributes& attributes,
630 const NodeId& referenceType
631) noexcept;
632
633/**
634 * @copydoc addMethod
635 * @param token @completiontoken{void(Result<NodeId>&)}
636 * @return @asyncresult{Result<NodeId>}
637 */
638template <typename CompletionToken>
640 Client& connection,
641 const NodeId& parentId,
642 const NodeId& id,
643 std::string_view browseName,
644 [[maybe_unused]] MethodCallback callback, // NOLINT
645 [[maybe_unused]] Span<const Argument> inputArguments,
646 [[maybe_unused]] Span<const Argument> outputArguments,
647 const MethodAttributes& attributes,
648 const NodeId& referenceType,
649 CompletionToken&& token
650) {
651 return addNodeAsync(
652 connection,
654 parentId,
655 id,
656 browseName,
657 detail::wrapNodeAttributes(attributes),
658 {},
659 referenceType,
660 std::forward<CompletionToken>(token)
661 );
662}
663#endif
664
665/**
666 * Add object type.
667 * @param connection Instance of type Client (or Server)
668 * @param parentId Parent node
669 * @param id Requested NodeId of the node to add
670 * @param browseName Browse name
671 * @param attributes Object type attributes
672 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
673 * ReferenceTypeId::HasSubtype
674 */
675template <typename T>
677 T& connection,
678 const NodeId& parentId,
679 const NodeId& id,
680 std::string_view browseName,
681 const ObjectTypeAttributes& attributes,
682 const NodeId& referenceType
683) noexcept {
684 return addNode(
685 connection,
687 parentId,
688 id,
689 browseName,
690 detail::wrapNodeAttributes(attributes),
691 {},
692 referenceType
693 );
694}
695
696/**
697 * @copydoc addObjectType
698 * @param token @completiontoken{void(Result<NodeId>&)}
699 * @return @asyncresult{Result<NodeId>}
700 */
701template <typename CompletionToken>
703 Client& connection,
704 const NodeId& parentId,
705 const NodeId& id,
706 std::string_view browseName,
707 const ObjectTypeAttributes& attributes,
708 const NodeId& referenceType,
709 CompletionToken&& token
710) {
711 return addNodeAsync(
712 connection,
714 parentId,
715 id,
716 browseName,
717 detail::wrapNodeAttributes(attributes),
718 {},
719 referenceType,
720 std::forward<CompletionToken>(token)
721 );
722}
723
724/**
725 * Add variable type.
726 * @param connection Instance of type Client (or Server)
727 * @param parentId Parent node
728 * @param id Requested NodeId of the node to add
729 * @param browseName Browse name
730 * @param attributes Variable type attributes
731 * @param variableType NodeId of the variable type, e.g. VariableTypeId::BaseDataVariableType
732 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
733 * ReferenceTypeId::HasSubtype
734 */
735template <typename T>
737 T& connection,
738 const NodeId& parentId,
739 const NodeId& id,
740 std::string_view browseName,
741 const VariableTypeAttributes& attributes,
742 const NodeId& variableType,
743 const NodeId& referenceType
744) noexcept {
745 return addNode(
746 connection,
748 parentId,
749 id,
750 browseName,
751 detail::wrapNodeAttributes(attributes),
752 variableType,
753 referenceType
754 );
755}
756
757/**
758 * @copydoc addVariableType
759 * @param token @completiontoken{void(Result<NodeId>&)}
760 * @return @asyncresult{Result<NodeId>}
761 */
762template <typename CompletionToken>
764 Client& connection,
765 const NodeId& parentId,
766 const NodeId& id,
767 std::string_view browseName,
768 const VariableTypeAttributes& attributes,
769 const NodeId& variableType,
770 const NodeId& referenceType,
771 CompletionToken&& token
772) {
773 return addNodeAsync(
774 connection,
776 parentId,
777 id,
778 browseName,
779 detail::wrapNodeAttributes(attributes),
780 variableType,
781 referenceType,
782 std::forward<CompletionToken>(token)
783 );
784}
785
786/**
787 * Add reference type.
788 * @param connection Instance of type Client (or Server)
789 * @param parentId Parent node
790 * @param id Requested NodeId of the node to add
791 * @param browseName Browse name
792 * @param attributes Reference type attributes
793 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
794 * ReferenceTypeId::HasSubtype
795 */
796template <typename T>
798 T& connection,
799 const NodeId& parentId,
800 const NodeId& id,
801 std::string_view browseName,
802 const ReferenceTypeAttributes& attributes,
803 const NodeId& referenceType
804) noexcept {
805 return addNode(
806 connection,
808 parentId,
809 id,
810 browseName,
811 detail::wrapNodeAttributes(attributes),
812 {},
813 referenceType
814 );
815}
816
817/**
818 * @copydoc addReferenceType
819 * @param token @completiontoken{void(Result<NodeId>&)}
820 * @return @asyncresult{Result<NodeId>}
821 */
822template <typename CompletionToken>
824 Client& connection,
825 const NodeId& parentId,
826 const NodeId& id,
827 std::string_view browseName,
828 const ReferenceTypeAttributes& attributes,
829 const NodeId& referenceType,
830 CompletionToken&& token
831) {
832 return addNodeAsync(
833 connection,
835 parentId,
836 id,
837 browseName,
838 detail::wrapNodeAttributes(attributes),
839 {},
840 referenceType,
841 std::forward<CompletionToken>(token)
842 );
843}
844
845/**
846 * Add data type.
847 * @param connection Instance of type Client (or Server)
848 * @param parentId Parent node
849 * @param id Requested NodeId of the node to add
850 * @param browseName Browse name
851 * @param attributes Data type attributes
852 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
853 * ReferenceTypeId::HasSubtype
854 */
855template <typename T>
857 T& connection,
858 const NodeId& parentId,
859 const NodeId& id,
860 std::string_view browseName,
861 const DataTypeAttributes& attributes,
862 const NodeId& referenceType
863) noexcept {
864 return addNode(
865 connection,
867 parentId,
868 id,
869 browseName,
870 detail::wrapNodeAttributes(attributes),
871 {},
872 referenceType
873 );
874}
875
876/**
877 * @copydoc addDataType
878 * @param token @completiontoken{void(Result<NodeId>&)}
879 * @return @asyncresult{Result<NodeId>}
880 */
881template <typename CompletionToken>
883 Client& connection,
884 const NodeId& parentId,
885 const NodeId& id,
886 std::string_view browseName,
887 const DataTypeAttributes& attributes,
888 const NodeId& referenceType,
889 CompletionToken&& token
890) {
891 return addNodeAsync(
892 connection,
894 parentId,
895 id,
896 browseName,
897 detail::wrapNodeAttributes(attributes),
898 {},
899 referenceType,
900 std::forward<CompletionToken>(token)
901 );
902}
903
904/**
905 * Add view.
906 * @param connection Instance of type Client (or Server)
907 * @param parentId Parent node
908 * @param id Requested NodeId of the node to add
909 * @param browseName Browse name
910 * @param attributes View attributes
911 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
912 * ReferenceTypeId::Organizes
913 */
914template <typename T>
916 T& connection,
917 const NodeId& parentId,
918 const NodeId& id,
919 std::string_view browseName,
920 const ViewAttributes& attributes,
921 const NodeId& referenceType
922) noexcept {
923 return addNode(
924 connection,
926 parentId,
927 id,
928 browseName,
929 detail::wrapNodeAttributes(attributes),
930 {},
931 referenceType
932 );
933}
934
935/**
936 * @copydoc addView
937 * @param token @completiontoken{void(Result<NodeId>&)}
938 * @return @asyncresult{Result<NodeId>}
939 */
940template <typename CompletionToken>
942 Client& connection,
943 const NodeId& parentId,
944 const NodeId& id,
945 std::string_view browseName,
946 const ViewAttributes& attributes,
947 const NodeId& referenceType,
948 CompletionToken&& token
949) {
950 return addNodeAsync(
951 connection,
953 parentId,
954 id,
955 browseName,
956 detail::wrapNodeAttributes(attributes),
957 {},
958 referenceType,
959 std::forward<CompletionToken>(token)
960 );
961}
962
963/**
964 * @}
965 * @addtogroup AddReferences
966 * @{
967 */
968
969/**
970 * Add modelling rule.
971 * @param connection Instance of type Client (or Server)
972 * @param id Node
973 * @param rule Modelling rule to add
974 * @see https://reference.opcfoundation.org/Core/Part3/v105/docs/6.4.4
975 */
976template <typename T>
977StatusCode addModellingRule(T& connection, const NodeId& id, ModellingRule rule) noexcept {
978 return addReference(
979 connection, id, {0, static_cast<uint32_t>(rule)}, ReferenceTypeId::HasModellingRule, true
980 );
981}
982
983/**
984 * @copydoc addModellingRule
985 * @param token @completiontoken{void(StatusCode)}
986 * @return @asyncresult{StatusCode}
987 */
988template <typename CompletionToken>
990 Client& connection, const NodeId& id, ModellingRule rule, CompletionToken&& token
991) {
992 return addReferenceAsync(
993 connection,
994 id,
995 {0, static_cast<uint32_t>(rule)},
996 ReferenceTypeId::HasModellingRule,
997 true,
998 std::forward<CompletionToken>(token)
999 );
1000}
1001
1002/**
1003 * @}
1004 * @}
1005 */
1006
1007} // namespace opcua::services
High-level client class.
Definition client.hpp:130
UA_ExtensionObject wrapper class.
Definition types.hpp:1742
UA_NodeId wrapper class.
Definition types.hpp:641
The template class Result encapsulates a StatusCode and optionally a value.
Definition result.hpp:53
High-level session class to manage client sessions.
Definition session.hpp:20
View to a contiguous sequence of objects, similar to std::span in C++20.
Definition span.hpp:29
UA_StatusCode wrapper class.
Definition types.hpp:44
UA_AddNodesRequest wrapper class.
Definition types.hpp:762
UA_AddNodesResponse wrapper class.
Definition types.hpp:780
UA_AddReferencesRequest wrapper class.
Definition types.hpp:826
UA_AddReferencesResponse wrapper class.
Definition types.hpp:847
UA_DataTypeAttributes wrapper class.
Definition types.hpp:589
UA_DeleteNodesRequest wrapper class.
Definition types.hpp:878
UA_DeleteNodesResponse wrapper class.
Definition types.hpp:897
UA_DeleteReferencesRequest wrapper class.
Definition types.hpp:941
UA_DeleteReferencesResponse wrapper class.
Definition types.hpp:962
UA_MethodAttributes wrapper class.
Definition types.hpp:483
UA_ObjectAttributes wrapper class.
Definition types.hpp:400
UA_ObjectTypeAttributes wrapper class.
Definition types.hpp:501
UA_ReferenceTypeAttributes wrapper class.
Definition types.hpp:568
UA_VariableAttributes wrapper class.
Definition types.hpp:419
UA_VariableAttributes wrapper class.
Definition types.hpp:518
UA_ViewAttributes wrapper class.
Definition types.hpp:605
Result< NodeId > addNode(T &connection, NodeClass nodeClass, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ExtensionObject &nodeAttributes, const NodeId &typeDefinition, const NodeId &referenceType) noexcept
Add a node.
auto addObjectTypeAsync(Client &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ObjectTypeAttributes &attributes, const NodeId &referenceType, CompletionToken &&token)
Add object type.
auto addPropertyAsync(Client &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const VariableAttributes &attributes, CompletionToken &&token)
Add property.
Result< NodeId > addObject(T &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ObjectAttributes &attributes, const NodeId &objectType, const NodeId &referenceType) noexcept
Add object.
auto addMethodAsync(Client &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, MethodCallback callback, Span< const Argument > inputArguments, Span< const Argument > outputArguments, const MethodAttributes &attributes, const NodeId &referenceType, CompletionToken &&token)
Add method.
std::variant< std::function< void(Span< const Variant > input, Span< Variant > output)>, std::function< StatusCode(Session &session, Span< const Variant > input, Span< Variant > output, const NodeId &methodId, const NodeId &objectId)> > MethodCallback
Method callback.
Result< NodeId > addObjectType(T &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ObjectTypeAttributes &attributes, const NodeId &referenceType) noexcept
Add object type.
Result< NodeId > addMethod(T &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, MethodCallback callback, Span< const Argument > inputArguments, Span< const Argument > outputArguments, const MethodAttributes &attributes, const NodeId &referenceType) noexcept
Add method.
auto addNodesAsync(Client &connection, const AddNodesRequest &request, CompletionToken &&token)
Add one or more nodes (client only).
auto addFolderAsync(Client &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ObjectAttributes &attributes, const NodeId &referenceType, CompletionToken &&token)
Add folder.
Result< NodeId > addFolder(T &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ObjectAttributes &attributes, const NodeId &referenceType) noexcept
Add folder.
Result< NodeId > addDataType(T &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const DataTypeAttributes &attributes, const NodeId &referenceType) noexcept
Add data type.
auto addNodeAsync(Client &connection, NodeClass nodeClass, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ExtensionObject &nodeAttributes, const NodeId &typeDefinition, const NodeId &referenceType, CompletionToken &&token)
Add a node.
auto addReferenceTypeAsync(Client &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ReferenceTypeAttributes &attributes, const NodeId &referenceType, CompletionToken &&token)
Add reference type.
auto addDataTypeAsync(Client &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const DataTypeAttributes &attributes, const NodeId &referenceType, CompletionToken &&token)
Add data type.
auto addVariableTypeAsync(Client &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const VariableTypeAttributes &attributes, const NodeId &variableType, const NodeId &referenceType, CompletionToken &&token)
Add variable type.
Result< NodeId > addVariableType(T &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const VariableTypeAttributes &attributes, const NodeId &variableType, const NodeId &referenceType) noexcept
Add variable type.
auto addVariableAsync(Client &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const VariableAttributes &attributes, const NodeId &variableType, const NodeId &referenceType, CompletionToken &&token)
Add variable.
Result< NodeId > addReferenceType(T &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ReferenceTypeAttributes &attributes, const NodeId &referenceType) noexcept
Add reference type.
Result< NodeId > addProperty(T &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const VariableAttributes &attributes) noexcept
Add property.
Result< NodeId > addView(T &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ViewAttributes &attributes, const NodeId &referenceType) noexcept
Add view.
AddNodesResponse addNodes(Client &connection, const AddNodesRequest &request) noexcept
Add one or more nodes (client only).
auto addObjectAsync(Client &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ObjectAttributes &attributes, const NodeId &objectType, const NodeId &referenceType, CompletionToken &&token)
Add object.
auto addViewAsync(Client &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const ViewAttributes &attributes, const NodeId &referenceType, CompletionToken &&token)
Add view.
Result< NodeId > addVariable(T &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const VariableAttributes &attributes, const NodeId &variableType, const NodeId &referenceType) noexcept
Add variable.
StatusCode addModellingRule(T &connection, const NodeId &id, ModellingRule rule) noexcept
Add modelling rule.
AddReferencesResponse addReferences(Client &connection, const AddReferencesRequest &request) noexcept
Add one or more references (client only).
auto addReferencesAsync(Client &connection, const AddReferencesRequest &request, CompletionToken &&token)
Add one or more references (client only).
auto addModellingRuleAsync(Client &connection, const NodeId &id, ModellingRule rule, CompletionToken &&token)
Add modelling rule.
auto addReferenceAsync(Client &connection, const NodeId &sourceId, const NodeId &targetId, const NodeId &referenceType, bool forward, CompletionToken &&token)
Add reference.
StatusCode addReference(T &connection, const NodeId &sourceId, const NodeId &targetId, const NodeId &referenceType, bool forward) noexcept
Add reference.
DeleteNodesResponse deleteNodes(Client &connection, const DeleteNodesRequest &request) noexcept
Delete one or more nodes (client only).
auto deleteNodeAsync(Client &connection, const NodeId &id, bool deleteReferences, CompletionToken &&token)
Delete node.
StatusCode deleteNode(T &connection, const NodeId &id, bool deleteReferences) noexcept
Delete node.
auto deleteNodesAsync(Client &connection, const DeleteNodesRequest &request, CompletionToken &&token)
Delete one or more nodes (client only).
auto deleteReferencesAsync(Client &connection, const DeleteReferencesRequest &request, CompletionToken &&token)
Delete one or more references (client only).
DeleteReferencesResponse deleteReferences(Client &connection, const DeleteReferencesRequest &request) noexcept
Delete one or more references (client only).
auto deleteReferenceAsync(Client &connection, const NodeId &sourceId, const NodeId &targetId, const NodeId &referenceType, bool isForward, bool deleteBidirectional, CompletionToken &&token)
Delete reference.
StatusCode deleteReference(T &connection, const NodeId &sourceId, const NodeId &targetId, const NodeId &referenceType, bool isForward, bool deleteBidirectional) noexcept
Delete reference.
OPC UA services as free functions.
Definition attribute.hpp:21
NodeClass
Node class.
Definition common.hpp:71
ModellingRule
Modelling rules.
Definition common.hpp:190