ANSI C Based OPC UA Client/Server SDK  1.8.3.398
Provider Subscription Mechanism

The SDK simplifies the implementation of subscriptions tremendously. The interaction between Server and the Provider is done through three methods of the Provider Interface:

and two functions of the SDK:

This interface is designed to handle two different kinds of providers:

The UA Server hides the complexity of managing multiple subscriptions and monitored items. It uses only one “Provider Subscription” to retrieve updates from a provider. The provider only has to take care about updating this one subscription considering the individual update rate of the items.

Function Overview

AddItem and RemoveItem

AddItem and RemoveItem work synchronously and are adding or removing single items respectively. These functions should return immediately and should not call any long blocking functions. If adding an item is a complicated procedure that you don’t want to do for single items you should consider implementing a Complex Provider.

Subscribe

Subscribe works asynchronously. This means you can start a long running operation but Subscribe returns immediately. When your long running operation is finished you can signal the completion of this operation by calling the UaServer_SubscribeComplete function.

NewItemValue

If you retrieve new data from your underlying system you should call the UaServer_NewItemValue function of the SDK to inform the server about this data change. This triggers the server to queue the new value into the monitored item queue. On the next publish cycle this value will be sent to the OPC UA Clients that are monitoring that item.

Modify Monitored Items

A ModifyMonitoredItems call of a client leads to following call order by the SDK:

  1. AddItem of a new monitored item using the new parameters
  2. RemoveItem for the item with the previous parameters, only if AddItem succeeded
  3. Subscribe

Depending on the provider implementation it is possible that data changes get lost while modifying, e.g. if the underlying system requires to unsubscribe and subscribe all items again in order to modify them.

Simple Provider

A simple provider is one where it is very easy to add and remove items without influencing the rest of the subscription. Typical cases of such providers are in-memory providers like the Demo Provider that comes with the SDK, or providers where the underlying protocol supports adding and removing of individual items.

In this case you only have to implement the AddItem and RemoveItem functions and Subscribe can be an empty method that does nothing than calling the UaServer_SubscribeComplete function.

simple_provider_sequence.png
Simple Provider Sequence

Complex Provider

For some protocols adding and removing of items are very expensive operations. For example sometimes it is necessary to remove the complete subscription and to create a new one. In this case you have to implement all three functions AddItem, RemoveItem and Subscribe.

In this scenario AddItem and RemoveItem should just mark the subscription as “dirty” and keep account of the changes. In this scenario AddItem and RemoveItem are called multiple times from the server until all changes are done. Then Subscribe is called to finalize the changes. This is the place where you now can create a new subscription to the underlying system and clean the “dirty” flag of your subscription.

complex_provider_sequence.png
Complex Provider Sequence