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

MinMaxTaskAdvocate.cc

Go to the documentation of this file.
00001 /*
00002  * MinMaxTaskAdvocate.cc
00003  *
00004  * Copyright (c) 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 MinMaxTaskAdvocate.cc
00014  *
00015  * Implementation of the MinMaxTaskAdvocate class.
00016  */
00017 
00018 #include "config.h"
00019 
00020 #include <limits.h>
00021 #include <iostream>
00022 
00023 #include <instrumentation.h>
00024 
00025 #include "MinMaxTaskAdvocate.hh"
00026 
00027 using namespace std;
00028 
00029 #ifndef max
00030 #define max(x, y) (((x) > (y)) ? (x) : (y))
00031 #endif
00032 
00033 #ifndef min
00034 #define min(x, y) (((x) < (y)) ? (x) : (y))
00035 #endif
00036 
00037 MinMaxTaskAdvocate::MinMaxTaskAdvocate(void)
00038 {
00039     this->mm_Minimum = 0;
00040     this->mm_Maximum = ULONG_MAX;
00041 }
00042 
00043 MinMaxTaskAdvocate::~MinMaxTaskAdvocate(void)
00044 {
00045 }
00046 
00047 void MinMaxTaskAdvocate::SetDelegateAttribute(const char *name,
00048                                               const CORBA::Any &value)
00049     throw (CORBA::SystemException)
00050 {
00051     if( strcasecmp(name, "minimum") == 0 )
00052     {
00053         const char *str;
00054         
00055         if( value >>= this->mm_Minimum )
00056         {
00057         }
00058         else if( (value >>= str) &&
00059                  (sscanf(str, "%d", &this->mm_Minimum) == 1) )
00060         {
00061         }
00062         else
00063         {
00064             throw CORBA::BAD_PARAM();
00065         }
00066     }
00067     else if( strcasecmp(name, "maximum") == 0 )
00068     {
00069         const char *str;
00070         
00071         if( value >>= this->mm_Maximum )
00072         {
00073         }
00074         else if( (value >>= str) &&
00075                  (sscanf(str, "%d", &this->mm_Maximum) == 1) )
00076         {
00077         }
00078         else
00079         {
00080             throw CORBA::BAD_PARAM();
00081         }
00082     }
00083     else
00084     {
00085         this->RealTimeTaskDelegateImpl::SetDelegateAttribute(name, value);
00086     }
00087 }
00088 
00089 CORBA::Any_ptr MinMaxTaskAdvocate::GetDelegateAttribute(const char *name)
00090     throw (CORBA::SystemException)
00091 {
00092     CORBA::Any_var retval;
00093     
00094     if( name == NULL )
00095     {
00096         throw CORBA::BAD_PARAM();
00097     }
00098     else if( strcasecmp(name, "minimum") == 0 )
00099     {
00100         retval = new CORBA::Any();
00101         (*retval) <<= this->mm_Minimum;
00102     }
00103     else if( strcasecmp(name, "maximum") == 0 )
00104     {
00105         retval = new CORBA::Any();
00106         (*retval) <<= this->mm_Maximum;
00107     }
00108     else
00109     {
00110         retval = this->RealTimeTaskDelegateImpl::GetDelegateAttribute(name);
00111     }
00112     return( retval._retn() );
00113 }
00114 
00115 Broker::CPUReserve
00116 MinMaxTaskAdvocate::PassCPU(Broker::RealTimeTask_ptr rtt,
00117                             const Broker::CPUReserve &status,
00118                             const Broker::CPUReserve &advice,
00119                             const Broker::KeyedReportParameters &krp)
00120     throw (CORBA::SystemException)
00121 {
00122     Broker::CPUReserve new_advice = advice;
00123     
00124     if( CORBA::is_nil(this->dm_RemoteObject.in()) )
00125     {
00126         throw CORBA::BAD_INV_ORDER();
00127     }
00128 
00129     new_advice.Compute = max(new_advice.Compute, this->mm_Minimum);
00130     new_advice.Compute = min(new_advice.Compute, this->mm_Maximum);
00131     return this->RealTimeTaskDelegateImpl::PassCPU(rtt,
00132                                                    status,
00133                                                    new_advice,
00134                                                    krp);
00135 }

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