/
server_pubsub.h
837 lines (728 loc) · 34.4 KB
/
server_pubsub.h
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
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright (c) 2017-2018 Fraunhofer IOSB (Author: Andreas Ebner)
* Copyright (c) 2019 Kalycito Infotech Private Limited
* Copyright (c) 2021 Fraunhofer IOSB (Author: Jan Hermes)
*/
#ifndef UA_SERVER_PUBSUB_H
#define UA_SERVER_PUBSUB_H
#include <open62541/util.h>
#include <open62541/plugin/pubsub.h>
#include <open62541/plugin/securitypolicy.h>
_UA_BEGIN_DECLS
#ifdef UA_ENABLE_PUBSUB
/**
* .. _pubsub:
*
* PubSub
* ======
*
* In PubSub the participating OPC UA Applications take their roles as
* Publishers and Subscribers. Publishers are the sources of data, while
* Subscribers consume that data. Communication in PubSub is message-based.
* Publishers send messages to a Message Oriented Middleware, without knowledge
* of what, if any, Subscribers there may be. Similarly, Subscribers express
* interest in specific types of data, and process messages that contain this
* data, without knowledge of what Publishers there are.
*
* Message Oriented Middleware is software or hardware infrastructure that
* supports sending and receiving messages between distributed systems. OPC UA
* PubSub supports two different Message Oriented Middleware variants, namely
* the broker-less form and broker-based form. A broker-less form is where the
* Message Oriented Middleware is the network infrastructure that is able to
* route datagram-based messages. Subscribers and Publishers use datagram
* protocols like UDP. In a broker-based form, the core component of the Message
* Oriented Middleware is a message Broker. Subscribers and Publishers use
* standard messaging protocols like AMQP or MQTT to communicate with the
* Broker.
*
* This makes PubSub suitable for applications where location independence
* and/or scalability are required.
*
* The Publish/Subscribe (PubSub) extension for OPC UA enables fast and
* efficient 1:m communication. The PubSub extension is protocol agnostic and
* can be used with broker based protocols like MQTT and AMQP or brokerless
* implementations like UDP-Multicasting.
*
* The PubSub API uses the following scheme:
*
* 1. Create a configuration for the needed PubSub element.
*
* 2. Call the add[element] function and pass in the configuration.
*
* 3. The add[element] function returns the unique nodeId of the internally created element.
*
* Take a look on the PubSub Tutorials for more details about the API usage::
*
* +-----------+
* | UA_Server |
* +-----------+
* | |
* | |
* | |
* | | +----------------------+
* | +--> UA_PubSubConnection | UA_Server_addPubSubConnection
* | +----------------------+
* | | |
* | | | +----------------+
* | | +----> UA_WriterGroup | UA_PubSubConnection_addWriterGroup
* | | +----------------+
* | | |
* | | | +------------------+
* | | +----> UA_DataSetWriter | UA_WriterGroup_addDataSetWriter +-+
* | | +------------------+ |
* | | |
* | | +----------------+ | r
* | +---------> UA_ReaderGroup | UA_PubSubConnection_addReaderGroup | e
* | +----------------+ | f
* | | |
* | | +------------------+ |
* | +----> UA_DataSetReader | UA_ReaderGroup_addDataSetReader |
* | +------------------+ |
* | | |
* | | +----------------------+ |
* | +----> UA_SubscribedDataSet | |
* | +----------------------+ |
* | | |
* | | +----------------------------+ |
* | +----> UA_TargetVariablesDataType | |
* | | +----------------------------+ |
* | | |
* | | +------------------------------------+ |
* | +----> UA_SubscribedDataSetMirrorDataType | |
* | +------------------------------------+ |
* | |
* | +---------------------------+ |
* +-------> UA_PubSubPublishedDataSet | UA_Server_addPublishedDataSet <-+
* +---------------------------+
* |
* | +-----------------+
* +----> UA_DataSetField | UA_PublishedDataSet_addDataSetField
* +-----------------+
*
* PubSub Information Model Representation
* ---------------------------------------
* .. _pubsub_informationmodel:
*
* The complete PubSub configuration is available inside the information model.
* The entry point is the node 'PublishSubscribe', located under the Server
* node.
* The standard defines for PubSub no new Service set. The configuration can
* optionally be done over methods inside the information model.
* The information model representation of the current PubSub configuration is
* generated automatically. This feature can be enabled/disabled by changing the
* UA_ENABLE_PUBSUB_INFORMATIONMODEL option.
*
* Connections
* -----------
* The PubSub connections are the abstraction between the concrete transport protocol
* and the PubSub functionality. It is possible to create multiple connections with
* different transport protocols at runtime.
*
* Take a look on the PubSub Tutorials for mor details about the API usage.
*/
typedef enum {
UA_PUBSUB_COMPONENT_CONNECTION,
UA_PUBSUB_COMPONENT_WRITERGROUP,
UA_PUBSUB_COMPONENT_DATASETWRITER,
UA_PUBSUB_COMPONENT_READERGROUP,
UA_PUBSUB_COMPONENT_DATASETREADER
} UA_PubSubComponentEnumType;
typedef enum {
UA_PUBSUB_PUBLISHERID_NUMERIC,
UA_PUBSUB_PUBLISHERID_STRING
} UA_PublisherIdType;
struct UA_PubSubConnectionConfig {
UA_String name;
UA_Boolean enabled;
UA_PublisherIdType publisherIdType;
union { /* std: valid types UInt or String */
UA_UInt32 numeric;
UA_String string;
} publisherId;
UA_String transportProfileUri;
UA_Variant address;
size_t connectionPropertiesSize;
UA_KeyValuePair *connectionProperties;
UA_Variant connectionTransportSettings;
};
#ifdef UA_ENABLE_PUBSUB_MONITORING
typedef enum {
UA_PUBSUB_MONITORING_MESSAGE_RECEIVE_TIMEOUT
// extend as needed
} UA_PubSubMonitoringType;
/* PubSub monitoring interface */
typedef struct {
UA_StatusCode (*createMonitoring)(UA_Server *server, UA_NodeId Id,
UA_PubSubComponentEnumType eComponentType,
UA_PubSubMonitoringType eMonitoringType,
void *data, UA_ServerCallback callback);
UA_StatusCode (*startMonitoring)(UA_Server *server, UA_NodeId Id,
UA_PubSubComponentEnumType eComponentType,
UA_PubSubMonitoringType eMonitoringType, void *data);
UA_StatusCode (*stopMonitoring)(UA_Server *server, UA_NodeId Id,
UA_PubSubComponentEnumType eComponentType,
UA_PubSubMonitoringType eMonitoringType, void *data);
UA_StatusCode (*updateMonitoringInterval)(UA_Server *server, UA_NodeId Id,
UA_PubSubComponentEnumType eComponentType,
UA_PubSubMonitoringType eMonitoringType,
void *data);
UA_StatusCode (*deleteMonitoring)(UA_Server *server, UA_NodeId Id,
UA_PubSubComponentEnumType eComponentType,
UA_PubSubMonitoringType eMonitoringType, void *data);
} UA_PubSubMonitoringInterface;
#endif /* UA_ENABLE_PUBSUB_MONITORING */
/* General PubSub configuration */
struct UA_PubSubConfiguration {
/* PubSub network layer */
size_t transportLayersSize;
UA_PubSubTransportLayer *transportLayers;
/* Callback for PubSub component state changes: If provided this callback
* informs the application about PubSub component state changes. E.g. state
* change from operational to error in case of a DataSetReader
* MessageReceiveTimeout. The status code provides additional
* information. */
void (*stateChangeCallback)(UA_NodeId *Id, UA_PubSubState state,
UA_StatusCode status);
/* TODO: maybe status code provides not enough information about the state change */
#ifdef UA_ENABLE_PUBSUB_ENCRYPTION
/* PubSub security policies */
size_t securityPoliciesSize;
UA_PubSubSecurityPolicy *securityPolicies;
#endif
#ifdef UA_ENABLE_PUBSUB_MONITORING
UA_PubSubMonitoringInterface monitoringInterface;
#endif
};
/**
* The UA_ServerConfig_addPubSubTransportLayer is used to add a transport layer
* to the server configuration. The list memory is allocated and will be freed
* with UA_PubSubManager_delete.
*
* .. note:: If the UA_String transportProfileUri was dynamically allocated
* the memory has to be freed when no longer required.
*
* .. note:: This has to be done before the server is started with UA_Server_run. */
UA_StatusCode UA_EXPORT
UA_ServerConfig_addPubSubTransportLayer(UA_ServerConfig *config,
UA_PubSubTransportLayer pubsubTransportLayer);
/**
* Add a new PubSub connection to the given server and open it.
* @param[in] server the server to add the connection to
* @param[in] connectionConfig the configuration for the newly added connection
* @param[out] connectionIdentifier if not NULL will be set to the identifier of the
* newly added connection
* @return UA_STATUSCODE_GOOD if connection was successfully added, otherwise an
* error code.
*/
UA_StatusCode UA_EXPORT
UA_Server_addPubSubConnection(UA_Server *server,
const UA_PubSubConnectionConfig *connectionConfig,
UA_NodeId *connectionIdentifier);
/* Returns a deep copy of the config */
UA_StatusCode UA_EXPORT
UA_Server_getPubSubConnectionConfig(UA_Server *server,
const UA_NodeId connection,
UA_PubSubConnectionConfig *config);
/* Remove Connection, identified by the NodeId. Deletion of Connection
* removes all contained WriterGroups and Writers. */
UA_StatusCode UA_EXPORT UA_THREADSAFE
UA_Server_removePubSubConnection(UA_Server *server, const UA_NodeId connection);
/**
* PublishedDataSets
* -----------------
* The PublishedDataSets (PDS) are containers for the published information. The
* PDS contain the published variables and meta information. The metadata is
* commonly autogenerated or given as constant argument as part of the template
* functions. The template functions are standard defined and intended for
* configuration tools. You should normally create an empty PDS and call the
* functions to add new fields. */
/* The UA_PUBSUB_DATASET_PUBLISHEDITEMS has currently no additional members and
* thus no dedicated config structure. */
typedef enum {
UA_PUBSUB_DATASET_PUBLISHEDITEMS,
UA_PUBSUB_DATASET_PUBLISHEDEVENTS,
UA_PUBSUB_DATASET_PUBLISHEDITEMS_TEMPLATE,
UA_PUBSUB_DATASET_PUBLISHEDEVENTS_TEMPLATE,
} UA_PublishedDataSetType;
typedef struct {
UA_DataSetMetaDataType metaData;
size_t variablesToAddSize;
UA_PublishedVariableDataType *variablesToAdd;
} UA_PublishedDataItemsTemplateConfig;
typedef struct {
UA_NodeId eventNotfier;
UA_ContentFilter filter;
} UA_PublishedEventConfig;
typedef struct {
UA_DataSetMetaDataType metaData;
UA_NodeId eventNotfier;
size_t selectedFieldsSize;
UA_SimpleAttributeOperand *selectedFields;
UA_ContentFilter filter;
} UA_PublishedEventTemplateConfig;
/* Configuration structure for PublishedDataSet */
typedef struct {
UA_String name;
UA_PublishedDataSetType publishedDataSetType;
union {
/* The UA_PUBSUB_DATASET_PUBLISHEDITEMS has currently no additional members
* and thus no dedicated config structure.*/
UA_PublishedDataItemsTemplateConfig itemsTemplate;
UA_PublishedEventConfig event;
UA_PublishedEventTemplateConfig eventTemplate;
} config;
} UA_PublishedDataSetConfig;
void UA_EXPORT
UA_PublishedDataSetConfig_clear(UA_PublishedDataSetConfig *pdsConfig);
typedef struct {
UA_StatusCode addResult;
size_t fieldAddResultsSize;
UA_StatusCode *fieldAddResults;
UA_ConfigurationVersionDataType configurationVersion;
} UA_AddPublishedDataSetResult;
UA_AddPublishedDataSetResult UA_EXPORT
UA_Server_addPublishedDataSet(UA_Server *server,
const UA_PublishedDataSetConfig *publishedDataSetConfig,
UA_NodeId *pdsIdentifier);
/* Returns a deep copy of the config */
UA_StatusCode UA_EXPORT
UA_Server_getPublishedDataSetConfig(UA_Server *server, const UA_NodeId pds,
UA_PublishedDataSetConfig *config);
/* Returns a deep copy of the DataSetMetaData for an specific PDS */
UA_StatusCode UA_EXPORT
UA_Server_getPublishedDataSetMetaData(UA_Server *server, const UA_NodeId pds,
UA_DataSetMetaDataType *metaData);
/* Remove PublishedDataSet, identified by the NodeId. Deletion of PDS removes
* all contained and linked PDS Fields. Connected WriterGroups will be also
* removed. */
UA_StatusCode UA_EXPORT
UA_Server_removePublishedDataSet(UA_Server *server, const UA_NodeId pds);
/**
* DataSetFields
* -------------
* The description of published variables is named DataSetField. Each
* DataSetField contains the selection of one information model node. The
* DataSetField has additional parameters for the publishing, sampling and error
* handling process. */
typedef struct{
UA_ConfigurationVersionDataType configurationVersion;
UA_String fieldNameAlias;
UA_Boolean promotedField;
UA_PublishedVariableDataType publishParameters;
/* non std. field */
struct {
UA_Boolean rtFieldSourceEnabled;
/* If the rtInformationModelNode is set, the nodeid in publishParameter must point
* to a node with external data source backend defined
* */
UA_Boolean rtInformationModelNode;
//TODO -> decide if suppress C++ warnings and use 'UA_DataValue * * const staticValueSource;'
UA_DataValue ** staticValueSource;
} rtValueSource;
} UA_DataSetVariableConfig;
typedef enum {
UA_PUBSUB_DATASETFIELD_VARIABLE,
UA_PUBSUB_DATASETFIELD_EVENT
} UA_DataSetFieldType;
typedef struct {
UA_DataSetFieldType dataSetFieldType;
union {
/* events need other config later */
UA_DataSetVariableConfig variable;
} field;
} UA_DataSetFieldConfig;
void UA_EXPORT
UA_DataSetFieldConfig_clear(UA_DataSetFieldConfig *dataSetFieldConfig);
typedef struct {
UA_StatusCode result;
UA_ConfigurationVersionDataType configurationVersion;
} UA_DataSetFieldResult;
UA_DataSetFieldResult UA_EXPORT UA_THREADSAFE
UA_Server_addDataSetField(UA_Server *server,
const UA_NodeId publishedDataSet,
const UA_DataSetFieldConfig *fieldConfig,
UA_NodeId *fieldIdentifier);
/* Returns a deep copy of the config */
UA_StatusCode UA_EXPORT
UA_Server_getDataSetFieldConfig(UA_Server *server, const UA_NodeId dsf,
UA_DataSetFieldConfig *config);
UA_DataSetFieldResult UA_EXPORT UA_THREADSAFE
UA_Server_removeDataSetField(UA_Server *server, const UA_NodeId dsf);
/**
* Custom Callback Implementation
* ------------------------------
* The user can use his own callback implementation for publishing
* and subscribing. The user must take care of the callback to call for
* every publishing or subscibing interval */
typedef struct {
/* User's callback implementation. The user configured base time and timer policy
* will be provided as an argument to this callback so that the user can
* implement his callback (thread) considering base time and timer policies */
UA_StatusCode (*addCustomCallback)(UA_Server *server, UA_NodeId identifier,
UA_ServerCallback callback,
void *data, UA_Double interval_ms,
UA_DateTime *baseTime, UA_TimerPolicy timerPolicy,
UA_UInt64 *callbackId);
UA_StatusCode (*changeCustomCallback)(UA_Server *server, UA_NodeId identifier,
UA_UInt64 callbackId, UA_Double interval_ms,
UA_DateTime *baseTime, UA_TimerPolicy timerPolicy);
void (*removeCustomCallback)(UA_Server *server, UA_NodeId identifier, UA_UInt64 callbackId);
} UA_PubSub_CallbackLifecycle;
/**
* WriterGroup
* -----------
* All WriterGroups are created within a PubSubConnection and automatically
* deleted if the connection is removed. The WriterGroup is primary used as
* container for :ref:`dsw` and network message settings. The WriterGroup can be
* imagined as producer of the network messages. The creation of network
* messages is controlled by parameters like the publish interval, which is e.g.
* contained in the WriterGroup. */
typedef enum {
UA_PUBSUB_ENCODING_BINARY,
UA_PUBSUB_ENCODING_JSON,
UA_PUBSUB_ENCODING_UADP
} UA_PubSubEncodingType;
/**
* WriterGroup
* -----------
* The message publishing can be configured for realtime requirements. The RT-levels
* go along with different requirements. The below listed levels can be configured:
*
* UA_PUBSUB_RT_NONE -
* ---> Description: Default "none-RT" Mode
* ---> Requirements: -
* ---> Restrictions: -
* UA_PUBSUB_RT_DIRECT_VALUE_ACCESS (Preview - not implemented)
* ---> Description: Normally, the latest value for each DataSetField is read out of the information model. Within this RT-mode, the
* value source of each field configured as static pointer to an DataValue. The publish cycle won't use call the server read function.
* ---> Requirements: All fields must be configured with a 'staticValueSource'.
* ---> Restrictions: -
* UA_PUBSUB_RT_FIXED_LENGTH (Preview - not implemented)
* ---> Description: All DataSetFields have a known, non-changing length. The server will pre-generate some
* buffers and use only memcopy operations to generate requested PubSub packages.
* ---> Requirements: DataSetFields with variable size cannot be used within this mode.
* ---> Restrictions: The configuration must be frozen and changes are not allowed while the WriterGroup is 'Operational'.
* UA_PUBSUB_RT_DETERMINISTIC (Preview - not implemented)
* ---> Description: -
* ---> Requirements: -
* ---> Restrictions: -
*
* WARNING! For hard real time requirements the underlying system must be rt-capable.
*
*/
typedef enum {
UA_PUBSUB_RT_NONE = 0,
UA_PUBSUB_RT_DIRECT_VALUE_ACCESS = 1,
UA_PUBSUB_RT_FIXED_SIZE = 2,
UA_PUBSUB_RT_DETERMINISTIC = 4,
} UA_PubSubRTLevel;
typedef struct {
UA_String name;
UA_Boolean enabled;
UA_UInt16 writerGroupId;
UA_Duration publishingInterval;
UA_Double keepAliveTime;
UA_Byte priority;
UA_ExtensionObject transportSettings;
UA_ExtensionObject messageSettings;
size_t groupPropertiesSize;
UA_KeyValuePair *groupProperties;
UA_PubSubEncodingType encodingMimeType;
/* PubSub Manager Callback */
UA_PubSub_CallbackLifecycle pubsubManagerCallback;
/* non std. config parameter. maximum count of embedded DataSetMessage in
* one NetworkMessage */
UA_UInt16 maxEncapsulatedDataSetMessageCount;
/* non std. field */
UA_PubSubRTLevel rtLevel;
/* Message are encrypted if a SecurityPolicy is configured and the
* securityMode set accordingly. The symmetric key is a runtime information
* and has to be set via UA_Server_setWriterGroupEncryptionKey. */
UA_MessageSecurityMode securityMode; /* via the UA_WriterGroupDataType */
#ifdef UA_ENABLE_PUBSUB_ENCRYPTION
UA_PubSubSecurityPolicy *securityPolicy;
#endif
} UA_WriterGroupConfig;
void UA_EXPORT
UA_WriterGroupConfig_clear(UA_WriterGroupConfig *writerGroupConfig);
/* Add a new WriterGroup to an existing Connection */
UA_StatusCode UA_EXPORT
UA_Server_addWriterGroup(UA_Server *server, const UA_NodeId connection,
const UA_WriterGroupConfig *writerGroupConfig,
UA_NodeId *writerGroupIdentifier);
/* Returns a deep copy of the config */
UA_StatusCode UA_EXPORT
UA_Server_getWriterGroupConfig(UA_Server *server, const UA_NodeId writerGroup,
UA_WriterGroupConfig *config);
UA_StatusCode UA_EXPORT
UA_Server_updateWriterGroupConfig(UA_Server *server, UA_NodeId writerGroupIdentifier,
const UA_WriterGroupConfig *config);
/* Get state of WriterGroup */
UA_StatusCode UA_EXPORT
UA_Server_WriterGroup_getState(UA_Server *server, UA_NodeId writerGroupIdentifier,
UA_PubSubState *state);
UA_StatusCode UA_EXPORT UA_THREADSAFE
UA_Server_removeWriterGroup(UA_Server *server, const UA_NodeId writerGroup);
UA_StatusCode UA_EXPORT
UA_Server_freezeWriterGroupConfiguration(UA_Server *server, const UA_NodeId writerGroup);
UA_StatusCode UA_EXPORT
UA_Server_unfreezeWriterGroupConfiguration(UA_Server *server, const UA_NodeId writerGroup);
UA_StatusCode UA_EXPORT
UA_Server_setWriterGroupOperational(UA_Server *server, const UA_NodeId writerGroup);
UA_StatusCode UA_EXPORT
UA_Server_setWriterGroupDisabled(UA_Server *server, const UA_NodeId writerGroup);
#ifdef UA_ENABLE_PUBSUB_ENCRYPTION
/* Set the group key for the message encryption */
UA_StatusCode UA_EXPORT
UA_Server_setWriterGroupEncryptionKeys(UA_Server *server, const UA_NodeId writerGroup,
UA_UInt32 securityTokenId,
const UA_ByteString signingKey,
const UA_ByteString encryptingKey,
const UA_ByteString keyNonce);
#endif
/**
* .. _dsw:
*
* DataSetWriter
* -------------
* The DataSetWriters are the glue between the WriterGroups and the
* PublishedDataSets. The DataSetWriter contain configuration parameters and
* flags which influence the creation of DataSet messages. These messages are
* encapsulated inside the network message. The DataSetWriter must be linked
* with an existing PublishedDataSet and be contained within a WriterGroup. */
typedef struct {
UA_String name;
UA_UInt16 dataSetWriterId;
UA_DataSetFieldContentMask dataSetFieldContentMask;
UA_UInt32 keyFrameCount;
UA_ExtensionObject messageSettings;
UA_ExtensionObject transportSettings;
UA_String dataSetName;
size_t dataSetWriterPropertiesSize;
UA_KeyValuePair *dataSetWriterProperties;
} UA_DataSetWriterConfig;
void UA_EXPORT
UA_DataSetWriterConfig_clear(UA_DataSetWriterConfig *pdsConfig);
/* Add a new DataSetWriter to an existing WriterGroup. The DataSetWriter must be
* coupled with a PublishedDataSet on creation.
*
* Part 14, 7.1.5.2.1 defines: The link between the PublishedDataSet and
* DataSetWriter shall be created when an instance of the DataSetWriterType is
* created. */
UA_StatusCode UA_EXPORT
UA_Server_addDataSetWriter(UA_Server *server,
const UA_NodeId writerGroup, const UA_NodeId dataSet,
const UA_DataSetWriterConfig *dataSetWriterConfig,
UA_NodeId *writerIdentifier);
/* Returns a deep copy of the config */
UA_StatusCode UA_EXPORT
UA_Server_getDataSetWriterConfig(UA_Server *server, const UA_NodeId dsw,
UA_DataSetWriterConfig *config);
/* Get state of DataSetWriter */
UA_StatusCode UA_EXPORT
UA_Server_DataSetWriter_getState(UA_Server *server, UA_NodeId dataSetWriterIdentifier,
UA_PubSubState *state);
UA_StatusCode UA_EXPORT
UA_Server_removeDataSetWriter(UA_Server *server, const UA_NodeId dsw);
/**
* SubscribedDataSet
* -----------------
* SubscribedDataSet describes the processing of the received DataSet.
* SubscribedDataSet defines which field in the DataSet is mapped to which
* Variable in the OPC UA Application. SubscribedDataSet has two sub-types
* called the TargetVariablesType and SubscribedDataSetMirrorType.
* SubscribedDataSetMirrorType is currently not supported. SubscribedDataSet is
* set to TargetVariablesType and then the list of target Variables are created
* in the Subscriber AddressSpace. TargetVariables are a list of variables that
* are to be added in the Subscriber AddressSpace. It defines a list of Variable
* mappings between received DataSet fields and added Variables in the
* Subscriber AddressSpace. */
/* SubscribedDataSetDataType Definition */
typedef enum {
UA_PUBSUB_SDS_TARGET,
UA_PUBSUB_SDS_MIRROR
} UA_SubscribedDataSetEnumType;
typedef struct {
/* Standard-defined FieldTargetDataType */
UA_FieldTargetDataType targetVariable;
/* If realtime-handling is required, set this pointer non-NULL and it will be used
* to memcpy the value instead of using the Write service.
* If the beforeWrite method pointer is set, it will be called before a memcpy update
* to the value. But param externalDataValue already contains the new value.
* If the afterWrite method pointer is set, it will be called after a memcpy update
* to the value. */
UA_DataValue **externalDataValue;
void *targetVariableContext; /* user-defined pointer */
void (*beforeWrite)(UA_Server *server,
const UA_NodeId *readerIdentifier,
const UA_NodeId *readerGroupIdentifier,
const UA_NodeId *targetVariableIdentifier,
void *targetVariableContext,
UA_DataValue **externalDataValue);
void (*afterWrite)(UA_Server *server,
const UA_NodeId *readerIdentifier,
const UA_NodeId *readerGroupIdentifier,
const UA_NodeId *targetVariableIdentifier,
void *targetVariableContext,
UA_DataValue **externalDataValue);
} UA_FieldTargetVariable;
typedef struct {
size_t targetVariablesSize;
UA_FieldTargetVariable *targetVariables;
} UA_TargetVariables;
/* Return Status Code after creating TargetVariables in Subscriber AddressSpace */
UA_StatusCode UA_EXPORT
UA_Server_DataSetReader_createTargetVariables(UA_Server *server,
UA_NodeId dataSetReaderIdentifier,
size_t targetVariablesSize,
const UA_FieldTargetVariable *targetVariables);
/* To Do:Implementation of SubscribedDataSetMirrorType
* UA_StatusCode
* A_PubSubDataSetReader_createDataSetMirror(UA_Server *server, UA_NodeId dataSetReaderIdentifier,
* UA_SubscribedDataSetMirrorDataType* mirror) */
/**
* DataSetReader
* -------------
* DataSetReader can receive NetworkMessages with the DataSetMessage
* of interest sent by the Publisher. DataSetReaders represent
* the configuration necessary to receive and process DataSetMessages
* on the Subscriber side. DataSetReader must be linked with a
* SubscribedDataSet and be contained within a ReaderGroup. */
/* Parameters for PubSubSecurity */
typedef struct {
UA_Int32 securityMode; /* placeholder datatype 'MessageSecurityMode' */
UA_String securityGroupId;
size_t keyServersSize;
UA_Int32 *keyServers;
} UA_PubSubSecurityParameters;
typedef enum {
UA_PUBSUB_RT_UNKNOWN = 0,
UA_PUBSUB_RT_VARIANT = 1,
UA_PUBSUB_RT_DATA_VALUE = 2,
UA_PUBSUB_RT_RAW = 4,
} UA_PubSubRtEncoding;
/* Parameters for PubSub DataSetReader Configuration */
typedef struct {
UA_String name;
UA_Variant publisherId;
UA_UInt16 writerGroupId;
UA_UInt16 dataSetWriterId;
UA_DataSetMetaDataType dataSetMetaData;
UA_DataSetFieldContentMask dataSetFieldContentMask;
UA_Double messageReceiveTimeout;
UA_PubSubSecurityParameters securityParameters;
UA_ExtensionObject messageSettings;
UA_ExtensionObject transportSettings;
UA_SubscribedDataSetEnumType subscribedDataSetType;
/* TODO UA_SubscribedDataSetMirrorDataType subscribedDataSetMirror */
union {
UA_TargetVariables subscribedDataSetTarget;
// UA_SubscribedDataSetMirrorDataType subscribedDataSetMirror;
} subscribedDataSet;
/* non std. fields */
UA_PubSubRtEncoding expectedEncoding;
} UA_DataSetReaderConfig;
/* Update configuration to the dataSetReader */
UA_StatusCode UA_EXPORT
UA_Server_DataSetReader_updateConfig(UA_Server *server, UA_NodeId dataSetReaderIdentifier,
UA_NodeId readerGroupIdentifier,
const UA_DataSetReaderConfig *config);
/* Get configuration of the dataSetReader */
UA_StatusCode UA_EXPORT
UA_Server_DataSetReader_getConfig(UA_Server *server, UA_NodeId dataSetReaderIdentifier,
UA_DataSetReaderConfig *config);
/* Get state of DataSetReader */
UA_StatusCode UA_EXPORT
UA_Server_DataSetReader_getState(UA_Server *server, UA_NodeId dataSetReaderIdentifier,
UA_PubSubState *state);
/**
* ReaderGroup
* -----------
* ReaderGroup is used to group a list of DataSetReaders. All ReaderGroups are
* created within a PubSubConnection and automatically deleted if the connection
* is removed. All network message related filters are only available in the
* DataSetReader.
*
* The RT-levels go along with different requirements. The below listed levels
* can be configured for a ReaderGroup.
*
* - UA_PUBSUB_RT_NONE: RT applied to this level
* - PUBSUB_CONFIG_FASTPATH_FIXED_OFFSETS: Extends PubSub RT functionality and
* implements fast path message decoding in the Subscriber. Uses a buffered
* network message and only decodes the necessary offsets stored in an offset
* buffer. */
/* ReaderGroup configuration */
typedef struct {
UA_String name;
UA_PubSubSecurityParameters securityParameters;
/* PubSub Manager Callback */
UA_PubSub_CallbackLifecycle pubsubManagerCallback;
/* non std. field */
UA_Duration subscribingInterval; // Callback interval for subscriber: set the least publishingInterval value of all DSRs in this RG
UA_Boolean enableBlockingSocket; // To enable or disable blocking socket option
UA_UInt32 timeout; // Timeout for receive to wait for the packets
UA_PubSubRTLevel rtLevel;
size_t groupPropertiesSize;
UA_KeyValuePair *groupProperties;
/* Messages are decrypted if a SecurityPolicy is configured and the
* securityMode set accordingly. The symmetric key is a runtime information
* and has to be set via UA_Server_setReaderGroupEncryptionKey. */
UA_MessageSecurityMode securityMode;
#ifdef UA_ENABLE_PUBSUB_ENCRYPTION
UA_PubSubSecurityPolicy *securityPolicy;
#endif
} UA_ReaderGroupConfig;
void UA_EXPORT
UA_ReaderGroupConfig_clear(UA_ReaderGroupConfig *readerGroupConfig);
/* Add DataSetReader to the ReaderGroup */
UA_StatusCode UA_EXPORT
UA_Server_addDataSetReader(UA_Server *server, UA_NodeId readerGroupIdentifier,
const UA_DataSetReaderConfig *dataSetReaderConfig,
UA_NodeId *readerIdentifier);
/* Remove DataSetReader from ReaderGroup */
UA_StatusCode UA_EXPORT
UA_Server_removeDataSetReader(UA_Server *server, UA_NodeId readerIdentifier);
/* To Do: Update Configuration of ReaderGroup
* UA_StatusCode UA_EXPORT
* UA_Server_ReaderGroup_updateConfig(UA_Server *server, UA_NodeId readerGroupIdentifier,
* const UA_ReaderGroupConfig *config);
*/
/* Get configuraiton of ReaderGroup */
UA_StatusCode UA_EXPORT
UA_Server_ReaderGroup_getConfig(UA_Server *server, UA_NodeId readerGroupIdentifier,
UA_ReaderGroupConfig *config);
/* Get state of ReaderGroup */
UA_StatusCode UA_EXPORT
UA_Server_ReaderGroup_getState(UA_Server *server, UA_NodeId readerGroupIdentifier,
UA_PubSubState *state);
/* Add ReaderGroup to the created connection */
UA_StatusCode UA_EXPORT
UA_Server_addReaderGroup(UA_Server *server, UA_NodeId connectionIdentifier,
const UA_ReaderGroupConfig *readerGroupConfig,
UA_NodeId *readerGroupIdentifier);
/* Remove ReaderGroup from connection */
UA_StatusCode UA_EXPORT UA_THREADSAFE
UA_Server_removeReaderGroup(UA_Server *server, UA_NodeId groupIdentifier);
UA_StatusCode UA_EXPORT
UA_Server_freezeReaderGroupConfiguration(UA_Server *server, const UA_NodeId readerGroupId);
UA_StatusCode UA_EXPORT
UA_Server_unfreezeReaderGroupConfiguration(UA_Server *server, const UA_NodeId readerGroupId);
UA_StatusCode UA_EXPORT
UA_Server_setReaderGroupOperational(UA_Server *server, const UA_NodeId readerGroupId);
UA_StatusCode UA_EXPORT
UA_Server_setReaderGroupDisabled(UA_Server *server, const UA_NodeId readerGroupId);
#ifdef UA_ENABLE_PUBSUB_ENCRYPTION
/* Set the group key for the message encryption */
UA_StatusCode UA_EXPORT
UA_Server_setReaderGroupEncryptionKeys(UA_Server *server, UA_NodeId readerGroup,
UA_UInt32 securityTokenId,
UA_ByteString signingKey,
UA_ByteString encryptingKey,
UA_ByteString keyNonce);
#endif
#endif /* UA_ENABLE_PUBSUB */
_UA_END_DECLS
#endif /* UA_SERVER_PUBSUB_H */