public NodeId CreateSubscriptionDiagnostics(
ServerSystemContext systemContext,
SubscriptionDiagnosticsDataType diagnostics,
NodeValueSimpleEventHandler updateCallback)
{
NodeId nodeId = null;
lock (Lock)
{
// check if diagnostics have been enabled.
if (!m_diagnosticsEnabled)
{
return null;
}
SubscriptionDiagnosticsState diagnosticsNode = new SubscriptionDiagnosticsState(null);
// create a new instance and assign ids.
nodeId = CreateNode(
systemContext,
null,
ReferenceTypeIds.HasComponent,
new QualifiedName(diagnostics.SubscriptionId.ToString()),
diagnosticsNode);
// add reference to subscription array.
diagnosticsNode.AddReference(
ReferenceTypeIds.HasComponent,
true,
VariableIds.Server_ServerDiagnostics_SubscriptionDiagnosticsArray);
// wrap diagnostics in a thread safe object.
SubscriptionDiagnosticsValue diagnosticsValue = new SubscriptionDiagnosticsValue(diagnosticsNode, diagnostics, Lock);
diagnosticsValue.CopyPolicy = Opc.Ua.VariableCopyPolicy.Never;
diagnosticsValue.OnBeforeRead = OnBeforeReadDiagnostics;
// must ensure the first update gets sent.
diagnosticsValue.Value = null;
diagnosticsValue.Error = StatusCodes.BadWaitingForInitialData;
m_subscriptions.Add(new SubscriptionDiagnosticsData(diagnosticsValue, updateCallback));
// add reference from subscription array.
SubscriptionDiagnosticsArrayState array = (SubscriptionDiagnosticsArrayState)FindPredefinedNode(
VariableIds.Server_ServerDiagnostics_SubscriptionDiagnosticsArray,
typeof(SubscriptionDiagnosticsArrayState));
if (array != null)
{
array.AddReference(ReferenceTypeIds.HasComponent, false, diagnosticsNode.NodeId);
}
// add reference to session subscription array.
diagnosticsNode.AddReference(
ReferenceTypeIds.HasComponent,
true,
diagnostics.SessionId);
// add reference from session subscription array.
SessionDiagnosticsObjectState sessionNode = (SessionDiagnosticsObjectState)FindPredefinedNode(
diagnostics.SessionId,
typeof(SessionDiagnosticsObjectState));
if (sessionNode != null)
{
// add reference from subscription array.
array = (SubscriptionDiagnosticsArrayState)sessionNode.CreateChild(
systemContext,
BrowseNames.SubscriptionDiagnosticsArray);
if (array != null)
{
array.AddReference(ReferenceTypeIds.HasComponent, false, diagnosticsNode.NodeId);
}
}
// send initial update.
DoScan(true);
}
return nodeId;
}