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

StubPolicy.hh

Go to the documentation of this file.
00001 /*
00002  * StubPolicy.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 StubPolicy.hh
00014  *
00015  * Header file and implementation for the StubPolicy class.
00016  */
00017 
00018 #ifndef _stub_policy_hh
00019 #define _stub_policy_hh
00020 
00021 #include "BrokerS.h"
00022 
00023 /**
00024  * A Broker::Policy subclass that can be used for testing.
00025  */
00026 class StubPolicy : public POA_Broker::Policy
00027 {
00028 
00029 public:
00030 
00031     /**
00032      * Construct a StubPolicy object with the given value.
00033      *
00034      * @param name The policy name.
00035      */
00036     StubPolicy(const char *name)
00037     {
00038         this->sp_Name = name;
00039     };
00040 
00041     /**
00042      * Deconstruct a StubPolicy object.
00043      */
00044     virtual ~StubPolicy()
00045     {
00046     };
00047 
00048     /**
00049      * @return The name passed to the constructor.
00050      */
00051     char *Name(void)
00052         throw (CORBA::SystemException)
00053     {
00054         CORBA::String_var retval;
00055 
00056         retval = this->sp_Name;
00057         return( retval._retn() );
00058     }
00059 
00060     /**
00061      * Add a task to the sp_Tasks list.
00062      *
00063      * @param task The task to add to the policy.
00064      * @param sp The task's scheduling parameters.
00065      */
00066     void AddTask(Broker::Task_ptr task, const Broker::ScheduleParameters &sp)
00067         throw (CORBA::SystemException)
00068     {
00069         unsigned int slot;
00070 
00071         slot = this->sp_Tasks.length();
00072         this->sp_Tasks.length(slot + 1);
00073         this->sp_Tasks[slot] = task; // XXX dup?
00074     };
00075 
00076     /**
00077      * Remove a task from the sp_Tasks list.
00078      *
00079      * @param task The task to remove from the policy.
00080      */
00081     void RemoveTask(Broker::Task_ptr task)
00082         throw (CORBA::SystemException)
00083     {
00084         unsigned int lpc;
00085         int slot;
00086 
00087         slot = this->TaskIndex(task);
00088         for( lpc = (unsigned int)slot;
00089              lpc < (this->sp_Tasks.length() - 1);
00090              lpc++ )
00091         {
00092             this->sp_Tasks[lpc] = this->sp_Tasks[lpc + 1];
00093         }
00094         this->sp_Tasks.length(this->sp_Tasks.length() - 1);
00095     };
00096 
00097     /**
00098      * @return The list of tasks that have been added to this policy.
00099      */
00100     Broker::TaskList *GetTaskList(void)
00101         throw (CORBA::SystemException)
00102     {
00103         Broker::TaskList_var retval;
00104 
00105         retval = new Broker::TaskList(this->sp_Tasks);
00106         return( retval._retn() );
00107     };
00108 
00109     /**
00110      * Activate the policy and add the given list of tasks to sp_Tasks.
00111      *
00112      * @param tasks The existing tasks being handled by the broker.
00113      */
00114     void Activate(const Broker::TaskList &tasks)
00115         throw (CORBA::SystemException)
00116     {
00117         unsigned int lpc;
00118 
00119         this->sp_Tasks.length(tasks.length());
00120         for( lpc = 0; lpc < tasks.length(); lpc++ )
00121         {
00122             this->sp_Tasks[lpc] = tasks[lpc];
00123         }
00124     };
00125 
00126     /**
00127      * Deactivate the policy and set the length of sp_Tasks to zero.
00128      */
00129     void Deactivate(void)
00130         throw (CORBA::SystemException)
00131     {
00132         this->sp_Tasks.length(0);
00133     };
00134 
00135     /**
00136      * Change the compute time for the given task to the given advice.
00137      *
00138      * @param task The task whose compute time should be changed.
00139      * @param ct The current compute time.
00140      * @param status The reported status value.
00141      * @param advice The advocate's advice.
00142      */
00143     void ChangeTaskCPU(Broker::RealTimeTask_ptr task,
00144                        CORBA::ULong ct,
00145                        CORBA::ULong status,
00146                        CORBA::ULong advice)
00147         throw (CORBA::SystemException, Broker::InvalidState)
00148     {
00149         task->SetComputeTime(advice);
00150     };
00151 
00152     /**
00153      * Find a task in the sp_Tasks list.
00154      *
00155      * @param task The task to find.
00156      * @return The index of the task in sp_Tasks or -1 if it could not be
00157      *         found.
00158      */
00159     int TaskIndex(Broker::Task_ptr task)
00160     {
00161         unsigned int lpc;
00162         int retval = -1;
00163         
00164         for( lpc = 0;
00165              (lpc < this->sp_Tasks.length()) && (retval == -1);
00166              lpc++ )
00167         {
00168             if( this->sp_Tasks[lpc]->_is_equivalent(task) )
00169             {
00170                 retval = lpc;
00171             }
00172         }
00173         return( retval );
00174     }
00175 
00176     /** The policy's name. */
00177     CORBA::String_var sp_Name;
00178     /** The list of tasks being managed by this policy. */
00179     Broker::TaskList sp_Tasks;
00180     
00181 };
00182 
00183 #endif

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