private void OnStateVariableChanged(DvStateVariable variable)
        {
            lock (_serverData.SyncObj)
            {
                // Unicast event notifications
                DvService service = variable.ParentService;
                foreach (EndpointConfiguration config in _serverData.UPnPEndPoints)
                {
                    foreach (EventSubscription subscription in config.EventSubscriptions)
                    {
                        if (subscription.Service == service && !subscription.IsDisposed)
                        {
                            subscription.StateVariableChanged(variable);
                        }
                    }
                }

                // Multicast event notifications
                if (variable.Multicast)
                {
                    EventingState eventingState = _serverData.GetMulticastEventKey(variable.ParentService);
                    if (eventingState.EventKey == 0)
                    {
                        // Avoid sending "normal" change events before the initial event was sent
                        return;
                    }
                    eventingState.ModerateChangeEvent(variable);
                    ScheduleMulticastEvents();
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Called when a state variable has changed its value.
 /// </summary>
 /// <remarks>
 /// This method will check if the variable is evented. If not, nothing happens. If yes, and the variable
 /// is moderated in rate or minimum change, it will be scheduled to be evented later, or will
 /// be evented at once, depending on the moderation.
 /// </remarks>
 /// <param name="variable">The variable which changed its value.</param>
 public void StateVariableChanged(DvStateVariable variable)
 {
     if (!variable.SendEvents)
     {
         return;
     }
     lock (_serverData.SyncObj)
     {
         // Only send event if:
         // - Subscription is not expired
         // - Initial event was already sent
         if (DateTime.Now > Expiration)
         {
             Dispose();
             return;
         }
         if (_eventingState.EventKey == 0)
         {
             // Avoid sending "normal" change events before the initial event was sent
             return;
         }
         _eventingState.ModerateChangeEvent(variable);
     }
     // Outside the lock
     ScheduleEvents();
 }