timer.cpp 885 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #if defined(Hiro_Timer)
  2. namespace hiro {
  3. static auto Timer_trigger(pTimer* p) -> int {
  4. //prevent all timers from firing once the program has been terminated
  5. if(Application::state().quit) return false;
  6. //timer may have been disabled prior to triggering, so check state
  7. if(p->self().enabled(true)) p->self().doActivate();
  8. //callback may have disabled timer, so check state again
  9. if(p->self().enabled(true)) {
  10. g_timeout_add(p->state().interval, (GSourceFunc)Timer_trigger, (gpointer)p);
  11. }
  12. //kill this timer instance (it is spawned above if needed again)
  13. return false;
  14. }
  15. auto pTimer::construct() -> void {
  16. }
  17. auto pTimer::destruct() -> void {
  18. }
  19. auto pTimer::setEnabled(bool enabled) -> void {
  20. if(enabled) {
  21. g_timeout_add(state().interval, (GSourceFunc)Timer_trigger, (gpointer)this);
  22. }
  23. }
  24. auto pTimer::setInterval(uint interval) -> void {
  25. }
  26. }
  27. #endif