Example #1
0
            async Task Initialize()
            {
                // Start a timer, and stop it immediately
                TimerId tid = StartTimer(payload, 10, true);

                await this.StopTimer(tid, flush : false);
            }
Example #2
0
 void Initialize()
 {
     tcs = (this.ReceivedEvent as Configure).TCS;
     tid = this.StartTimer(this.payload, 100, true);
     m   = CreateMachine(typeof(T3), new TransferTimerAndTCS(tid, tcs));
     this.Raise(new Halt());
 }
Example #3
0
            void InitOnEntry()
            {
                count = 0;

                // Start a one-off timer
                tid = StartTimer(payload, 10, false);
            }
Example #4
0
 public static void Init()
 {
     if (instance == default(TimerId))
     {
         instance = new TimerId(0xB5);
     }
 }
Example #5
0
 public InitTimer(MachineId client, TimerId tid, bool IsPeriodic, int period)
 {
     this.client     = client;
     this.IsPeriodic = IsPeriodic;
     this.Period     = period;
     this.tid        = tid;
 }
            void InitOnEntry()
            {
                count = 0;

                // Start a periodic timer
                tid = StartTimer(payload, 10, true);
            }
Example #7
0
            async Task Initialize()
            {
                // Incorrect period, will throw assertion violation
                TimerId tid = this.StartTimer(payload, -1, true);

                await this.StopTimer(tid, flush : true);
            }
Example #8
0
 private static void TimerProcedure(WindowHandle window, MessageType message, TimerId timerId, uint time)
 {
     Windows.MessageBeep();
     s_fFlipFlop             = !s_fFlipFlop;
     using DeviceContext dc  = window.GetDeviceContext();
     using BrushHandle brush = Gdi.CreateSolidBrush(s_fFlipFlop ? Color.Red : Color.Blue);
     dc.FillRectangle(window.GetClientRectangle(), brush);
 }
Example #9
0
        private void InitializeTimer()
        {
            var e = (this.ReceivedEvent as InitTimerEvent);

            this.client     = e.client;
            this.IsPeriodic = e.IsPeriodic;
            this.tid        = e.tid;
            this.Send(this.Id, new RepeatTimeoutEvent());
        }
Example #10
0
        private void DoPing()
        {
            // reset the count
            count = 1;

            // Start a periodic timer with timeout interval of 1sec.
            // The timer generates TimerElapsedEvent with 'm' as payload.
            pingTimer = StartTimer(payload, 50, true);
        }
Example #11
0
            private async Task DoPing()
            {
                // Start a periodic timer with timeout interval of 1sec.
                // The timer generates TimerElapsedEvent with 'm' as payload.
                pingTimer = StartTimer(payload, 5, true);
                await this.StopTimer(pingTimer, flush : true);

                this.Goto <Pong>();
            }
Example #12
0
        public TimeSpan Timer(TimerId id)
        {
            if (id < (TimerId)0 || id >= TimerId.Count)
            {
                return(TimeSpan.Zero);
            }

            return(m_Timers[(int)id]);
        }
            async Task Initialize()
            {
                TimerId tid = (this.ReceivedEvent as TransferTimer).tid;

                // trying to stop a timer created by a different machine.
                // should throw an assertion violation
                await this.StopTimer(tid, true);

                this.Raise(new Halt());
            }
Example #14
0
 static void TimerProcedure(WindowHandle window, WindowMessage message, TimerId timerId, uint time)
 {
     Windows.MessageBeep();
     fFlipFlop = !fFlipFlop;
     using (DeviceContext dc = window.GetDeviceContext())
     {
         RECT rect = window.GetClientRectangle();
         using (BrushHandle brush = fFlipFlop ? Windows.CreateSolidBrush(255, 0, 0) : Windows.CreateSolidBrush(0, 0, 255))
         {
             dc.FillRectangle(rect, brush);
         }
     }
 }
Example #15
0
            private async Task DoPing()
            {
                tcs = (this.ReceivedEvent as Configure).TCS;

                // Start a periodic timer with timeout interval of 1sec.
                // The timer generates TimerElapsedEvent with 'm' as payload.
                pingTimer = StartTimer(payload, 5, true);
                await Task.Delay(100);

                await this.StopTimer(pingTimer, flush : true);

                this.Goto <Pong>();
            }
Example #16
0
            async Task Initialize()
            {
                TimerId tid = (this.ReceivedEvent as TransferTimerAndTCS).tid;
                TaskCompletionSource <bool> tcs = (this.ReceivedEvent as TransferTimerAndTCS).TCS;

                // trying to stop a timer created by a different machine.
                // should throw an assertion violation
                try
                {
                    await this.StopTimer(tid, true);
                }
                catch (AssertionFailureException)
                {
                    tcs.SetResult(true);
                    this.Raise(new Halt());
                }
            }
Example #17
0
            void InitOnEntry()
            {
                Configure e = (this.ReceivedEvent as Configure);

                tcs      = e.TCS;
                periodic = e.periodic;
                count    = 0;

                if (periodic)
                {
                    // Start a periodic timer with 10ms timeouts
                    tid = StartTimer(payload, 10, true);
                }
                else
                {
                    // Start a one-off timer
                    tid = StartTimer(payload, 10, false);
                }
            }
Example #18
0
 /// <summary>
 /// Handle timeout events from the pongTimer.
 /// </summary>
 private void DoPong()
 {
     // Start a periodic timer with timeout interval of 0.5sec.
     // The timer generates TimerElapsedEvent with 'm' as payload.
     pongTimer = StartTimer(payload, 50, false);
 }
Example #19
0
 public override Task OnActivateAsync()
 {
     this._id     = TimerId.Parse(this.GetPrimaryKeyString());
     this._logger = this._serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger(this._id.FunctionType);
     return(Task.CompletedTask);
 }
Example #20
0
        /// <summary>
        /// Allocate a free timer from the stack of free timers, set expiration
        /// add the timer to end of the list of running timers
        /// </summary>
        /// <param name="timeout">
        /// A <see cref="System.Int64"/>
        /// </param>
        /// <param name="timer">
        /// A <see cref="Timer"/>
        /// Reference to the started timer. Can be used in call to Stop()
        /// </param>
        /// <param name="timerId">
        /// A <see cref="System.Int64"/>
        /// Timer list reuse refernces (objects) of type Timer. Reference to Timer is
        /// not enough to make sure that you stop the correct timer. Value timerId
        /// is a unique (system level) timer identifier
        /// </param>
        /// <param name="applicationHook">
        /// A <see cref="System.Object"/>
        /// Timer.applicationHook field will be set to this value
        /// Field applicationHook can help to identify the timer in the context of timerExpired
        /// callback
        /// </param>
        /// <param name="autoRestart">
        /// A <see cref="System.Boolean"/>
        /// If true the system will reschedule the expire timer automatically while taking care
        /// that the next expiration tick is exactly startTick+2*timeout
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// returns true of Ok, false is failed to allocate a new timer - no free
        /// timers are available
        /// </returns>
        public bool Start(out ITimer iTimer, out long timerId, object applicationHook, bool autoRestart)
        {
            // timestamp the call as soon as possible
            DateTime startTime = DateTime.Now;
            long     startTick = (startTime.Ticks) / TICKS_IN_MILLISECOND;


            Timer timer = null;

            iTimer  = null;
            timerId = 0;
            Timers.Error error = Timers.Error.START_UNKNOWN;


            do
            {
                // get new timer Id
                timerId = TimerId.GetNext();

                // allocate a timer from the stack of free timers
                lock (this)
                {
                    countStartAttempt++;

                    if (freeTimers.Count > 0)
                    {
                        timer = freeTimers.Pop();
                    }
                    else
                    {
                        error = Timers.Error.NO_FREE_TIMERS;
                        break;
                    }
                }

                // initialize the timer
                timer.ApplicationHook = applicationHook;
                timer.StartTick       = startTick;
                timer.ExpirationTime  = startTick + Timeout;
                timer.Running         = true;
                timer.TimerId         = timerId;
                timer.AutoRestart     = autoRestart;
                timer.Restarts        = 1;          // first start is considered a restart
                iTimer = timer;

                // add the timer to the queue of the pending timers
                lock (this)
                {
                    countStart++;
                    pendingTimers.Add(timer);
                    countMax = Math.Max(countMax, pendingTimers.Count);
                }

                // send wakeup call to the task handling the timers
                timerTask.WakeupCall();

                error = Timers.Error.NONE;
            }while (false);

            if (error != Timers.Error.NONE)
            {
                PrintError("Start failed ", error);
            }


            return(error == Timers.Error.NONE);
        }
Example #21
0
 public static void InitTimerId()
 {
     TimerId.Init();
 }
Example #22
0
 public ITimer GeTimer(TimerId id)
 {
     return(GeTimer(id.ToString()));
 }
Example #23
0
 public ITimer CreatOrRestartTimer(TimerId id, float duration, bool loop)
 {
     return(CreatOrRestartTimer(id.ToString(), duration, loop));
 }
 public TransferTimer(TimerId tid)
 {
     this.tid = tid;
 }
 void Initialize()
 {
     tid = this.StartTimer(this.payload, 100, true);
     m   = CreateMachine(typeof(T3), new TransferTimer(tid));
     this.Raise(new Halt());
 }
Example #26
0
 public ITimer ResetTimerData(TimerId id, float duration, bool loop)
 {
     return(ResetTimerData(id.ToString(), duration, loop));
 }
Example #27
0
 public static extern ResultCode GpioSetTimerFunc(TimerId timer, uint periodMilliseconds, [In, MarshalAs(UnmanagedType.FunctionPtr)] PiGpioTimerDelegate callback);
Example #28
0
 public static extern ResultCode GpioSetTimerFuncEx(TimerId timer, uint millisecondsTimeout, [In, MarshalAs(UnmanagedType.FunctionPtr)] PiGpioTimerExDelegate callback, UIntPtr userData);
Example #29
0
 public void Add(TimerId id, TimeSpan diff)
 {
     m_Timers[(int)id] += diff;
 }
Example #30
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="tid">Tid</param>
 public TimerElapsedEvent(TimerId tid)
 {
     this.Tid = tid;
 }
Example #31
0
        public TimeSpan Timer(TimerId id)
        {
            if (id < (TimerId)0 || id >= TimerId.Count)
                return TimeSpan.Zero;

            return m_Timers[(int)id];
        }
Example #32
0
 public void Add(TimerId id, TimeSpan diff)
 {
     m_Timers[(int)id] += diff;
 }