Skip to content

Commit

Permalink
Fixes #703.
Browse files Browse the repository at this point in the history
Fix regression caused by #656. Add a MonitoredItem constructor to allow keeping the ClientHandle of the template. (#704)
  • Loading branch information
AlinMoldovean authored Apr 17, 2019
1 parent 0a6b1cb commit 40db29f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
22 changes: 18 additions & 4 deletions SampleApplications/SDK/Opc.Ua.Client/MonitoredItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,22 @@ public MonitoredItem(MonitoredItem template) : this(template, false)
/// </summary>
/// <param name="template">The template used to specify the monitoring parameters.</param>
/// <param name="copyEventHandlers">if set to <c>true</c> the event handlers are copied.</param>
public MonitoredItem(MonitoredItem template, bool copyEventHandlers)
public MonitoredItem(MonitoredItem template, bool copyEventHandlers) : this(template, copyEventHandlers, false)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="MonitoredItem"/> class.
/// </summary>
/// <param name="template">The template used to specify the monitoring parameters.</param>
/// <param name="copyEventHandlers">if set to <c>true</c> the event handlers are copied.</param>
/// <param name="copyClientHandle">if set to <c>true</c> the clientHandle is of the template copied.</param>
public MonitoredItem(MonitoredItem template, bool copyEventHandlers, bool copyClientHandle)
{
Initialize();

if (template != null)
{
{
string displayName = template.DisplayName;

if (displayName != null)
Expand All @@ -103,7 +113,6 @@ public MonitoredItem(MonitoredItem template, bool copyEventHandlers)
}
}

m_clientHandle = template.m_clientHandle; // keep the same clientHandle since it uniquely identifies the monitored item for the subscriber
m_handle = template.m_handle;
m_displayName = Utils.Format("{0} {1}", displayName, m_clientHandle);
m_startNodeId = template.m_startNodeId;
Expand All @@ -123,6 +132,11 @@ public MonitoredItem(MonitoredItem template, bool copyEventHandlers)
m_Notification = template.m_Notification;
}

if (copyClientHandle)
{
m_clientHandle = template.m_clientHandle;
}

// this ensures the state is consistent with the node class.
NodeClass = template.m_nodeClass;
}
Expand Down
11 changes: 5 additions & 6 deletions SampleApplications/SDK/Opc.Ua.Client/Subscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Subscription(Subscription template, bool copyEventHandlers)
Initialize();

if (template != null)
{
{
string displayName = template.DisplayName;

if (String.IsNullOrEmpty(displayName))
Expand Down Expand Up @@ -110,19 +110,18 @@ public Subscription(Subscription template, bool copyEventHandlers)
if (copyEventHandlers)
{
m_StateChanged = template.m_StateChanged;
m_PublishStatusChanged = template.m_PublishStatusChanged;
m_PublishStatusChanged = template.m_PublishStatusChanged;
m_fastDataChangeCallback = template.m_fastDataChangeCallback;
m_fastEventCallback = template.m_fastEventCallback;
}

// copy the list of monitored items.
foreach (MonitoredItem monitoredItem in template.MonitoredItems)
{
MonitoredItem clone = new MonitoredItem(monitoredItem, copyEventHandlers);
clone.Subscription = this;
MonitoredItem clone = new MonitoredItem(monitoredItem, copyEventHandlers, true);
clone.DisplayName = monitoredItem.DisplayName;
m_monitoredItems.Add(clone.ClientHandle, clone);
}
AddItem(clone);
}
}
}

Expand Down

0 comments on commit 40db29f

Please sign in to comment.