
#ifndef __WFX_KERNEL_KERNEL_H__
#define __WFX_KERNEL_KERNEL_H__

#include <WFX/WFXIncludes.h>

#include <WFX/lang/Singleton.h>
#include <WFX/kernel/Task.h>

namespace WFX {

    namespace kernel {

        class Task;

        /**
         * the system Kernel.
         * 
         */
        class Kernel : public WFX::lang::Singleton<Kernel> {
            public:
                /**
                 * Ctor
                 */
                Kernel();
                /**
                 * Dtor
                 */
                virtual ~Kernel();

                /**
                 * starts the task loop and keeps it going as long
                 * as there are any unstopped tasks left.
                 * To stop this call Kernel::removeAllTasks()
                 */
                int exec();
                /**
                 * adds a Task to the task list
                 */
                bool addTask(Task* t);
                /**
                 * stops a task and removes it from the task list
                 */
                void removeTask(Task* t);
                /**
                 * stop()s all tasks and removes them from the task list
                 * Tasks are deleted in this process
                 */
                void removeAllTasks();
                /**
                 * pauses a task
                 */
                void pauseTask(Task* t);
                /**
                 * resumes a previousliy paused task
                 */
                void resumeTask(Task* t);

            protected:
                /**
                 * a list containing all running tasks
                 */
                std::list<Task*> RunningTasks;
                /**
                 * a list containing all paused tasks
                 */
                std::list<Task*> PausedTasks;
                    
            
            private:
                /**
                 * inserts a task into task list
                 */
                void insertTask(Task* t);
        };

    }

}


#endif //include guard


