Ejemplo n.º 1
0
 /// <summary>
 /// Allows an <see cref="IQActive"/> object to unsubscribe for a given signal.
 /// </summary>
 /// <param name="qActive">The unsubscribing <see cref="IQActive"/> object.</param>
 /// <param name="qSignal">The signal to unsubscribe.</param>
 public void Unsubscribe(IQActive qActive, string qSignal)
 {
     lock (m_SignalSubscribers)
     {
         int hashCode = qSignal.GetHashCode();
         m_SignalSubscribers[hashCode].Remove(qActive.Priority);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new <see cref="QTimer"/> instance.
 /// </summary>
 /// <param name="qActive">The <see cref="IQActive"/> object that owns this <see cref="QTimer"/>; this is also
 /// the <see cref="IQActive"/> object that will receive the timer based events.</param>
 public QTimer(IQActive qActive)
 {
     m_QActive = qActive;
     m_Timer   = new Timer(
         new TimerCallback(this.OnTimer),
         null,                 // we don't need a state object
         Timeout.Infinite,     // don't start yet
         Timeout.Infinite      // no periodic firing
         );
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new <see cref="QTimer"/> instance.
 /// </summary>
 /// <param name="qActive">The <see cref="IQActive"/> object that owns this <see cref="QTimer"/>; this is also
 /// the <see cref="IQActive"/> object that will receive the timer based events.</param>
 public QTimer(IQActive qActive)
 {
     m_QActive = qActive;
     m_Timer = new Timer(
         new TimerCallback(this.OnTimer),
         null, // we don't need a state object
         Timeout.Infinite, // don't start yet
         Timeout.Infinite  // no periodic firing
         );
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Allows an <see cref="IQActive"/> object to subscribe for a given signal.
        /// </summary>
        /// <param name="qActive">The subscribing <see cref="IQActive"/> object.</param>
        /// <param name="qSignal">The signal to subscribe for.</param>
        public void Subscribe(IQActive qActive, string qSignal)
        {
            //Debug.WriteLine(qActive.ToString() + " subscribes for signal " + qSignal.ToString());
            lock (m_SignalSubscribers)
            {
                int hashCode = qSignal.GetHashCode();
                if (m_SignalSubscribers[hashCode] == null)
                {
                    // this is the first time that somebody subscribes for this signal
                    m_SignalSubscribers[hashCode] = new SortedList();
                }

                m_SignalSubscribers[hashCode].Add(qActive.Priority, qActive);
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            QF.Instance.Initialize((int)DPPSignal.MaxSignal - 1);

            IQActive table = new Table(c_NumberOfPhilosophers);
            IQActive[] philosophers = new IQActive[c_NumberOfPhilosophers];

            for(int i = 0; i < c_NumberOfPhilosophers; i++)
            {
                philosophers[i] = new Philosopher(i);
            }

            Console.WriteLine(c_NumberOfPhilosophers + " philosophers gather around a table thinking ...");
            table.Start(c_NumberOfPhilosophers);
            for(int i = 0; i < c_NumberOfPhilosophers; i++)
            {
                philosophers[i].Start(i);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Allows an event source to publish an event.
 /// </summary>
 /// <param name="qEvent">The <see cref="QEvent"/> to publish.</param>
 public void Publish(QEvent qEvent)
 {
     lock (m_SignalSubscribers)
     {
         int        hashCode             = qEvent.QSignal.GetHashCode();
         SortedList sortedSubscriberList = m_SignalSubscribers[hashCode];
         if (sortedSubscriberList != null)
         {
             // For simplicity we do not use the event propagae pattern that Miro Samek uses in his implementation.
             // This has two consequences:
             // a) We rely on the Garbage Collector to clean up events that are no longer used
             // b) We don't have the restriction that only once instance of a given type (signal value) can be in use at any given time
             for (int i = 0; i < sortedSubscriberList.Count; i++)
             {
                 IQActive subscribingQActive = (IQActive)sortedSubscriberList.GetByIndex(i);
                 subscribingQActive.PostFIFO(qEvent);
             }
         }
     }
 }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            QF.Instance.Initialize((int)DPPSignal.MaxSignal - 1);

            IQActive table = new Table(c_NumberOfPhilosophers);

            IQActive[] philosophers = new IQActive[c_NumberOfPhilosophers];

            for (int i = 0; i < c_NumberOfPhilosophers; i++)
            {
                philosophers[i] = new Philosopher(i);
            }

            Console.WriteLine(c_NumberOfPhilosophers + " philosophers gather around a table thinking ...");
            table.Start(c_NumberOfPhilosophers);
            for (int i = 0; i < c_NumberOfPhilosophers; i++)
            {
                philosophers[i].Start(i);
            }
        }
Ejemplo n.º 8
0
 internal void RemoveSubscriber(IQActive qActive)
 {
     m_SubscriberList.Remove(qActive.Priority);
 }
Ejemplo n.º 9
0
 internal void AddSubscriber(IQActive qActive)
 {
     m_SubscriberList.Add(qActive.Priority, qActive);
 }
Ejemplo n.º 10
0
 internal void RemoveSubscriber(IQActive qActive)
 {
     m_SubscriberList.Remove(qActive.Priority);
 }
Ejemplo n.º 11
0
 internal void AddSubscriber(IQActive qActive)
 {
     m_SubscriberList.Add(qActive.Priority, qActive);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Allows an <see cref="IQActive"/> object to unsubscribe for a given signal.
 /// </summary>
 /// <param name="qActive">The unsubscribing <see cref="IQActive"/> object.</param>
 /// <param name="qSignal">The signal to unsubscribe.</param>
 public void Unsubscribe(IQActive qActive, int qSignal)
 {
     lock(m_SignalSubscribers)
     {
         m_SignalSubscribers[qSignal].Remove(qActive.Priority);
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Allows an <see cref="IQActive"/> object to subscribe for a given signal.
        /// </summary>
        /// <param name="qActive">The subscribing <see cref="IQActive"/> object.</param>
        /// <param name="qSignal">The signal to subscribe for.</param>
        public void Subscribe(IQActive qActive, int qSignal)
        {
            //Debug.WriteLine(qActive.ToString() + " subscribes for signal " + qSignal.ToString());
            lock(m_SignalSubscribers)
            {
                if (m_SignalSubscribers[qSignal] == null)
                {
                    // this is the first time that somebody subscribes for this signal
                    m_SignalSubscribers[qSignal] = new SortedList();
                }

                m_SignalSubscribers[qSignal].Add(qActive.Priority, qActive);
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Allows an <see cref="IQActive"/> object to unsubscribe for a given signal.
 /// </summary>
 /// <param name="qActive">The unsubscribing <see cref="IQActive"/> object.</param>
 /// <param name="qSignal">The signal to unsubscribe.</param>
 public void Unsubscribe(IQActive qActive, string qSignal)
 {
     lock(m_SignalSubscribers)
     {
         int hashCode = qSignal.GetHashCode ();
         m_SignalSubscribers[hashCode].Remove(qActive.Priority);
     }
 }