/** * @file * Copyright 2013 (c) Anna Schumaker. */ #ifndef OCARINA_CORE_IDLE_H #define OCARINA_CORE_IDLE_H /** * Namespace for controlling idle tasks. */ namespace idle { /** * Base class for creating new IdleTasks. */ class IdleBase { protected: /** * Add the IdleBase to the idle queue. */ void schedule(); public: /** * Constructor for the IdleBase class. */ IdleBase(); /** * IdleBase destructor. */ virtual ~IdleBase(); /** * Run the idle task. */ virtual void run() = 0; }; /** * Generic IdleTask class. */ template class IdleTask : public IdleBase { private: void (*func)(T &); T data; public: /** * IdleTask constructor. * @param func Function to call when running this task. * @param data Data to pass to the function. */ IdleTask(void (*)(T &), T); /** * IdleTask destructor. */ ~IdleTask(); /** * Run the IdleTask. */ void run(); }; /** * Create a new IdleTask and add it to the queue. * @param func Function to call when running the new task. * @param data Data to pass to the function. */ template static inline void schedule(void (*func)(T &), T param) { new IdleTask(func, param); } /** * Run the next task on the idle queue. * @return True if there are still tracks on the queue, false otherwise. */ bool run_task(); /** * Call to find the progress of the idle queue. * @return A fraction representing the idle queue progress. */ float get_progress(); }; #include "idle.hpp" #endif /* OCARINA_CORE_IDLE_H */