Public Member Functions | Private Attributes

TAO_Multi_Priority_Mapping Class Reference

An implementation of the Priority_Mapping interface for communication between different platforms. More...

#include <Multi_Priority_Mapping.h>

Inheritance diagram for TAO_Multi_Priority_Mapping:
Inheritance graph
[legend]
Collaboration diagram for TAO_Multi_Priority_Mapping:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TAO_Multi_Priority_Mapping (int base_native_priority, int base_corba_priority, int priority_spacing=1, int priorities_contiguous=1, int policy=ACE_SCHED_FIFO)
 Default constructor.
virtual ~TAO_Multi_Priority_Mapping (void)
 The destructor.
virtual CORBA::Boolean to_native (RTCORBA::Priority corba_priority, RTCORBA::NativePriority &native_priority)
virtual CORBA::Boolean to_CORBA (RTCORBA::NativePriority native_priority, RTCORBA::Priority &corba_priority)

Private Attributes

int base_native_priority_
 The base settings.
int base_corba_priority_
const int priority_spacing_
const int priorities_contiguous_
int policy_
 The scheduling policy.
int const min_
 The range.
int const max_

Detailed Description

An implementation of the Priority_Mapping interface for communication between different platforms.

This implementation uses a custom mapping between the range of priorities for a given scheduling class (ACE_SCHED_OTHER, ACE_SCHED_FIFO, ACE_SCHED_RR) and the valid range of CORBA priorities (0...32767)

Definition at line 44 of file Multi_Priority_Mapping.h.


Constructor & Destructor Documentation

TAO_Multi_Priority_Mapping::TAO_Multi_Priority_Mapping ( int  base_native_priority,
int  base_corba_priority,
int  priority_spacing = 1,
int  priorities_contiguous = 1,
int  policy = ACE_SCHED_FIFO 
)

Default constructor.

Parameters:
base_native_priority The native priority to use for the highest priority endpoint.
base_corba_priority The corba priority to use for the highest priority endpoint
priority_spacing The priority increment to use between endpoints
priorities_contiguous Some platforms do use contiguous priorities
policy The scheduling policy to use.

Definition at line 18 of file Multi_Priority_Mapping.cpp.

  :  base_native_priority_ (base_native_priority)
  ,  base_corba_priority_ (base_corba_priority)
  ,  priority_spacing_ (priority_spacing)
  ,  priorities_contiguous_(priorities_contiguous)
  ,  policy_ (policy)
  ,  min_ (ACE_Sched_Params::priority_min (this->policy_))
  ,  max_ (ACE_Sched_Params::priority_max (this->policy_))
{
  if ( this->min_ < this->max_ )
  {
     if (base_native_priority_ < this->min_)
     {
        if (TAO_debug_level > 2)
        {
           ACE_DEBUG ((LM_DEBUG,
                       "TAO (%P|%t) - Multi_Priority_Mapping::ctor: "
                       " base_native_priority %d out of range [%d,%d]\n",
                        base_native_priority_, this->min_, this->max_));
        }
     }
  }
  else
  {
     if (base_native_priority_ > this->min_)
     {
        if (TAO_debug_level > 2)
        {
           ACE_DEBUG ((LM_DEBUG,
                       "TAO (%P|%t) - Multi_Priority_Mapping::ctor: "
                       " base_native_priority %d out of range [%d,%d]\n",
                        base_native_priority_, this->min_, this->max_));
        }
     }
  }

  if (base_corba_priority_ > RTCORBA::maxPriority)
    {
       if (TAO_debug_level > 2)
         {
           ACE_DEBUG ((LM_DEBUG,
             "TAO (%P|%t) - Multi_Priority_Mapping::ctor: "
             " base_corba_priority %d out of range [%d,%d]\n",
             base_corba_priority_, RTCORBA::minPriority, RTCORBA::maxPriority));
         }
    }
}

TAO_Multi_Priority_Mapping::~TAO_Multi_Priority_Mapping ( void   )  [virtual]

The destructor.

Definition at line 71 of file Multi_Priority_Mapping.cpp.

{
}


Member Function Documentation

CORBA::Boolean TAO_Multi_Priority_Mapping::to_CORBA ( RTCORBA::NativePriority  native_priority,
RTCORBA::Priority &  corba_priority 
) [virtual]

Implements TAO_Priority_Mapping.

Definition at line 146 of file Multi_Priority_Mapping.cpp.

{
  // Check for an invalid native priority
  if ((this->min_ < this->max_ && (native_priority < this->min_ || native_priority > this->base_native_priority_ )) ||
      (this->min_ > this->max_ && (native_priority < this->base_corba_priority_ || native_priority > this->min_)))
  {
     if (TAO_debug_level > 2)
     {
        ACE_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t) - Multi_Priority_Mapping::to_CORBA: "
                    " priority %d out of range [%d,%d]\n",
                    native_priority, this->min_, this->base_corba_priority_));
     }
     return 0;
  }

  if (native_priority == base_native_priority_)
  {
     // If this is the highest priority endpoint, then just give it the highest priority corba base priority
     corba_priority = static_cast<RTCORBA::Priority> (base_corba_priority_);
  }
  else
  {
     if (priorities_contiguous_ == 1)
     {
        if ( this->min_ < this->max_ )
        {
           corba_priority = static_cast<RTCORBA::Priority> 
             (((native_priority - base_native_priority_) * priority_spacing_) + base_corba_priority_);
        }
        else
        {
           corba_priority = static_cast<RTCORBA::Priority> 
             (((base_native_priority_ - native_priority) * priority_spacing_) + base_corba_priority_);
        }
     }
     else
     {
        // Start at the max priority and search until we reach the base priority
        int last_priority = this->base_native_priority_;
        while (true)
        {
           int previous_priority = ACE_Sched_Params::previous_priority (this->policy_,
                                                                        last_priority,
                                                                        ACE_SCOPE_THREAD);
           last_priority = previous_priority;

           if (last_priority == this->min_)
           {
              break;
           }

           if ( this->min_ < this->max_ )
           {
              if (base_native_priority_ >= previous_priority) break;
           }
           else
           {
              if (base_native_priority_ <= previous_priority) break;
           }
        }

        int priority_ndx = 1;
        while (true)
        {
           if (last_priority == this->min_)
           {
              break;
           }

           if ( this->min_ < this->max_ )
           {
              if (native_priority >= last_priority) break;
           }
           else
           {
              if (native_priority <= last_priority) break;
           }

           int previous_priority = ACE_Sched_Params::previous_priority (this->policy_,
                                                                        last_priority,
                                                                        ACE_SCOPE_THREAD);
           last_priority = previous_priority;
           priority_ndx++;
        }

        corba_priority = static_cast<RTCORBA::Priority> 
          (base_corba_priority_ - priority_ndx);
     }
  }

  return 1;
}

CORBA::Boolean TAO_Multi_Priority_Mapping::to_native ( RTCORBA::Priority  corba_priority,
RTCORBA::NativePriority &  native_priority 
) [virtual]

Implements TAO_Priority_Mapping.

Definition at line 76 of file Multi_Priority_Mapping.cpp.

{
  // Check for an invalid native priority
  if (corba_priority < RTCORBA::minPriority || corba_priority > this->base_corba_priority_ )
  {
     if (TAO_debug_level > 2)
     {
        ACE_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t) - Multi_Priority_Mapping::to_native: "
                    " corba priority %d out of range [%d,%d]\n",
                    corba_priority, RTCORBA::minPriority, this->base_corba_priority_));
     }
     return 0;
  }

  if (corba_priority == base_corba_priority_)
  {
     // If this is the highest priority endpoint, then just give it the highest priority corba base priority
     native_priority = static_cast<RTCORBA::NativePriority> (base_native_priority_);
  }
  else
  {
     if (priorities_contiguous_ == 1)
     {
        if ( this->min_ < this->max_ )
        {
           native_priority = static_cast<RTCORBA::NativePriority> 
             (((corba_priority - base_corba_priority_) / priority_spacing_) + base_native_priority_);
        }
        else
        {
           native_priority = static_cast<RTCORBA::NativePriority> 
             (((base_corba_priority_ - corba_priority) / priority_spacing_) + base_native_priority_);
        }
     }
     else
     {
        // Start at the max priority and search until we reach the base priority
        int last_priority = this->base_corba_priority_;
        while (true)
        {
           if (last_priority == RTCORBA::minPriority) break;
           if (base_corba_priority_ >= --last_priority) break;
        }

        int priority_ndx = 0;
        while (true)
        {
           if (last_priority == RTCORBA::minPriority) break;
           if (corba_priority >= --last_priority) break;
           priority_ndx++;
        }

        // Start at the max priority and search until we reach the base priority
        last_priority = this->base_native_priority_;
        for (int current_ndx = 0; current_ndx < priority_ndx; current_ndx++)
        {
           native_priority = static_cast<RTCORBA::NativePriority> 
             (ACE_Sched_Params::previous_priority (this->policy_,
                                                   last_priority,
                                                   ACE_SCOPE_THREAD));
        }
     }
  }

  return 1;
}


Member Data Documentation

Definition at line 78 of file Multi_Priority_Mapping.h.

The base settings.

Definition at line 77 of file Multi_Priority_Mapping.h.

int const TAO_Multi_Priority_Mapping::max_ [private]

Definition at line 88 of file Multi_Priority_Mapping.h.

int const TAO_Multi_Priority_Mapping::min_ [private]

The range.

Definition at line 87 of file Multi_Priority_Mapping.h.

The scheduling policy.

Definition at line 84 of file Multi_Priority_Mapping.h.

Definition at line 81 of file Multi_Priority_Mapping.h.

Definition at line 80 of file Multi_Priority_Mapping.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines