Pebble Foundation Classes  0.2.0
C++ for Pebble
pebble_event_services.hpp
1 #pragma once
2 
3 namespace Pebble {
4 
7 
8 class TickTimer
9 {
10 protected:
14  virtual void OnTick(tm &tick_time, TimeUnits units_changed) = 0;
15 
17  virtual ~TickTimer() { TickTimerEnd(); }
18 
23  inline void TickTimerStart(TimeUnits tick_units) {
24  active() = this;
25  tick_timer_service_subscribe(tick_units, handler_tick);
26  }
27 
29  inline void TickTimerEnd() { if (active() == this) { tick_timer_service_unsubscribe(); active() = 0; } }
30 
31 private:
33  inline static TickTimer*& active() { static TickTimer* active = 0; return active; }
34 
38  static void handler_tick(tm *tick_time, TimeUnits units_changed) { active()->OnTick(*tick_time, units_changed); }
39 };
40 
42 
43 }
Pebble::TickTimer
Definition: pebble_event_services.hpp:8
Pebble::TickTimer::~TickTimer
virtual ~TickTimer()
Tick Timer destructor; ends the timer
Definition: pebble_event_services.hpp:17
Pebble::TickTimer::OnTick
virtual void OnTick(tm &tick_time, TimeUnits units_changed)=0
TimeUnits
TimeUnits
Definition: pebble.h:815
tick_timer_service_subscribe
void tick_timer_service_subscribe(TimeUnits tick_units, TickHandler handler)
Pebble::TickTimer::TickTimerStart
void TickTimerStart(TimeUnits tick_units)
Definition: pebble_event_services.hpp:23
tm
Definition: pebble.h:8311
tick_timer_service_unsubscribe
void tick_timer_service_unsubscribe(void)
Pebble::TickTimer::TickTimerEnd
void TickTimerEnd()
Stops the tick timer events.
Definition: pebble_event_services.hpp:29