Example #1
0
        /// <summary>
        /// Fires the drive collection.
        ///
        /// This method first checks if the goal (if not None) is met. If
        /// that is the case, then FireResult(False, self) is
        /// returned. Otherwise it goes through the list of priority
        /// elements until the first one was fired successfully (returning
        /// something else than None). In that case, FireResult(True,
        /// None) is returned. If none of the priority elements were
        /// successful, FireResult(False, None) is returned, indicating a
        /// failing of the drive collection.
        ///
        /// To summarise:
        ///     - FireResult(True, None): drive element fired
        ///     - FireResult(False, self): goal reached
        ///     - FireResult(False, None): drive failed
        /// </summary>
        /// <returns>The result of firing the drive.</returns>
        public override FireResult  fire()
        {
            log.Debug("Fired");

            // check if goal reached
            if (goal is Trigger && goal.fire())
            {
                log.Debug("Goal Satisfied");
                return(new FireResult(false, this));
            }

            // fire elements
            foreach (DrivePriorityElement elem in elements)
            {
                // a priority element returns None if it wasn't
                // successfully fired
                if (elem.fire() != null)
                {
                    return(new FireResult(true, null));
                }
            }

            // drive failed (no element fired)
            log.Debug("Failed");

            return(new FireResult(false, null));
        }
Example #2
0
        /// <summary>
        /// Fires the competence.
        ///
        /// This method first checks if the competence's goal is satisfied
        /// (if the goal is not None). If that is the case, then it
        /// returns FireResult(False, None). Otherwise it fires the
        /// priority elements one by one. On the first successful firing
        /// of a competence priority element, the method returns the
        /// result of the priority element. If no priority element fired
        /// successfully, then FireResult(False, None) is returned.
        /// </summary>
        /// <returns>The result of firing an element, or
        ///         FireResult(False, None)</returns>
        public override FireResult  fire()
        {
            log.Debug("Fired");
            // check if the goal is satisfied
            if (goal is Trigger && goal.fire())
            {
                log.Debug("Goal satisfied");
                return(new FireResult(false, null));
            }
            // process the elements
            FireResult result;

            foreach (CompetencePriorityElement elem in elements)
            {
                result = elem.fire();
                // check if the competence priority element failed
                if (result.continueExecution() && !(result.nextElement() is CopiableElement))
                {
                    continue;
                }
                return(result);
            }
            // we failed
            log.Debug("Failed");

            return(new FireResult(false, null));
        }
Example #3
0
 /// <summary>
 /// Returns if the element is ready to be fired.
 ///
 /// The element is ready to be fired if its trigger is
 /// satisfied and it was not fired more than maxRetries.
 /// Note that timestamp is ignored in this method. It is only
 /// there because isReady is defined like that in the
 /// POSH.scheduled.Element interface.
 /// </summary>
 /// <param name="timeStamp"></param>
 /// <returns>If the element is ready to be fired.</returns>
 public override bool  isReady(long timeStamp)
 {
     if (trigger.fire())
     {
         if (maxRetries < 0 || retries < maxRetries)
         {
             retries += 1;
             return(true);
         }
         else
         {
             log.Debug("Retry limit exceeded");
         }
     }
     return(false);
 }
Example #4
0
        /// <summary>
        /// Returns if the element is ready to be fired.
        ///
        /// The element is ready to be fired if its trigger is
        /// satisfied and if the time since the last firing is
        /// larger than the one given by C{maxFreq}. The time of the
        /// last firing is determined by the timestamp given
        /// to L{isReady} when it was called the last time and returned
        /// True. This implies that the element has to be fired
        /// every time when this method returns True.
        /// </summary>
        /// <param name="timeStamp">The current timestamp in milliseconds</param>
        /// <returns></returns>
        public override bool isReady(long timeStamp)
        {
            if (trigger.fire())
            {
                if (maxFreq < 0 || timeStamp - lastFired > +maxFreq)
                {
                    lastFired = timeStamp;
                    return(true);
                }
                else
                {
                    log.Debug("Max. firing frequency exceeded");
                }
            }

            return(false);
        }