Continuous_Priority_Mapping.cpp

Go to the documentation of this file.
00001 // $Id: Continuous_Priority_Mapping.cpp 76593 2007-01-25 19:19:27Z johnnyw $
00002 
00003 #include "tao/RTCORBA/Continuous_Priority_Mapping.h"
00004 
00005 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00006 
00007 #include "ace/Sched_Params.h"
00008 
00009 ACE_RCSID(RTCORBA, Continuous_Priority_Mapping, "$Id: Continuous_Priority_Mapping.cpp 76593 2007-01-25 19:19:27Z johnnyw $")
00010 
00011 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00012 
00013 TAO_Continuous_Priority_Mapping::TAO_Continuous_Priority_Mapping (int policy)
00014   :  policy_ (policy)
00015    , min_ (ACE_Sched_Params::priority_min (this->policy_))
00016    , max_ (ACE_Sched_Params::priority_max (this->policy_))
00017 {
00018 }
00019 
00020 TAO_Continuous_Priority_Mapping::~TAO_Continuous_Priority_Mapping (void)
00021 {
00022 }
00023 
00024 CORBA::Boolean
00025 TAO_Continuous_Priority_Mapping::to_native (RTCORBA::Priority corba_priority,
00026                                             RTCORBA::NativePriority &native_priority)
00027 {
00028   if (corba_priority < 0)
00029     return false;
00030 
00031 #if defined (ACE_WIN32)
00032 
00033   int current_native_priority = this->min_;
00034   int next_native_priority;
00035   for (int i = 1; i <= corba_priority; ++i)
00036     {
00037       next_native_priority =
00038         ACE_Sched_Params::next_priority (this->policy_,
00039                                          current_native_priority);
00040 
00041       if (next_native_priority == current_native_priority)
00042         return false;
00043 
00044       current_native_priority = next_native_priority;
00045     }
00046 
00047   native_priority = static_cast<RTCORBA::NativePriority> (current_native_priority);
00048   return true;
00049 
00050 #else
00051 
00052   if (this->min_ < this->max_)
00053     {
00054       native_priority = corba_priority + this->min_;
00055       if (native_priority > this->max_)
00056         return false;
00057     }
00058   else if (this->min_ > this->max_)
00059     {
00060       native_priority = this->min_ - corba_priority;
00061       if (native_priority < this->max_)
00062         return false;
00063     }
00064   else
00065     {
00066       // There is only one native priority.
00067       if (corba_priority != 0)
00068         return false;
00069 
00070       native_priority = this->min_;
00071     }
00072 
00073   return true;
00074 
00075 #endif /* ACE_WIN32 */
00076 
00077 }
00078 
00079 CORBA::Boolean
00080 TAO_Continuous_Priority_Mapping::to_CORBA (RTCORBA::NativePriority native_priority,
00081                                            RTCORBA::Priority &corba_priority)
00082 {
00083 
00084 #if defined (ACE_WIN32)
00085 
00086   int current_native_priority = this->min_;
00087   for (corba_priority = 0; ; ++corba_priority)
00088     {
00089       if (current_native_priority == native_priority)
00090         return true;
00091 
00092       else if (current_native_priority == this->max_)
00093         return false;
00094 
00095       else
00096         current_native_priority =
00097           ACE_Sched_Params::next_priority (this->policy_,
00098                                            current_native_priority);
00099     }
00100 
00101 #else
00102 
00103   if (this->min_ < this->max_)
00104     {
00105       if (native_priority < this->min_
00106           || native_priority > this->max_)
00107         return false;
00108       corba_priority = native_priority - this->min_;
00109     }
00110   else if (this->min_ > this->max_)
00111     {
00112       if (native_priority > this->min_
00113           || native_priority < this->max_)
00114         return false;
00115       corba_priority = this->min_ - native_priority;
00116     }
00117   else if (this->min_ == this->max_)
00118     {
00119       if (native_priority != this->min_)
00120         return false;
00121       corba_priority = 0;
00122     }
00123 
00124   return true;
00125 
00126 #endif /* ACE_WIN32 */
00127 
00128 }
00129 
00130 TAO_END_VERSIONED_NAMESPACE_DECL
00131 
00132 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */

Generated on Tue Feb 2 17:42:49 2010 for TAO_RTCORBA by  doxygen 1.4.7