Go to the documentation of this file.00001
00002
00003 #include "tao/orbconf.h"
00004
00005 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00006
00007 #include "tao/RTCORBA/Linear_Priority_Mapping.h"
00008 #include "tao/debug.h"
00009 #include "ace/Sched_Params.h"
00010 #include "ace/Log_Msg.h"
00011
00012 ACE_RCSID (RTCORBA,
00013 Linear_Priority_Mapping,
00014 "$Id: Linear_Priority_Mapping.cpp 82838 2008-09-26 09:26:54Z smcqueen $")
00015
00016
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018
00019 TAO_Linear_Priority_Mapping::TAO_Linear_Priority_Mapping (long policy)
00020 : policy_ (policy)
00021 , min_ (ACE_Sched_Params::priority_min (this->policy_))
00022 , max_ (ACE_Sched_Params::priority_max (this->policy_))
00023 {
00024 }
00025
00026 TAO_Linear_Priority_Mapping::~TAO_Linear_Priority_Mapping (void)
00027 {
00028 }
00029
00030 CORBA::Boolean
00031 TAO_Linear_Priority_Mapping::to_native (
00032 RTCORBA::Priority corba_priority,
00033 RTCORBA::NativePriority &native_priority)
00034 {
00035 if (corba_priority < RTCORBA::minPriority
00036
00037
00038
00039
00040 )
00041 {
00042 return 0;
00043 }
00044
00045 #if defined (ACE_WIN32)
00046
00047
00048 int n;
00049 int current_priority = this->min_;
00050 for (n = 1; current_priority != this->max_; ++n)
00051 {
00052 current_priority =
00053 ACE_Sched_Params::next_priority (this->policy_,
00054 current_priority);
00055 }
00056 int native_priority_index =
00057 1
00058 + ((n - 1)
00059 * (corba_priority - RTCORBA::minPriority)
00060 / (RTCORBA::maxPriority - RTCORBA::minPriority));
00061
00062
00063 native_priority = static_cast<RTCORBA::NativePriority> (this->min_);
00064 for (int i = 2; i <= native_priority_index; ++i)
00065 {
00066 native_priority = static_cast<RTCORBA::NativePriority>
00067 (ACE_Sched_Params::next_priority (this->policy_, native_priority));
00068 }
00069 return 1;
00070
00071 #else
00072
00073 native_priority =
00074 this->min_
00075 + ((this->max_ - this->min_)
00076 * (corba_priority - RTCORBA::minPriority)
00077 / (RTCORBA::maxPriority - RTCORBA::minPriority));
00078
00079 return 1;
00080
00081 #endif
00082 }
00083
00084 CORBA::Boolean
00085 TAO_Linear_Priority_Mapping::to_CORBA (RTCORBA::NativePriority native_priority,
00086 RTCORBA::Priority &corba_priority)
00087 {
00088 #if defined (ACE_WIN32)
00089
00090
00091
00092
00093
00094
00095 int total;
00096 int native_priority_index = 0;
00097 int current_priority = this->min_;
00098 for (total = 1; ; ++total)
00099 {
00100 if (native_priority == current_priority)
00101 native_priority_index = total;
00102
00103 if (current_priority == this->max_)
00104 break;
00105
00106 current_priority =
00107 ACE_Sched_Params::next_priority (this->policy_,
00108 current_priority);
00109 }
00110
00111 if (native_priority_index == 0)
00112 return 0;
00113
00114 int delta = total - 1;
00115 if (delta != 0)
00116 {
00117 int numerator = (RTCORBA::maxPriority - RTCORBA::minPriority)
00118 * (native_priority_index - 1);
00119
00120 div_t corba_offset = div (numerator, delta);
00121
00122 int rounding = 0;
00123
00124 if (corba_offset.rem)
00125 {
00126 rounding = ((numerator < 0 && delta < 0) ||
00127 (numerator >= 0 && delta >= 0) ? 1 : -1);
00128 }
00129
00130 corba_priority = static_cast<RTCORBA::Priority>
00131 (RTCORBA::minPriority + corba_offset.quot + rounding);
00132 }
00133 else
00134 {
00135
00136 corba_priority = RTCORBA::minPriority;
00137 }
00138
00139 return 1;
00140
00141 #else
00142
00143 if ((this->min_ < this->max_
00144 && (native_priority < this->min_
00145 || native_priority > this->max_))
00146 || (this->min_ > this->max_
00147 && (native_priority < this->max_
00148 || native_priority > this->min_)))
00149 {
00150 ACE_DEBUG ((LM_DEBUG,
00151 "TAO (%P|%t) - Linear_Priority_Mapping::to_CORBA: "
00152 " priority %d out of range [%d,%d]\n",
00153 native_priority, this->min_, this->max_));
00154 return 0;
00155 }
00156
00157 int delta = this->max_ - this->min_;
00158 if (delta != 0)
00159 {
00160 int numerator = (RTCORBA::maxPriority - RTCORBA::minPriority)
00161 * (native_priority - this->min_);
00162
00163 div_t corba_offset = div (numerator, delta);
00164
00165 int rounding = 0;
00166
00167 if (corba_offset.rem)
00168 {
00169 rounding = ((numerator < 0 && delta < 0) ||
00170 (numerator >= 0 && delta >= 0) ? 1 : -1);
00171 }
00172
00173 corba_priority =
00174 RTCORBA::minPriority + corba_offset.quot + rounding;
00175 }
00176 else
00177 {
00178
00179 if (native_priority != this->min_)
00180 return 0;
00181 corba_priority = RTCORBA::minPriority;
00182 }
00183
00184 return 1;
00185
00186 #endif
00187 }
00188
00189 TAO_END_VERSIONED_NAMESPACE_DECL
00190
00191 #endif