/// <summary>Removes function that requires a data object from call list of this message</summary>
        public void UnsubscribeToMessage(MessageHeader _messageHeader, SubscriberFunction _subscriberFunction)
        {
            SubscriberList subscriberList = m_subscriberList[(int)_messageHeader];

            subscriberList.m_messageFunction     -= _subscriberFunction;
            m_subscriberList[(int)_messageHeader] = subscriberList;
        }
 /// <summary>Remove single interest to from prefix MessageHeader key.</summary>
 public void RemovePrefixInterest(string _prefix, SubscriberFunction _function)
 {
     if (m_prefixesOfInterest.ContainsKey(_prefix))
     {
         m_prefixesOfInterest[_prefix].Remove(GetPrefixInterest(_prefix, _function));
     }
 }
 /// <summary>Remove single interest to from dynamic MessageHeader key.</summary>
 public void RemoveDynamicInterest(string _messageHeader, SubscriberFunction _function)
 {
     if (m_dynamicMessagesOfInterest.ContainsKey(_messageHeader))
     {
         m_dynamicMessagesOfInterest[_messageHeader].Remove(GetDynamicInterest(_messageHeader, _function));
     }
 }
        /// <summary>Unsubscribe from single use subscription.</summary>
        private void UnsubscribeSingleSubscription(string _messageHeader, SubscriberFunction _messageFunction)
        {
            if (m_useSingle && m_hasSingle)
            {
                string subscriptionKey = _messageHeader + " ~ " + _messageFunction.Method;

                //If in single active subscriptions, unsubscribe from LocalNoticeBoard
                if (m_singleActiveSubscriptions.ContainsKey(subscriptionKey))
                {
                    if (m_singleActiveSubscriptions[subscriptionKey].m_noticeBoard)
                    {
                        m_singleActiveSubscriptions[subscriptionKey].m_noticeBoard.UnsubscribeToMessage(
                            m_singleActiveSubscriptions[subscriptionKey].m_dynamicMessageHeader, _messageFunction,
                            OnRemoveSubscriberList);
                    }
                    else
                    {
                        GlobalNoticeBoard.s_instance.UnsubscribeToMessage(
                            m_singleActiveSubscriptions[subscriptionKey].m_staticMessageHeader, _messageFunction);
                    }

                    MPac_UnsubscribedLocalMessage package = new MPac_UnsubscribedLocalMessage(
                        m_singleActiveSubscriptions[subscriptionKey].m_dynamicMessageHeader,
                        "Local Message: " + m_singleActiveSubscriptions[subscriptionKey].m_dynamicMessageHeader
                        + " ~Unsubscribed", m_singleActiveSubscriptions[subscriptionKey].m_dynamicMessageHeader);
                    m_singleActiveSubscriptions[subscriptionKey].m_unsubscribeFunction?.Invoke(package);
                    m_singleActiveSubscriptions.Remove(subscriptionKey);
                }

                if (m_singleActiveSubscriptions.Count == 0)
                {
                    m_hasSingle = false;
                }
            }
        }
        /// <summary>Gets Solo ActiveSubscription if SubscriptionKey exists.</summary>
        private ActiveSubscription GetSoloSubscription(string _messageHeader, SubscriberFunction _messageFunction)
        {
            string subscriptionKey = _messageHeader + " ~ " + _messageFunction.Method;

            if (m_soloActiveSubscriptions.ContainsKey(subscriptionKey))
            {
                return(m_soloActiveSubscriptions[subscriptionKey]);
            }
            return(null);
        }
 public ActiveSubscription(MessageHeader _messageHeader,
                           SubscriberFunction _subscriberFunction,
                           SubscriberFunction _unsubscribeFunction = null)
 {
     m_noticeBoard          = null;
     m_dynamicMessageHeader = "Global";
     m_staticMessageHeader  = _messageHeader;
     m_subscriberFunction   = _subscriberFunction;
     m_unsubscribeFunction  = _unsubscribeFunction;
 }
 public ActiveSubscription(LocalNoticeBoard _noticeBoard,
                           string _messageHeader, SubscriberFunction _subscriberFunction,
                           SubscriberFunction _unsubscribeFunction = null)
 {
     m_noticeBoard          = _noticeBoard;
     m_dynamicMessageHeader = _messageHeader;
     m_staticMessageHeader  = MessageHeader.Count;
     m_subscriberFunction   = _subscriberFunction;
     m_unsubscribeFunction  = _unsubscribeFunction;
 }
 public Interest(SubscriptionPersistence _persistence,
                 SubscriberFunction _messageFunction,
                 SubscriberFunction _removeFunction      = null,
                 SubscriberFunction _unsubscribeFunction = null)
 {
     m_persistence         = _persistence;
     m_messageFunction     = _messageFunction;
     m_removeFunction      = _removeFunction;
     m_unsubscribeFunction = _unsubscribeFunction;
 }
        /// <summary>Remove single interest to from static MessageHeader key.</summary>
        public void RemoveStaticInterest(MessageHeader _messageHeader, SubscriberFunction _function)
        {
            if (m_staticMessagesOfInterest.ContainsKey(_messageHeader))
            {
                Interest interest = GetStaticInterest(_messageHeader, _function);

                //Must unsubscribe from GlobalNoticeBoard to prevent dangling references
                UnsubscribeGlobalMessage(_messageHeader, interest);
                m_staticMessagesOfInterest[_messageHeader].Remove(interest);
            }
        }
Beispiel #10
0
        /// <summary>Removes function that requires a data object from call list of this message.</summary>
        public void UnsubscribeToMessage(string _messageHeader, SubscriberFunction _subscriberFunction,
                                         SubscriberFunction _removeFunction = null)
        {
            int messageIndex = GetMessageIndex(_messageHeader);

            if (messageIndex != -1)
            {
                SubscriberList subscriberList = m_subscriberList[messageIndex];
                subscriberList.m_messageFunction -= _subscriberFunction;
                subscriberList.m_removeFunction  -= _removeFunction;
                m_subscriberList[messageIndex]    = subscriberList;
            }
        }
        /// <summary>Returns interests from static lists.</summary>
        private Interest GetStaticInterest(MessageHeader _messageHeader, SubscriberFunction _function)
        {
            Interest result = null;

            if (m_staticMessagesOfInterest.ContainsKey(_messageHeader))
            {
                foreach (Interest interest in m_staticMessagesOfInterest[_messageHeader])
                {
                    if (interest.m_messageFunction == _function)
                    {
                        result = interest;
                    }
                }
            }
            return(result);
        }
        /// <summary>Returns interests from prefix lists.</summary>
        private Interest GetPrefixInterest(string _prefix, SubscriberFunction _function)
        {
            Interest result = null;

            if (m_prefixesOfInterest.ContainsKey(_prefix))
            {
                foreach (Interest interest in m_prefixesOfInterest[_prefix])
                {
                    if (interest.m_messageFunction == _function)
                    {
                        result = interest;
                    }
                }
            }
            return(result);
        }
Beispiel #13
0
 public void Unregister(EEventType mEventType, SubscriberFunction mSubscriberFunction)
 {
     FunctionList(mEventType).Remove(mSubscriberFunction);
 }
Beispiel #14
0
 public void Register(EEventType mEventType, SubscriberFunction mSubscriberFunction)
 {
     FunctionList(mEventType).Add(mSubscriberFunction);
 }
        /// <summary>Gets ActiveSubscription from a specific Subscription List by persistance.</summary>
        private ActiveSubscription GetActiveSubscription(SubscriptionPersistence _persistence, string _messageHeader, SubscriberFunction _messageFunction)
        {
            ActiveSubscription result = null;

            switch (_persistence)
            {
            case SubscriptionPersistence.Endless:
            {
                result = GetEndlessSubscription(_messageHeader, _messageFunction);
                break;
            }

            case SubscriptionPersistence.SingleUse:
            {
                result = GetSingleSubscription(_messageHeader, _messageFunction);
                break;
            }

            case SubscriptionPersistence.SoloFrame:
            {
                result = GetSoloSubscription(_messageHeader, _messageFunction);
                break;
            }

            default:
            {
                break;
            }
            }

            return(result);
        }
 /// <summary>Handle logic after subscription has triggered.</summary>
 public void SubscriptionTriggered(string _messageHeader, SubscriberFunction _messageFunction)
 {
     //If single use, unsubscribe ActiveSubscription
     UnsubscribeSingleSubscription(_messageHeader, _messageFunction);
 }