//Editor-Info: -*- C++ -*-
//
//Subject: Scheduler Framework
//
//File: task.h
//
//Version: $Revision: 1.6 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/07/15 11:28:17 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//      Juhana Räsänen
//
//Description:
//      Base class for schedulable tasks.
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//
//Licence:
//
//
//History: 
//

#ifndef __SF_TASK_H__
#define __SF_TASK_H__

class sfSchedulerHandle;
class OTime;

#include <typeinfo>
#include "exception.h"

//
// Class: sfTask
//
// Description:
//     A base class for schedulable objects. A task can request different
//     events from a scheduler, which will schedule the requests according
//     to some scheduling policy and call the tasks at the time of the
//     event occurs. This class provides default methods for such inter-
//     action and some default parameters (priority & load) that could
//     be used in scheduler. By default the task should access scheduler
//     via a scheduler handle object, which is done by the default event
//     request methods.
//     Note that it is not necessary to use the default request methods,
//     a task can be handed directly to the scheduler by a third party.
//     However, because tasks are stored as pointers within the scheduler,
//     extreme care must be taken to prevent the scheduler from calling
//     an already deleted task's callback methods. The default methods
//     require the task to know its scheduler and the default destructor
//     calls scheduler's removeTask() methods in case the scheduler of
//     the task is known, so their use is recommended.
//

class sfTask
{
    protected:
        // Constructor is protected to prevent instantiation of this class
        sfTask(void);

    public:
        sfTask(const sfTask &other_);
        virtual ~sfTask(void);

        const sfTask & operator = (const sfTask &other_);

        // Event request methods
        virtual void requestCPU(void);
        virtual void requestTimeout(const OTime &timeout_);
        virtual void requestAbsoluteTimeout(const OTime &timeout_);
        virtual void requestRead(int fileDescriptor_, const OTime &timeout_);
        virtual void requestWrite(int fileDescriptor_, const OTime &timeout_);

        // Event cancel methods
        virtual void cancelCPU(void);
        virtual void cancelTimeout(void);
        virtual void cancelRead(void);
        virtual void cancelWrite(void);

        // Event callback methods
        virtual void runCallback(void);
        virtual void timeoutCallback(void);
        virtual void readCallback(void);
        virtual void writeCallback(void);

        // Parameter get/set methods
        virtual void setHandle(sfSchedulerHandle *handle_);
        virtual sfSchedulerHandle *getHandle(void) const;
        virtual void setPriority(int priority_);
        virtual int getPriority(void) const;
        virtual void setLoad(int load_);
        virtual int getLoad(void) const;

    protected:
        sfSchedulerHandle *_handle;
        int _priority;
        int _load;
};

#endif // __SF_TASK_H__

