/// <summary> /// Sets up a broadcast signal key and subscription list /// </summary> /// <typeparam name="S">Signal Type</typeparam> /// <typeparam name="R">Response Type</typeparam> /// <param name="group">Group</param> /// <param name="signalKey">The returned signal key</param> /// <param name="subscriptionList">The return subscription list</param> /// <returns>True if successful</returns> private bool _PreBroadcast <S, R>(long?group, out SignalKey signalKey, out IList subscriptionList) { signalKey = new SignalKey(typeof(S), typeof(R), group); subscriptionList = null; // If the manager is not active ignore the broadcast if (!_active) { return(false); } // Make sure that this broadcast is not already occuring, such as a // nested call. If it is we need to abort or the stack will overflow in // recursion. if (_broadcastingKeys.Contains(signalKey)) { Debug.LogError("Circular broadcast will result in an overflow. Aborting."); return(false); } if (_logInfo) { Debug.Log(string.Format("Signaler::Broadcast signal {0}", signalKey)); } // Look for the list of subscriptions based on the signal type if (_subscriptions.TryGetValue(signalKey, out subscriptionList)) { _broadcastingKeys.Add(signalKey); return(true); } else { // No subscriptions for this signal if (_logNoSubscriptions) { Debug.LogWarning(string.Format("Signaler::No subscriptions for {0}!", signalKey)); } return(false); } }
/// <summary> /// Updates the group for a subscription. This should not be called directly, /// instead you should set the subscription's Group parameter, which will then /// call this method. /// </summary> /// <typeparam name="S">Signal type</typeparam> /// <typeparam name="R">Response type</typeparam> /// <param name="subscription">The subscription to alter</param> /// <param name="newGroup">The new group of the subscription</param> public bool _QueueUpdateGroup <S, R>(ISubscription subscription, long?newGroup) { // Check to see if this subscription is currently being broadcast. // If so, we need to queue the group update for after the broadcast if (_broadcastingKeys.Contains(subscription._SignalKey)) { _hasQueuedUpdate = true; _queuedGroupUpdates.Add(subscription); return(false); } // Remove the subscription from its list _QueueUnSubscribe(subscription); // Add the subscription to its new list _AddSubscription <S, R>(subscription, newGroup); return(true); }
/// <summary> /// Updates the order of the subscription. This should not be called directly, /// instead you should set the subscription's Order parameter, which will then /// call this method. /// </summary> /// <typeparam name="S">Signal type</typeparam> /// <typeparam name="R">Response type</typeparam> /// <param name="subscription">The subscription to alter</param> /// <param name="newOrder">The new order to assign</param> public bool _QueueUpdateOrder <S, R>(ISubscription subscription, long newOrder) { // Check to see if this subscription is currently being broadcast. // If so, we need to queue the order update for after the broadcast if (_broadcastingKeys.Contains(subscription._SignalKey)) { _hasQueuedUpdate = true; _queuedOrderUpdates.Add(subscription); return(false); } // Remove the subscription from its list _QueueUnSubscribe(subscription); // Add the subscription back with the proper order _AddSubscription <S, R>(subscription, subscription.Group); return(true); }
// TODO: lock down how to move subscriptions (group, order) and delete them so // that nested broadcasts do not try to call subscriptions that are already marked disposed. /// <summary> /// Removes a subscription from the signal manager. This should not be called directly, /// instead it is called from a subscription's dispose method. /// </summary> /// <typeparam name="S">Signal type</typeparam> /// <typeparam name="R">Response type</typeparam> /// <param name="subscription">The subscription to remove</param> public bool _QueueUnSubscribe(ISubscription subscription) { // Check to see if this subscription is currently being broadcast. // If so, we need to queue the unsubscribe for after the broadcast if (_broadcastingKeys.Contains(subscription._SignalKey)) { _hasQueuedUpdate = true; _queuedUnSubscribes.Add(subscription); return(false); } // Remove the subscription from its list if (subscription != null && subscription._SubscriptionList != null) { subscription._SubscriptionList.Remove(subscription); subscription._SubscriptionList = null; } return(true); }