2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Diagnostics;
6 using Tizen.NUI.Binding;
8 namespace Tizen.NUI.Binding.Internals
10 internal abstract class Ticker
12 static Ticker s_ticker;
13 readonly Stopwatch _stopwatch;
14 readonly List<Tuple<int, Func<long, bool>>> _timeouts;
22 _timeouts = new List<Tuple<int, Func<long, bool>>>();
24 _stopwatch = new Stopwatch();
27 public static void SetDefault(Ticker ticker) => Default = ticker;
28 public static Ticker Default
30 internal set { s_ticker = value; }
31 get { return s_ticker ?? (s_ticker = Device.PlatformServices.CreateTicker()); }
34 public virtual int Insert(Func<long, bool> timeout)
37 _timeouts.Add(new Tuple<int, Func<long, bool>>(_count, timeout));
48 public virtual void Remove(int handle)
50 Device.BeginInvokeOnMainThread(() =>
52 _timeouts.RemoveAll(t => t.Item1 == handle);
62 protected abstract void DisableTimer();
64 protected abstract void EnableTimer();
66 protected void SendSignals(int timestep = -1)
68 long step = timestep >= 0 ? timestep : _stopwatch.ElapsedMilliseconds;
72 var localCopy = new List<Tuple<int, Func<long, bool>>>(_timeouts);
73 foreach (Tuple<int, Func<long, bool>> timeout in localCopy)
75 bool remove = !timeout.Item2(step);
77 _timeouts.RemoveAll(t => t.Item1 == timeout.Item1);