/// <summary>
/// Applies any changes to the subscriptions.
/// </summary>
private void ApplyChanges(Dictionary <string, HdaSubscribeAttributeRequest> requests, bool initialUpdateRequired)
{
List <HdaSubscribeAttributeRequest> requestsToRemove = null;
lock (m_lock)
{
// update existing requests.
foreach (KeyValuePair <string, HdaSubscribeAttributeRequest> entry in requests)
{
HdaSubscribeAttributeRequest request = entry.Value;
// remove unused requests.
if (request.MonitoredItems == null || request.MonitoredItems.Count == 0)
{
if (requestsToRemove == null)
{
requestsToRemove = new List <HdaSubscribeAttributeRequest>();
}
requestsToRemove.Add(entry.Value);
continue;
}
request.ChangesComplete(m_configuration.AttributeSamplingInterval);
}
// remove deleted requests from dictionary.
if (requestsToRemove != null)
{
for (int ii = 0; ii < requestsToRemove.Count; ii++)
{
m_requests.Remove(requestsToRemove[ii].ItemId);
}
}
// check if the attribute scanner needs to be stopped/started.
if (m_attributeScanTimer == null)
{
if (m_requests.Count > 0)
{
m_attributeScanTimer = new Timer(OnScanAttributes, null, m_configuration.AttributeSamplingInterval, m_configuration.AttributeSamplingInterval);
}
}
else
{
if (m_requests.Count == 0)
{
m_attributeScanTimer.Dispose();
m_attributeScanTimer = null;
}
}
}
// release any unused handles.
if (requestsToRemove != null)
{
ComHdaClientManager system = (ComHdaClientManager)m_context.SystemHandle;
ComHdaClient client = (ComHdaClient)system.SelectClient(m_context, false);
ReleaseHandles(client, requestsToRemove);
}
// send initial update.
if (initialUpdateRequired)
{
DoScan(requests, true);
}
}