Go to the documentation of this file.00001
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 82826 2008-09-25 08:12:53Z smcqueen $")
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 int native;
00052
00053 if (this->min_ < this->max_)
00054 {
00055 native = corba_priority + this->min_;
00056 if (native > this->max_)
00057 return false;
00058 }
00059 else if (this->min_ > this->max_)
00060 {
00061 native = this->min_ - corba_priority;
00062 if (native < this->max_)
00063 return false;
00064 }
00065 else
00066 {
00067
00068 if (corba_priority != 0)
00069 return false;
00070
00071 native = this->min_;
00072 }
00073
00074 native_priority = native;
00075
00076 return true;
00077
00078 #endif
00079
00080 }
00081
00082 CORBA::Boolean
00083 TAO_Continuous_Priority_Mapping::to_CORBA (RTCORBA::NativePriority native_priority,
00084 RTCORBA::Priority &corba_priority)
00085 {
00086
00087 #if defined (ACE_WIN32)
00088
00089 int current_native_priority = this->min_;
00090 for (corba_priority = 0; ; ++corba_priority)
00091 {
00092 if (current_native_priority == native_priority)
00093 return true;
00094
00095 else if (current_native_priority == this->max_)
00096 return false;
00097
00098 else
00099 current_native_priority =
00100 ACE_Sched_Params::next_priority (this->policy_,
00101 current_native_priority);
00102 }
00103
00104 #else
00105
00106 if (this->min_ < this->max_)
00107 {
00108 if (native_priority < this->min_
00109 || native_priority > this->max_)
00110 return false;
00111 corba_priority = native_priority - this->min_;
00112 }
00113 else if (this->min_ > this->max_)
00114 {
00115 if (native_priority > this->min_
00116 || native_priority < this->max_)
00117 return false;
00118 corba_priority = this->min_ - native_priority;
00119 }
00120 else if (this->min_ == this->max_)
00121 {
00122 if (native_priority != this->min_)
00123 return false;
00124 corba_priority = 0;
00125 }
00126
00127 return true;
00128
00129 #endif
00130
00131 }
00132
00133 TAO_END_VERSIONED_NAMESPACE_DECL
00134
00135 #endif