2014-10-17 09:56:54 -04:00
|
|
|
/**
|
|
|
|
* @file
|
2013-09-01 10:55:13 -04:00
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2014-06-21 09:37:47 -04:00
|
|
|
#ifndef OCARINA_CORE_IDLE_H
|
|
|
|
#define OCARINA_CORE_IDLE_H
|
2013-09-01 10:55:13 -04:00
|
|
|
|
2014-10-17 09:56:54 -04:00
|
|
|
/**
|
|
|
|
* Namespace for controlling idle tasks.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
namespace idle
|
|
|
|
{
|
|
|
|
|
2014-10-17 09:56:54 -04:00
|
|
|
/**
|
|
|
|
* Base class for creating new IdleTasks.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
class IdleBase {
|
|
|
|
protected:
|
2014-10-17 09:56:54 -04:00
|
|
|
/**
|
|
|
|
* Add the IdleBase to the idle queue.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
void schedule();
|
2014-03-16 13:09:33 -04:00
|
|
|
|
2013-09-01 10:55:13 -04:00
|
|
|
public:
|
2014-10-17 09:56:54 -04:00
|
|
|
/**
|
|
|
|
* Constructor for the IdleBase class.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
IdleBase();
|
2014-10-17 09:56:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IdleBase destructor.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
virtual ~IdleBase();
|
2014-10-17 09:56:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the idle task.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
virtual void run() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-17 09:56:54 -04:00
|
|
|
/**
|
|
|
|
* Generic IdleTask class.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
template <class T>
|
|
|
|
class IdleTask : public IdleBase {
|
|
|
|
private:
|
|
|
|
void (*func)(T &);
|
|
|
|
T data;
|
2014-03-16 13:09:33 -04:00
|
|
|
|
2013-09-01 10:55:13 -04:00
|
|
|
public:
|
2014-10-17 09:56:54 -04:00
|
|
|
/**
|
|
|
|
* IdleTask constructor.
|
|
|
|
* @param func Function to call when running this task.
|
|
|
|
* @param data Data to pass to the function.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
IdleTask(void (*)(T &), T);
|
2014-10-17 09:56:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IdleTask destructor.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
~IdleTask();
|
2014-10-17 09:56:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the IdleTask.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
void run();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-17 09:56:54 -04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
template <class T>
|
|
|
|
static inline void schedule(void (*func)(T &), T param)
|
|
|
|
{
|
|
|
|
new IdleTask<T>(func, param);
|
|
|
|
}
|
|
|
|
|
2014-10-17 09:56:54 -04:00
|
|
|
/**
|
|
|
|
* Run the next task on the idle queue.
|
|
|
|
* @return True if there are still tracks on the queue, false otherwise.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
bool run_task();
|
2014-10-17 09:56:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call to find the progress of the idle queue.
|
|
|
|
* @return A fraction representing the idle queue progress.
|
|
|
|
*/
|
2013-09-01 10:55:13 -04:00
|
|
|
float get_progress();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#include "idle.hpp"
|
|
|
|
|
2014-06-21 09:37:47 -04:00
|
|
|
#endif /* OCARINA_CORE_IDLE_H */
|