RSeries astromech firmware
AnimatedEvent.h
Go to the documentation of this file.
1 #ifndef AnimatedEvent_h
2 #define AnimatedEvent_h
3 
4 #include "ReelTwo.h"
5 
6 typedef void (*AnimatedLoopDone)();
7 
19 {
20 public:
26  fNext(NULL)
27  {
28  if (*head() == NULL)
29  *head() = this;
30  if (*tail() != NULL)
31  (*tail())->fNext = this;
32  *tail() = this;
33  }
34 
38  static void process()
39  {
40  static AnimatedEvent* sGuard;
41  AnimatedLoopDone* loopProc = loopDoneProc();
42  *loopProc = NULL;
43  for (AnimatedEvent* evt = *head(); evt != NULL; evt = evt->fNext)
44  {
45  // Reentrancy guard
46  if (sGuard == evt)
47  continue;
48  sGuard = evt;
49  evt->animate();
50  sGuard = NULL;
51  }
52  #if defined(USE_SMQ) && !defined(USE_SMQ32)
53  static bool sSMQReentrancy;
54  if (!sSMQReentrancy)
55  {
56  sSMQReentrancy = true;
57  SMQ::process();
58  sSMQReentrancy = false;
59  }
60  #endif
61  if ((*loopProc) != NULL)
62  {
63  (*loopProc)();
64  *loopProc = NULL;
65  }
66  }
67 
68  // \private
70  {
71  *loopDoneProc() = loopProc;
72  }
73 
78  virtual void animate() = 0;
79 
80 private:
81  AnimatedEvent* fNext;
82 
83  static AnimatedEvent** head()
84  {
85  static AnimatedEvent* sHead;
86  return &sHead;
87  }
88 
89  static AnimatedEvent** tail()
90  {
91  static AnimatedEvent* sTail;
92  return &sTail;
93  }
94 
95  static AnimatedLoopDone* loopDoneProc()
96  {
97  static AnimatedLoopDone sProc;
98  return &sProc;
99  }
100 };
101 
102 #endif
SMQ::process
static void process()
Definition: ReelTwoSMQ.h:74
ReelTwo.h
AnimatedEvent
Base class for all animated devices. AnimatedEvent::animate() is called for each device once through ...
Definition: AnimatedEvent.h:18
AnimatedLoopDone
void(* AnimatedLoopDone)()
Definition: AnimatedEvent.h:6
AnimatedEvent::AnimatedEvent
AnimatedEvent()
Default Constructor.
Definition: AnimatedEvent.h:25
AnimatedEvent::process
static void process()
Calls animate() for each created AnimatedEvent subclass.
Definition: AnimatedEvent.h:38
AnimatedEvent::animate
virtual void animate()=0
Subclasses must implement this function to run through a single frame of animation/activity.
AnimatedEvent::setLoopDoneCallback
void setLoopDoneCallback(AnimatedLoopDone loopProc)
Definition: AnimatedEvent.h:69