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

StubPolicy.hh

Go to the documentation of this file.
00001 /*
00002  * StubPolicy.hh
00003  *
00004  * Copyright (c) 2003, 2004 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                Broker::DuplicateScheduleParameter,
00069                Broker::InvalidScheduleParameter,
00070                Broker::MissingScheduleParameter)
00071     {
00072         unsigned int slot;
00073 
00074         slot = this->sp_Tasks.length();
00075         this->sp_Tasks.length(slot + 1);
00076         this->sp_Tasks[slot] = Broker::Task::_duplicate(task);
00077     };
00078 
00079     /**
00080      * Remove a task from the sp_Tasks list.
00081      *
00082      * @param task The task to remove from the policy.
00083      */
00084     void RemoveTask(Broker::Task_ptr task)
00085         throw (CORBA::SystemException)
00086     {
00087         unsigned int lpc;
00088         int slot;
00089 
00090         slot = this->TaskIndex(task);
00091         for( lpc = (unsigned int)slot;
00092              lpc < (this->sp_Tasks.length() - 1);
00093              lpc++ )
00094         {
00095             this->sp_Tasks[lpc] = this->sp_Tasks[lpc + 1];
00096         }
00097         this->sp_Tasks.length(this->sp_Tasks.length() - 1);
00098     };
00099 
00100     /**
00101      * @return The list of tasks that have been added to this policy.
00102      */
00103     Broker::TaskList *GetTaskList(void)
00104         throw (CORBA::SystemException)
00105     {
00106         Broker::TaskList_var retval;
00107 
00108         retval = new Broker::TaskList(this->sp_Tasks);
00109         return( retval._retn() );
00110     };
00111 
00112     /**
00113      * Activate the policy and add the given list of tasks to sp_Tasks.
00114      *
00115      * @param tasks The existing tasks being handled by the broker.
00116      */
00117     void Activate(const Broker::TaskList &tasks)
00118         throw (CORBA::SystemException)
00119     {
00120         unsigned int lpc;
00121 
00122         this->sp_Tasks.length(tasks.length());
00123         for( lpc = 0; lpc < tasks.length(); lpc++ )
00124         {
00125             this->sp_Tasks[lpc] = tasks[lpc];
00126         }
00127     };
00128 
00129     /**
00130      * Deactivate the policy and set the length of sp_Tasks to zero.
00131      */
00132     void Deactivate(void)
00133         throw (CORBA::SystemException)
00134     {
00135         this->sp_Tasks.length(0);
00136     };
00137 
00138     /**
00139      * Change the compute time for the given task to the given advice.
00140      *
00141      * @param task The task whose compute time should be changed.
00142      * @param advice The advocate's advice.
00143      */
00144     Broker::CPUReserve ChangeTaskCPU(Broker::RealTimeTask_ptr task,
00145                                      const Broker::CPUReserve &advice)
00146         throw (CORBA::SystemException, Broker::InvalidState)
00147     {
00148         Broker::CPUReserve retval;
00149 
00150         retval = advice;
00151         retval.Compute = 0;
00152         return retval;
00153     };
00154 
00155     /** @copydoc Broker::Policy::GetMaxCPUAllocation */
00156     virtual CORBA::Float GetMaxCPUAllocation(void)
00157         throw (CORBA::SystemException)
00158     {
00159         return this->sp_MaxCPUAllocation;
00160     };
00161     
00162     /** @copydoc Broker::Policy::SetMaxCPUAllocation */
00163     virtual void SetMaxCPUAllocation(CORBA::Float amount)
00164         throw (CORBA::SystemException)
00165     {
00166         this->sp_MaxCPUAllocation = amount;
00167     };
00168 
00169     /**
00170      * Find a task in the sp_Tasks list.
00171      *
00172      * @param task The task to find.
00173      * @return The index of the task in sp_Tasks or -1 if it could not be
00174      *         found.
00175      */
00176     int TaskIndex(Broker::Task_ptr task)
00177     {
00178         unsigned int lpc;
00179         int retval = -1;
00180         
00181         for( lpc = 0;
00182              (lpc < this->sp_Tasks.length()) && (retval == -1);
00183              lpc++ )
00184         {
00185             if( this->sp_Tasks[lpc]->_is_equivalent(task) )
00186             {
00187                 retval = lpc;
00188             }
00189         }
00190         return( retval );
00191     }
00192 
00193     /** The policy's name. */
00194     CORBA::String_var sp_Name;
00195     /** The list of tasks being managed by this policy. */
00196     Broker::TaskList sp_Tasks;
00197     /** The maximum CPU allocation. */
00198     CORBA::Float sp_MaxCPUAllocation;
00199     
00200 };
00201 
00202 #endif

Generated on Fri Oct 22 07:50:25 2004 for CPU Broker by  doxygen 1.3.9.1