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 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      */
00065     void AddTask(Broker::Task_ptr task)
00066         throw (CORBA::SystemException)
00067     {
00068         unsigned int slot;
00069 
00070         slot = this->sp_Tasks.length();
00071         this->sp_Tasks.length(slot + 1);
00072         this->sp_Tasks[slot] = task; // XXX dup?
00073     };
00074 
00075     /**
00076      * Remove a task from the sp_Tasks list.
00077      *
00078      * @param task The task to remove from the policy.
00079      */
00080     void RemoveTask(Broker::Task_ptr task)
00081         throw (CORBA::SystemException)
00082     {
00083         unsigned int lpc;
00084         int slot;
00085 
00086         slot = this->TaskIndex(task);
00087         for( lpc = (unsigned int)slot;
00088              lpc < (this->sp_Tasks.length() - 1);
00089              lpc++ )
00090         {
00091             this->sp_Tasks[lpc] = this->sp_Tasks[lpc + 1];
00092         }
00093         this->sp_Tasks.length(this->sp_Tasks.length() - 1);
00094     };
00095 
00096     /**
00097      * Activate the policy and add the given list of tasks to sp_Tasks.
00098      *
00099      * @param tasks The existing tasks being handled by the broker.
00100      */
00101     void Activate(const Broker::TaskList &tasks)
00102         throw (CORBA::SystemException)
00103     {
00104         unsigned int lpc;
00105 
00106         this->sp_Tasks.length(tasks.length());
00107         for( lpc = 0; lpc < tasks.length(); lpc++ )
00108         {
00109             this->sp_Tasks[lpc] = tasks[lpc];
00110         }
00111     };
00112 
00113     /**
00114      * Deactivate the policy and set the length of sp_Tasks to zero.
00115      */
00116     void Deactivate(void)
00117         throw (CORBA::SystemException)
00118     {
00119         this->sp_Tasks.length(0);
00120     };
00121 
00122     /**
00123      * Change the compute time for the given task to the given advice.
00124      *
00125      * @param task The task whose compute time should be changed.
00126      * @param ct The current compute time.
00127      * @param status The reported status value.
00128      * @param advice The advocate's advice.
00129      */
00130     void ChangeTaskCPU(Broker::RealTimeTask_ptr task,
00131                        CORBA::ULong ct,
00132                        CORBA::ULong status,
00133                        CORBA::ULong advice)
00134         throw (CORBA::SystemException, Broker::InvalidState)
00135     {
00136         task->SetComputeTime(advice);
00137     };
00138 
00139     /**
00140      * Find a task in the sp_Tasks list.
00141      *
00142      * @param task The task to find.
00143      * @return The index of the task in sp_Tasks or -1 if it could not be
00144      *         found.
00145      */
00146     int TaskIndex(Broker::Task_ptr task)
00147     {
00148         unsigned int lpc;
00149         int retval = -1;
00150         
00151         for( lpc = 0;
00152              (lpc < this->sp_Tasks.length()) && (retval == -1);
00153              lpc++ )
00154         {
00155             if( this->sp_Tasks[lpc]->_is_equivalent(task) )
00156             {
00157                 retval = lpc;
00158             }
00159         }
00160         return( retval );
00161     }
00162 
00163     /** The policy's name. */
00164     CORBA::String_var sp_Name;
00165     /** The list of tasks being managed by this policy. */
00166     Broker::TaskList sp_Tasks;
00167     
00168 };
00169 
00170 #endif

Generated on Mon Dec 1 16:21:56 2003 for CPUBroker by doxygen 1.3.4