nBandwidthArbitrator Class Reference

#include <nPriorizing.h>

Inheritance diagram for nBandwidthArbitrator:

Inheritance graph
[legend]
Collaboration diagram for nBandwidthArbitrator:

Collaboration graph
[legend]

List of all members.

Public Member Functions

bool Fill (nSendBuffer &buffer, nBandwidthControl &control)
void Timestep (REAL dt)
bool UseBandwidth (REAL dt)

Protected Member Functions

 nBandwidthArbitrator ()
 ~nBandwidthArbitrator ()

Private Member Functions

nType FirstType () const
virtual void OnChange ()
virtual bool DoUseBandwidth (REAL dt)=0
virtual tHeapBaseHeap () const
virtual REAL TimeScale ()
virtual REAL PacketOverhead ()

Private Attributes

nBandwidthScedulersceduler_

Friends

class nBandwidthSceduler
class tReferencable< nBandwidthArbitrator >


Detailed Description

Definition at line 119 of file nPriorizing.h.


Constructor & Destructor Documentation

nBandwidthArbitrator::nBandwidthArbitrator (  )  [protected]

Definition at line 134 of file nPriorizing.cpp.

References NULL, and sceduler_.

00135 {
00136     sceduler_ = NULL;
00137 }

nBandwidthArbitrator::~nBandwidthArbitrator (  )  [protected]

Definition at line 139 of file nPriorizing.cpp.

References NULL, nBandwidthSceduler::RemoveArbitrator(), tHeapElement::RemoveFromHeap(), sceduler_, and tASSERT.

00140 {
00141     if ( sceduler_ )
00142     {
00143         sceduler_->RemoveArbitrator( *this );
00144     }
00145 
00146     tASSERT( NULL == sceduler_ );
00147 
00148     this->RemoveFromHeap();
00149 }

Here is the call graph for this function:


Member Function Documentation

bool nBandwidthArbitrator::Fill ( nSendBuffer buffer,
nBandwidthControl control 
)

Definition at line 152 of file nPriorizing.cpp.

References FirstType(), Heap(), nBandwidthTaskPriorizer::Next(), nBandwidthTaskPriorizer::PeekNext(), REAL, nBandwidthControl::Score(), and tHeapElement::SetVal().

Referenced by nBandwitdhDistributor::DoUseBandwidth().

00153 {
00154     // return whether a message was sent
00155     bool ret = false;
00156 
00157     // find heap to use
00158     nType type = this->FirstType();
00159     if ( type < nBandwidthTask::Type_Count )
00160     {
00161         REAL totalPriority = 0.0f;                              // total prioirty of already added messages
00162 
00163         bool first = true;
00164         bool goon = true;
00165         while ( goon )
00166         {
00167             goon = false;
00168 
00169             tJUST_CONTROLLED_PTR< nBandwidthTask > next = this->PeekNext( type );
00170             if ( next )
00171             {
00172                 REAL priority = next->Priority();
00173                 REAL value = next->Val();
00174 
00175                 // see if we have enough bandwidth reservers to send message
00176                 if ( !first || value  * this->TimeScale() > -control.Score() )
00177                 {
00178                     // see if the priority of the next sent message justifies the delay caused for the messages already in the buffer
00179                     if ( priority * this->PacketOverhead() > totalPriority * next->EstimateSize() )
00180                     {
00181                         // extract message
00182                         next = this->Next( type );
00183 
00184                         // send it
00185                         next->Execute( buffer, control );
00186 
00187                         // sum up priority
00188                         totalPriority += priority;
00189 
00190                         // try another one!
00191                         goon = true;
00192                         ret = true;
00193                     }
00194                 }
00195             }
00196 
00197             first = false;
00198         }
00199     }
00200 
00201     // reduce priority so it is not picked until the next call to Timestep
00202     this->SetVal( this->Val() - 100.0f, *this->Heap() );
00203 
00204     return ret;
00205 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nBandwidthArbitrator::Timestep ( REAL  dt  ) 

Definition at line 208 of file nPriorizing.cpp.

References GrowingArrayBase::Len(), tHeap< T >::Len(), OnChange(), tArray< T, MALLOC >::SetLen(), and nBandwidthTaskPriorizer::Tasks().

00209 {
00210     for ( int i = 0; i < nBandwidthTask::Type_Count; ++i )
00211     {
00212         nType type = nType(i);
00213 
00214         nTaskHeap& heap = this->Tasks( type );
00215         int j;
00216 
00217         static tArray< nBandwidthTask* > tasks;
00218         tasks.SetLen( 0 );
00219 
00220         // copy heap; otherwise, we would risk updating elements twice or not al all
00221         for ( j = heap.Len()-1; j>=0; --j )
00222         {
00223             tasks[j] = heap(j);
00224         }
00225 
00226         for ( j = tasks.Len()-1; j>=0; --j )
00227         {
00228             tasks(j)->Timestep( dt );
00229         }
00230     }
00231 
00232     this->OnChange();
00233 }

Here is the call graph for this function:

bool nBandwidthArbitrator::UseBandwidth ( REAL  dt  )  [inline]

Definition at line 127 of file nPriorizing.h.

References DoUseBandwidth().

Referenced by nBandwidthSceduler::UseBandwidth().

00127 { return DoUseBandwidth( dt ); }        // consumes some bandwidth

Here is the call graph for this function:

Here is the caller graph for this function:

nBandwidthArbitrator::nType nBandwidthArbitrator::FirstType (  )  const [private]

Definition at line 236 of file nPriorizing.cpp.

Referenced by Fill().

00237 {
00238     for ( int i = 0; i < nBandwidthTask::Type_Count; ++i )
00239     {
00240         nType type = nType(i);
00241         if ( this->Tasks(type).Len() > 0 )
00242         {
00243             return type;
00244         }
00245     }
00246 
00247     return nBandwidthTask::Type_Count;
00248 }

Here is the caller graph for this function:

void nBandwidthArbitrator::OnChange (  )  [private, virtual]

Reimplemented from nBandwidthTaskPriorizer.

Definition at line 251 of file nPriorizing.cpp.

References tHeap< T >::Len(), REAL, tHeapElement::SetVal(), and nBandwidthTaskPriorizer::Tasks().

Referenced by Timestep().

00252 {
00253     REAL value = 0.0f;
00254 
00255     for ( int i = 0; i < nBandwidthTask::Type_Count; ++i )
00256     {
00257         nType type = nType(i);
00258         const nTaskHeap& heap = this->Tasks(type);
00259         if ( heap.Len() > 0 )
00260         {
00261             value += heap(0)->Val();
00262         }
00263     }
00264 
00265     this->SetVal( value, *this->Heap() );
00266 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool nBandwidthArbitrator::DoUseBandwidth ( REAL  dt  )  [private, pure virtual]

Implemented in nBandwitdhDistributor.

Referenced by UseBandwidth().

Here is the caller graph for this function:

tHeapBase * nBandwidthArbitrator::Heap (  )  const [private, virtual]

Implements tHeapElement.

Definition at line 268 of file nPriorizing.cpp.

References nBandwidthSceduler::arbitratorHeap_, NULL, and sceduler_.

Referenced by Fill().

00269 {
00270     if ( !sceduler_ )
00271     {
00272         return NULL;
00273     }
00274 
00275     return &sceduler_->arbitratorHeap_;
00276 }

Here is the caller graph for this function:

virtual REAL nBandwidthArbitrator::TimeScale (  )  [inline, private, virtual]

Reimplemented in nBandwitdhDistributor.

Definition at line 137 of file nPriorizing.h.

00137 { return 0.1f; }                                                // higher values let really urgent messages be sent even if the bandwidth control objectd

virtual REAL nBandwidthArbitrator::PacketOverhead (  )  [inline, private, virtual]

Reimplemented in nBandwitdhDistributor.

Definition at line 138 of file nPriorizing.h.

00138 { return 60.0f; }                                       // overhead in bytes per sent packet. Determines average package size


Friends And Related Function Documentation

friend class nBandwidthSceduler [friend]

Definition at line 121 of file nPriorizing.h.

friend class tReferencable< nBandwidthArbitrator > [friend]

Definition at line 122 of file nPriorizing.h.


Member Data Documentation

nBandwidthSceduler* nBandwidthArbitrator::sceduler_ [private]

Definition at line 140 of file nPriorizing.h.

Referenced by nBandwidthSceduler::AddArbitrator(), Heap(), nBandwidthArbitrator(), nBandwidthSceduler::RemoveArbitrator(), and ~nBandwidthArbitrator().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:46:49 2008 for Armagetron Advanced by  doxygen 1.5.4