Exemple #1
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);
        }
Exemple #2
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.strict.Element interface.
        /// </summary>
        /// <param name="timeStamp"></param>
        /// <returns>If the element is ready to be fired.</returns>
        public override bool  isReady(long timeStamp)
        {
            bool success = false;

            if (trigger.fire())
            {
                if (maxRetries == 0 || retries < maxRetries)
                {
                    retries += 1;
                    success  = true;
                }
                else
                {
                    log.Debug("Retry limit exceeded");
                }
            }

            return(success);
        }
Exemple #3
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");
            FireArgs args = new FireArgs();

            // check if the goal is satisfied
            if (goal is Trigger && goal.fire())
            {
                log.Debug("Goal satisfied");
                args.FireResult = false;
                args.Time       = DateTime.Now;
                BroadCastFireEvent(args);

                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;
                }
                args.FireResult = result.continueExecution();
                args.Time       = DateTime.Now;
                BroadCastFireEvent(args);

                return(result);
            }
            // we failed
            log.Debug("Failed");
            args.FireResult = false;
            args.Time       = DateTime.Now;
            BroadCastFireEvent(args);

            return(new FireResult(false, null));
        }
Exemple #4
0
        /// <summary>
        /// Fires the drive collection.
        ///
        /// This method first checks if the goal (if not null) 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");
            FireArgs args = new FireArgs();

            // check if goal reached
            if (goal is Trigger && goal.fire())
            {
                log.Debug("Goal Satisfied");
                args.FireResult = false;
                args.Time       = DateTime.Now;
                BroadCastFireEvent(args);
                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)
                {
                    args.FireResult = true;
                    args.Time       = DateTime.Now;
                    BroadCastFireEvent(args);
                    return(new FireResult(true, null));
                }
            }

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

            args.FireResult = false;
            args.Time       = DateTime.Now;
            BroadCastFireEvent(args);
            return(new FireResult(false, null));
        }