open62541pp 0.21.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
664/**
665 * Set method callback after creation.
666 * @param connection Instance of type Server
667 * @param id Method node
668 * @param callback Method callback
669 */
670template <typename T>
671StatusCode setMethodCallback(T& connection, const NodeId& id, MethodCallback callback) noexcept;
672#endif
673
674/**
675 * Add object type.
676 * @param connection Instance of type Client (or Server)
677 * @param parentId Parent node
678 * @param id Requested NodeId of the node to add
679 * @param browseName Browse name
680 * @param attributes Object type attributes
681 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
682 * ReferenceTypeId::HasSubtype
683 */
684template <typename T>
686 T& connection,
687 const NodeId& parentId,
688 const NodeId& id,
689 std::string_view browseName,
690 const ObjectTypeAttributes& attributes,
691 const NodeId& referenceType
692) noexcept {
693 return addNode(
694 connection,
696 parentId,
697 id,
698 browseName,
699 detail::wrapNodeAttributes(attributes),
700 {},
701 referenceType
702 );
703}
704
705/**
706 * @copydoc addObjectType
707 * @param token @completiontoken{void(Result<NodeId>&)}
708 * @return @asyncresult{Result<NodeId>}
709 */
710template <typename CompletionToken>
712 Client& connection,
713 const NodeId& parentId,
714 const NodeId& id,
715 std::string_view browseName,
716 const ObjectTypeAttributes& attributes,
717 const NodeId& referenceType,
718 CompletionToken&& token
719) {
720 return addNodeAsync(
721 connection,
723 parentId,
724 id,
725 browseName,
726 detail::wrapNodeAttributes(attributes),
727 {},
728 referenceType,
729 std::forward<CompletionToken>(token)
730 );
731}
732
733/**
734 * Add variable type.
735 * @param connection Instance of type Client (or Server)
736 * @param parentId Parent node
737 * @param id Requested NodeId of the node to add
738 * @param browseName Browse name
739 * @param attributes Variable type attributes
740 * @param variableType NodeId of the variable type, e.g. VariableTypeId::BaseDataVariableType
741 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
742 * ReferenceTypeId::HasSubtype
743 */
744template <typename T>
746 T& connection,
747 const NodeId& parentId,
748 const NodeId& id,
749 std::string_view browseName,
750 const VariableTypeAttributes& attributes,
751 const NodeId& variableType,
752 const NodeId& referenceType
753) noexcept {
754 return addNode(
755 connection,
757 parentId,
758 id,
759 browseName,
760 detail::wrapNodeAttributes(attributes),
761 variableType,
762 referenceType
763 );
764}
765
766/**
767 * @copydoc addVariableType
768 * @param token @completiontoken{void(Result<NodeId>&)}
769 * @return @asyncresult{Result<NodeId>}
770 */
771template <typename CompletionToken>
773 Client& connection,
774 const NodeId& parentId,
775 const NodeId& id,
776 std::string_view browseName,
777 const VariableTypeAttributes& attributes,
778 const NodeId& variableType,
779 const NodeId& referenceType,
780 CompletionToken&& token
781) {
782 return addNodeAsync(
783 connection,
785 parentId,
786 id,
787 browseName,
788 detail::wrapNodeAttributes(attributes),
789 variableType,
790 referenceType,
791 std::forward<CompletionToken>(token)
792 );
793}
794
795/**
796 * Add reference type.
797 * @param connection Instance of type Client (or Server)
798 * @param parentId Parent node
799 * @param id Requested NodeId of the node to add
800 * @param browseName Browse name
801 * @param attributes Reference type attributes
802 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
803 * ReferenceTypeId::HasSubtype
804 */
805template <typename T>
807 T& connection,
808 const NodeId& parentId,
809 const NodeId& id,
810 std::string_view browseName,
811 const ReferenceTypeAttributes& attributes,
812 const NodeId& referenceType
813) noexcept {
814 return addNode(
815 connection,
817 parentId,
818 id,
819 browseName,
820 detail::wrapNodeAttributes(attributes),
821 {},
822 referenceType
823 );
824}
825
826/**
827 * @copydoc addReferenceType
828 * @param token @completiontoken{void(Result<NodeId>&)}
829 * @return @asyncresult{Result<NodeId>}
830 */
831template <typename CompletionToken>
833 Client& connection,
834 const NodeId& parentId,
835 const NodeId& id,
836 std::string_view browseName,
837 const ReferenceTypeAttributes& attributes,
838 const NodeId& referenceType,
839 CompletionToken&& token
840) {
841 return addNodeAsync(
842 connection,
844 parentId,
845 id,
846 browseName,
847 detail::wrapNodeAttributes(attributes),
848 {},
849 referenceType,
850 std::forward<CompletionToken>(token)
851 );
852}
853
854/**
855 * Add data type.
856 * @param connection Instance of type Client (or Server)
857 * @param parentId Parent node
858 * @param id Requested NodeId of the node to add
859 * @param browseName Browse name
860 * @param attributes Data type attributes
861 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
862 * ReferenceTypeId::HasSubtype
863 */
864template <typename T>
866 T& connection,
867 const NodeId& parentId,
868 const NodeId& id,
869 std::string_view browseName,
870 const DataTypeAttributes& attributes,
871 const NodeId& referenceType
872) noexcept {
873 return addNode(
874 connection,
876 parentId,
877 id,
878 browseName,
879 detail::wrapNodeAttributes(attributes),
880 {},
881 referenceType
882 );
883}
884
885/**
886 * @copydoc addDataType
887 * @param token @completiontoken{void(Result<NodeId>&)}
888 * @return @asyncresult{Result<NodeId>}
889 */
890template <typename CompletionToken>
892 Client& connection,
893 const NodeId& parentId,
894 const NodeId& id,
895 std::string_view browseName,
896 const DataTypeAttributes& attributes,
897 const NodeId& referenceType,
898 CompletionToken&& token
899) {
900 return addNodeAsync(
901 connection,
903 parentId,
904 id,
905 browseName,
906 detail::wrapNodeAttributes(attributes),
907 {},
908 referenceType,
909 std::forward<CompletionToken>(token)
910 );
911}
912
913/**
914 * Add view.
915 * @param connection Instance of type Client (or Server)
916 * @param parentId Parent node
917 * @param id Requested NodeId of the node to add
918 * @param browseName Browse name
919 * @param attributes View attributes
920 * @param referenceType Hierarchical reference type from the parent node to the new node, e.g.
921 * ReferenceTypeId::Organizes
922 */
923template <typename T>
925 T& connection,
926 const NodeId& parentId,
927 const NodeId& id,
928 std::string_view browseName,
929 const ViewAttributes& attributes,
930 const NodeId& referenceType
931) noexcept {
932 return addNode(
933 connection,
935 parentId,
936 id,
937 browseName,
938 detail::wrapNodeAttributes(attributes),
939 {},
940 referenceType
941 );
942}
943
944/**
945 * @copydoc addView
946 * @param token @completiontoken{void(Result<NodeId>&)}
947 * @return @asyncresult{Result<NodeId>}
948 */
949template <typename CompletionToken>
951 Client& connection,
952 const NodeId& parentId,
953 const NodeId& id,
954 std::string_view browseName,
955 const ViewAttributes& attributes,
956 const NodeId& referenceType,
957 CompletionToken&& token
958) {
959 return addNodeAsync(
960 connection,
962 parentId,
963 id,
964 browseName,
965 detail::wrapNodeAttributes(attributes),
966 {},
967 referenceType,
968 std::forward<CompletionToken>(token)
969 );
970}
971
972/**
973 * @}
974 * @addtogroup AddReferences
975 * @{
976 */
977
978/**
979 * Add modelling rule.
980 * @param connection Instance of type Client (or Server)
981 * @param id Node
982 * @param rule Modelling rule to add
983 * @see https://reference.opcfoundation.org/Core/Part3/v105/docs/6.4.4
984 */
985template <typename T>
986StatusCode addModellingRule(T& connection, const NodeId& id, ModellingRule rule) noexcept {
987 return addReference(
988 connection, id, {0, static_cast<uint32_t>(rule)}, ReferenceTypeId::HasModellingRule, true
989 );
990}
991
992/**
993 * @copydoc addModellingRule
994 * @param token @completiontoken{void(StatusCode)}
995 * @return @asyncresult{StatusCode}
996 */
997template <typename CompletionToken>
999 Client& connection, const NodeId& id, ModellingRule rule, CompletionToken&& token
1000) {
1001 return addReferenceAsync(
1002 connection,
1003 id,
1004 {0, static_cast<uint32_t>(rule)},
1005 ReferenceTypeId::HasModellingRule,
1006 true,
1007 std::forward<CompletionToken>(token)
1008 );
1009}
1010
1011/**
1012 * @}
1013 * @}
1014 */
1015
1016} // namespace opcua::services
High-level client class.
Definition client.hpp:130
UA_ExtensionObject wrapper class.
Definition types.hpp:1750
UA_NodeId wrapper class.
Definition types.hpp:652
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:41
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
StatusCode setMethodCallback(T &connection, const NodeId &id, MethodCallback callback) noexcept
Set method callback after creation.
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