Exemple #1
0
        /// <summary>
        /// Add the subscription to the list
        /// </summary>
        /// <typeparam name="S">Signal type</typeparam>
        /// <typeparam name="R">Response type</typeparam>
        /// <param name="subscription">Subscription to add</param>
        /// <param name="group">The group to use</param>
        private void _AddSubscription <S, R>(ISubscription subscription, long?group)
        {
            var   responseType = typeof(R);
            var   signalKey    = new SignalKey(typeof(S), responseType, group);
            IList subscriptionList;

            // Set the subscriptions signal key
            subscription._SignalKey = signalKey;

            // If the signal type is not found, then create a new signal type in the dictionary
            if (!_subscriptions.TryGetValue(signalKey, out subscriptionList))
            {
                // Set up the appropriate subscription list based on whether it is a message or request
                if (responseType == typeof(NoResponse))
                {
                    subscriptionList = new LiteList <MessageSubscription <S> >();
                }
                else
                {
                    subscriptionList = new LiteList <RequestSubscription <S, R> >();
                }
                subscriptionList.Add(subscription);

                _subscriptions.Add(signalKey, subscriptionList);
            }
            else
            {
                // The signal type / group was found, so we insert the subscription
                _InsertSubscription(subscriptionList, subscription);
            }

            // Set the subscription's list
            subscription._SubscriptionList = subscriptionList;
        }
Exemple #2
0
        /// <summary>
        /// Searches for a subscription with the proper subscriber, request action, and group
        /// </summary>
        /// <typeparam name="S">Signal Type</typeparam>
        /// <typeparam name="R">Response Type</typeparam>
        /// <param name="group">Group</param>
        /// <returns>subscription if found</returns>
        private ISubscription _GetSubscription <S, R>(ISubscriber subscriber, RequestAction <S, R> action,
                                                      long?group = null)
        {
            var   signalKey = new SignalKey(typeof(S), typeof(R), group);
            IList subscriptionList;

            // If the signal type is not found, then create a new signal type in the dictionary
            if (_subscriptions.TryGetValue(signalKey, out subscriptionList))
            {
                // cast the subscription list to the appropriate type
                LiteList <RequestSubscription <S, R> > typeList = (LiteList <RequestSubscription <S, R> >)subscriptionList;

                // search through the subscriptions for one that has the correct
                // subscriber and action
                for (var i = 0; i < typeList.Count; i++)
                {
                    if (typeList[i]._Subscriber == subscriber &&
                        typeList[i].Action == action
                        )
                    {
                        return(typeList[i]);
                    }
                }
            }

            return(null);
        }
Exemple #3
0
        /// <summary>
        /// Takes the broadcast off the current stack and processes any queued updates
        /// </summary>
        /// <param name="signalKey"></param>
        private void _PostBroadcast(SignalKey signalKey)
        {
            _broadcastingKeys.Remove(signalKey);

            if (_broadcastingKeys.Count == 0 && _hasQueuedUpdate)
            {
                _ProcessQueuedUpdates();
            }
        }
Exemple #4
0
 public bool Equals(SignalKey obj)
 {
     if (ReferenceEquals(null, obj))
     {
         return(false);
     }
     if (ReferenceEquals(this, obj))
     {
         return(true);
     }
     return(Equals(obj.SignalType, SignalType) && Equals(obj.ResponseType, ResponseType) && Equals(obj.Group, Group));
 }
Exemple #5
0
        /// <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);
            }
        }