Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Examples  

task.h

Go to the documentation of this file.
00001 
00002 //
00003 // YASA project, task support
00004 //
00005 // Project: Yasa 2
00006 // Author : Jan Blumenthal
00007 // Start  : 2002/02/28
00008 // $Header: /sources/yasa/yasagui/task.h,v 1.5 2003/01/24 15:47:43 bj Exp $
00009 //
00011 //
00012 // This program is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU General Public License as published by
00014 // the Free Software Foundation; either version 2 of the License, or
00015 // (at your option) any later version.
00016 //
00017 // This program is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU General Public License
00023 // along with this program (See the included file COPYING);
00024 // if not, write to the Free Software Foundation, Inc.,
00025 // 675 Mass Ave, Cambridge, MA 02139, USA.
00026 //
00028 #ifndef YASAGUI_TASK_INCLUDE
00029 #define YASAGUI_TASK_INCLUDE
00030 
00031 #include <yasagui/yasagui.h>
00032 #include <qobject.h>
00033 #include "mutex.h"
00034 #include <qsortedlist.h>
00035 
00037 class YTaskSet;
00038 class YProject;
00039 
00042 class YResumeTime : public YObject
00043 {   Q_OBJECT
00044     YTIME                   time;                                           // time of action
00045 public:
00046                             YResumeTime(const YObjectArgs &args) : YObject(args),
00047                             time(YASA_TIME_INFINITY)
00048                             {
00049                                 connect(&time, SIGNAL(UpdateObject()), this, SLOT( UpdateName() ) );
00050                             }
00051     int                     InitInstance(YASA_TIME t)
00052                             {
00053                                 time=t;
00054                                 return 0;
00055                             }
00056     const YTIME &           GetTime() const                                 { return time;              }
00057     void                    SetTime(YASA_TIME t);
00058     virtual int             SetConfig(YInputParser &parser);
00059     virtual int             GetConfig(YOutputParser &parser);
00060 public slots:
00061     void                    UpdateName();
00062 /*                          {
00063                                 if ( GetName() != time.GetVisibleContentString() )
00064                                     SetName(time.GetVisibleContentString());
00065                             }*/
00066 };
00068 class YResumeTimeSet : public YSet
00069 {
00070 public:                     YResumeTimeSet() : YSet(YPC_RESUME_TIME, MSGP_ZERO, MSGP_DEFAULT_RESUMENAME)
00071                             {
00072                             }
00073     void                    Sort()                                  {   sort();                             }
00074 protected:
00075     virtual YObject*        AllocNewItem(const YObjectArgs &args)           { return new YResumeTime(args); }
00076     virtual void            AppendItem(YObject *object)             { if (object)
00077                                                                         QList<YObject>::inSort(object);     }
00078     virtual int             compareItems( QCollection::Item item1, QCollection::Item item2 )
00079     {
00080         if ( ((YResumeTime*)item1)->GetTime() < ((YResumeTime*)item2)->GetTime() )
00081             return -1;
00082         if ( ((YResumeTime*)item1)->GetTime() > ((YResumeTime*)item2)->GetTime() )
00083             return 1;
00084         return 0;
00085     }
00086 };
00087 
00089 inline void YResumeTime::UpdateName()
00090 {
00091     if ( GetName() != time.GetVisibleContentString() )
00092         SetName(time.GetVisibleContentString());
00093     if ( GetSet() )
00094         ((YResumeTimeSet*)GetSet())->Sort();
00095 }
00096 
00097 
00099 // This class contains information when should which action start or end
00100 class YResourceAction : public YObject
00101 {   Q_OBJECT
00102     YTIME                   time;                       
00103     QString                 mutexname;                  
00104     YObject                 *mutex;                     
00105     YASA_RESOURCEACTION     action;                     
00106 public:
00107                             YResourceAction(const YObjectArgs &args) :
00108                             YObject(args),
00109                             time(YASA_TIME_INFINITY),
00110                             mutex(0),
00111                             action(YASAA_NO_MORE_ACTION)
00112                             {
00113                                 connect(&action, SIGNAL(UpdateObject()), this, SLOT( ObjectUpdated() ) );
00114                                 connect(&time, SIGNAL(UpdateObject()), this, SLOT( UpdateName() ) );
00115                             }
00116     const YTIME &           GetTime() const                     {   return time;                        }
00117     YObject*                GetMutex();
00118     const YASA_RESOURCEACTION&  GetAction() const               {   return action;                      }
00119     void                    SetTime(YASA_TIME t)                {   time.SetContent(t);                 }
00120     void                    SetMutex(YObject *m);
00121     void                    SetAction(int id)                   {   action.SetContent(id);              }
00122     virtual int             SetConfig(YInputParser &parser);
00123     virtual int             GetConfig(YOutputParser &parser);
00124 public slots:
00125     void                    MutexUpdated(YObject *);
00126     void                    MutexDestroyed();
00127     void                    UpdateName();
00128 };
00129 
00130 
00132 class YResourceActionSet : public YSet
00133 {
00134 public:                     YResourceActionSet() : YSet(YPC_RESOURCE_TIME, MSGP_ZERO, MSGP_DEFAULT_RESOURCENAME)
00135                             { }
00136     static YMutexSet*       GetMutexSet(YSet *set);
00137     void                    Sort()                                  {   sort();                             }
00138 protected:
00139     virtual YObject*        AllocNewItem(const YObjectArgs &args)   { return new YResourceAction(args);     }
00140     virtual void            AppendItem(YObject *object)             { if (object)
00141                                                                         QList<YObject>::inSort(object);     }
00142     virtual int             compareItems( QCollection::Item item1, QCollection::Item item2 )
00143     {
00144         if ( ((YResourceAction*)item1)->GetTime() < ((YResourceAction*)item2)->GetTime() )
00145             return -1;
00146         if ( ((YResourceAction*)item1)->GetTime() > ((YResourceAction*)item2)->GetTime() )
00147             return 1;
00148         return 0;
00149     }
00150 };
00151 
00153 inline void YResourceAction::UpdateName()
00154 {
00155     if ( GetName() != time.GetVisibleContentString() )
00156         SetName(time.GetVisibleContentString());
00157     if ( GetSet() )
00158         ((YResourceActionSet*)GetSet())->Sort();
00159 }
00160 
00161 
00163 class YTask;
00164 class YTaskSet : public YSet
00165 {   YTask                   *parenttask;
00166 public:                     YTaskSet(YTask *p);
00167 protected:
00168     inline virtual YObject* AllocNewItem(const YObjectArgs &args);
00169     virtual YActions*       GetItemActions() const
00170                             { return YActionHandler::GetActions(YActionHandler::TASK_ACTIONS);  }
00171 };
00172 
00173 
00176 class YTask : public YObject
00177 {
00178     Q_OBJECT
00179     YTaskSet                *parenttaskset;
00180     YASA_PERIOD             period;                 
00181     YASA_OFFSET             offset;                 
00182     YASA_REQUIREDTIME       requiredtime;           
00183     YASA_LAXITY             laxity;
00184     YASA_DEADLINE           deadline;               
00185     YASA_DEADLINETOLERANCE  deadlinetolerance;      
00186     YASA_CPU                cpu;                    
00187     YASA_TASKTYPE           tasktype;               
00188     YASA_SERVERTYPE         servertype;
00189     YASA_PRIORITY           priority;
00190     YASA_DLBEHAVIOUR        deadlinebehaviour;      
00191     YTaskSet                subtaskset;             
00192     YResourceActionSet      resourceactionset;      
00193     YResumeTimeSet          resumetimeset;          
00194     YString                 function_init;          
00195     YString                 function_execute;       
00196     YString                 function_cleanup;       
00197 public:                     YTask(const YObjectArgs &args);
00198     int                     InitInstance();
00199     YTask*                  CreateSubTask(const YObjectArgs &i );
00200     const YTaskSet*         CreateParentTaskSet()               { return parenttaskset;         }
00201 //  const QList<YTask> &    GetSubTaskSet()                     { return subtaskset;            }
00202 //  YTaskSet &              GetSubTaskSet()                     { return taskset;               }
00203     YResumeTimeSet &        GetResumeTimeSet()                  { return resumetimeset;         }
00204     YResourceActionSet &    GetResourceActionSet()              { return resourceactionset;     }
00205     virtual int             SetConfig(YInputParser &parser);
00206     virtual int             GetConfig(YOutputParser &parser);
00207 
00208     YASA_CPU &              GetCPU()                            { return cpu;                   }
00209     const YASA_PRIORITY &   GetPriority() const                 { return priority;              }
00210     const YASA_PERIOD &     GetPeriod() const                   { return period;                }
00211     const YASA_OFFSET &     GetOffset() const                   { return offset;                }
00212     const YASA_REQUIREDTIME & GetRequiredTime() const           { return requiredtime;          }
00213     const YASA_LAXITY &     GetLaxity() const                   { return laxity;                }
00214     const YASA_DEADLINE &   GetDeadline() const                 { return deadline;              }
00215     const YASA_DEADLINETOLERANCE & GetDeadlineTolerance() const { return deadlinetolerance;     }
00216     const YASA_DLBEHAVIOUR & GetDeadlineBehaviour() const       { return deadlinebehaviour;     }
00217     const YASA_TASKTYPE &   GetTaskType() const                 { return tasktype;              }
00218     const YASA_SERVERTYPE & GetServerType() const               { return servertype;            }
00219     const YString&          GetInitFunction() const             { return function_init;         }
00220     const YString&          GetExecuteFunction() const          { return function_execute;      }
00221     const YString&          GetCleanupFunction() const          { return function_cleanup;      }
00222     YProject*               GetProject() const                  { return ((YProject*)GetSet()->GetParent()); }
00223     YTask*                  GetEmergencyThread() const          { return 0;                     }
00224 
00225     void                    SetCPU(int c)                       { cpu=c;                        }
00226     void                    SetPriority(int p)                  { priority=p;                   }
00227     void                    SetPeriod(YASA_TIME p)              { period=p;                     }
00228     void                    SetOffset(YASA_TIME o)              { offset=o;                     }
00229     void                    SetRequiredTime(YASA_TIME r)        { requiredtime=r;               }
00230     void                    SetDeadline(YASA_DEADLINE d)        { deadline=d;                   }
00231     void                    SetDeadlineTolerance(YASA_TIME d)   { deadlinetolerance=d;          }
00232     void                    SetDeadlineBehaviour(int b)         { deadlinebehaviour=b;          }
00233     void                    SetTaskType(int t)                  { tasktype=t;                   }
00234     void                    SetServerType(int t)                { servertype=t;                 }
00235     void                    SetInitFunction(const QString &f)   { function_init=f;              }
00236     void                    SetExecuteFunction(const QString &f){ function_execute=f;           }
00237     void                    SetCleanupFunction(const QString &f){ function_cleanup=f;           }
00238 public slots:
00239     void                    SubTaskChanged(YObject *object);
00240     void                    ResumeTimeChanged(YObject *object);
00241     void                    ResourceActionChanged(YObject *object);
00242 
00243 
00244     void                    CalculateLaxity()               {   laxity.operator =(deadline-requiredtime);   }
00245 };
00246 
00247 
00249 #endif                                                                  // ifndef YASAGUI_TASK_INCLUDE

Generated on Thu Feb 13 23:43:56 2003 for Yasa by doxygen1.3-rc3