public ServiceResult SubscribeToEvents(
OperationContext context,
object sourceId,
uint subscriptionId,
IEventMonitoredItem monitoredItem,
bool unsubscribe)
{
if (context == null) throw new ArgumentNullException("context");
if (sourceId == null) throw new ArgumentNullException("sourceId");
if (monitoredItem == null) throw new ArgumentNullException("monitoredItem");
try
{
m_lock.Enter();
// validate the node.
NodeMetadata metadata = GetNodeMetadata(context, sourceId, BrowseResultMask.NodeClass);
if (metadata == null)
{
return StatusCodes.BadNodeIdUnknown;
}
// validate the node class.
if (((metadata.NodeClass & NodeClass.Object | NodeClass.View)) == 0)
{
return StatusCodes.BadNotSupported;
}
// check that it supports events.
if ((metadata.EventNotifier & EventNotifiers.SubscribeToEvents) == 0)
{
return StatusCodes.BadNotSupported;
}
#if LEGACY_CORENODEMANAGER
// subscribe to all notifiers below the notifier.
SubscribeToEvents(
context,
metadata.Handle as ILocalNode,
subscriptionId,
monitoredItem,
unsubscribe);
#endif
return ServiceResult.Good;
}
finally
{
m_lock.Exit();
}
}