Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

StubRealTimeTask.hh

Go to the documentation of this file.
00001 /*
00002  * StubRealTimeTask.hh
00003  *
00004  * Copyright (c) 2003 The University of Utah and the Flux Group.
00005  * All rights reserved.
00006  *
00007  * This file is licensed under the terms of the GNU Public License.  
00008  * See the file "license.terms" for restrictions on redistribution 
00009  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  */
00011 
00012 /**
00013  * @file StubRealTimeTask.hh
00014  *
00015  * Header file and implementation for the StubRealTimeTask class.
00016  */
00017 
00018 #ifndef _stub_real_time_task_hh
00019 #define _stub_real_time_task_hh
00020 
00021 #include <time_util.h>
00022 
00023 #include "BrokerS.h"
00024 
00025 /**
00026  * A Broker::RealTimeTask class that can be used for testing.
00027  */
00028 class StubRealTimeTask : public POA_Broker::RealTimeTask
00029 {
00030 
00031 public:
00032 
00033     /**
00034      * Construct an empty StubRealTimeTask object.
00035      */
00036     StubRealTimeTask(const char *name)
00037     {
00038         this->srtt_Name = name;
00039     };
00040 
00041     /**
00042      * Deconstruct a StubTask object.
00043      */
00044     virtual ~StubRealTimeTask()
00045     {
00046     };
00047 
00048     /**
00049      * @return The name passed in the constructor.
00050      */
00051     virtual char *Name()
00052         throw (CORBA::SystemException)
00053     {
00054         return( this->srtt_Name._retn() );
00055     };
00056 
00057     /**
00058      * Basic implementation of Broker::Task::BeginCPUScheduling.
00059      *
00060      * @param manager Stored internally.
00061      * @param sp Specifies the "period" and/or "deadline" values.
00062      */
00063     virtual void BeginCPUScheduling(Broker::Manager_ptr manager,
00064                                     const Broker::ScheduleParameters &sp)
00065         throw (CORBA::SystemException,
00066                Broker::DuplicateScheduleParameter,
00067                Broker::InvalidScheduleParameter,
00068                Broker::MissingScheduleParameter)
00069     {
00070         CORBA::ULongLong period = ~0, deadline = ~0;
00071         unsigned int lpc;
00072         const char *str;
00073         
00074         this->srtt_Manager = Broker::Manager::_duplicate(manager);
00075         for( lpc = 0; lpc < sp.length(); lpc++ )
00076         {
00077             if( strcasecmp(sp[lpc].name.in(), "period") == 0 )
00078             {
00079                 CORBA::ULong period_ul;
00080                 
00081                 if( period != ~0ULL )
00082                 {
00083                     throw Broker::DuplicateScheduleParameter("period");
00084                 }
00085                 else if( sp[lpc].value >>= period_ul )
00086                 {
00087                     period = period_ul;
00088                 }
00089                 else if( (sp[lpc].value >>= str) &&
00090                          string_to_microsec(&period, str) )
00091                 {
00092                 }
00093                 else
00094                 {
00095                     throw Broker::InvalidScheduleParameter(
00096                         "'period' is not a time",
00097                         sp[lpc]);
00098                 }
00099             }
00100             else if( strcasecmp(sp[lpc].name.in(), "deadline") == 0 )
00101             {
00102                 CORBA::ULong deadline_ul;
00103                 
00104                 if( deadline != ~0ULL )
00105                 {
00106                     throw Broker::DuplicateScheduleParameter("deadline");
00107                 }
00108                 else if( sp[lpc].value >>= deadline_ul )
00109                 {
00110                     deadline = deadline_ul;
00111                 }
00112                 else if( (sp[lpc].value >>= str) &&
00113                          string_to_microsec(&deadline, str) )
00114                 {
00115                 }
00116                 else
00117                 {
00118                     throw Broker::InvalidScheduleParameter(
00119                         "'deadline' is not a time",
00120                         sp[lpc]);
00121                 }
00122             }
00123         }
00124         
00125         /* Make sure we have everything we need */
00126         if( period == ~0ULL )
00127         {
00128             throw Broker::MissingScheduleParameter("period");
00129         }
00130         /* ... and derive the rest. */
00131         if( deadline == ~0ULL )
00132         {
00133             deadline = period;
00134         }
00135         
00136         this->srtt_Period = period;
00137         this->srtt_Deadline = deadline;
00138     };
00139 
00140     /**
00141      * Empty implementation of Broker::Task::EndCPUScheduling.
00142      */
00143     virtual void EndCPUScheduling(void)
00144         throw (CORBA::SystemException)
00145     {
00146         this->srtt_Manager = Broker::Manager::_nil();
00147     };
00148 
00149     /** @copydoc Broker::RealTimeTask::Period */
00150     virtual CORBA::ULong Period(void)
00151         throw (CORBA::SystemException)
00152     {
00153         return( this->srtt_Period );
00154     };
00155 
00156     /** @copydoc Broker::RealTimeTask::Deadline */
00157     virtual CORBA::ULong Deadline(void)
00158         throw (CORBA::SystemException)
00159     {
00160         return( this->srtt_Deadline );
00161     };
00162 
00163     /** @copydoc Broker::RealTimeTask::GetComputeTime */
00164     virtual CORBA::ULong GetComputeTime(void)
00165         throw (CORBA::SystemException)
00166     {
00167         return( this->srtt_ComputeTime );
00168     };
00169 
00170     /** @copydoc Broker::RealTimeTask::SetComputeTime */
00171     virtual void SetComputeTime(CORBA::ULong usecs)
00172         throw (CORBA::SystemException)
00173     {
00174         this->srtt_ComputeTime = usecs;
00175     };
00176 
00177     /** @copydoc Broker::RealTimeTask::ReportCPU */
00178     virtual void ReportCPU(Broker::RealTimeTask_ptr rtt,
00179                            CORBA::ULong status,
00180                            CORBA::ULong advice)
00181         throw (CORBA::SystemException)
00182     {
00183         this->srtt_Manager->ChangeTaskCPU(rtt,
00184                                           this->srtt_ComputeTime,
00185                                           status,
00186                                           advice);
00187     };
00188 
00189 private:
00190 
00191     /**
00192      * The Broker::Manager used to handle scheduling during contention.  Only
00193      * valid between #BeginCPUScheduling and #EndCPUScheduling calls.
00194      */
00195     Broker::Manager_var srtt_Manager;
00196     
00197     /**
00198      * The task name.
00199      */
00200     CORBA::String_var srtt_Name;
00201 
00202     /**
00203      * The task's period.
00204      */
00205     CORBA::ULong srtt_Period;
00206 
00207     /**
00208      * The task's deadline.
00209      */
00210     CORBA::ULong srtt_Deadline;
00211 
00212     /**
00213      * The task compute time.
00214      */
00215     CORBA::ULong srtt_ComputeTime;
00216     
00217 };
00218 
00219 #endif

Generated on Mon Dec 1 16:29:07 2003 for CPU Broker by doxygen 1.3.4