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 79339 2007-08-14 17:49:17Z sowayaa $")
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
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
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 corba_priority = static_cast<RTCORBA::Priority> (RTCORBA::minPriority
00118 + ((RTCORBA::maxPriority - RTCORBA::minPriority)
00119 * (native_priority_index - 1) / delta));
00120 }
00121 else
00122 {
00123
00124 corba_priority = RTCORBA::minPriority;
00125 }
00126
00127 return 1;
00128
00129 #else
00130
00131 if ((this->min_ < this->max_
00132 && (native_priority < this->min_
00133 || native_priority > this->max_))
00134 || (this->min_ > this->max_
00135 && (native_priority < this->max_
00136 || native_priority > this->min_)))
00137 {
00138 ACE_DEBUG ((LM_DEBUG,
00139 "TAO (%P|%t) - Linear_Priority_Mapping::to_CORBA: "
00140 " priority %d out of range [%d,%d]\n",
00141 native_priority, this->min_, this->max_));
00142 return 0;
00143 }
00144
00145 int delta = this->max_ - this->min_;
00146 if (delta != 0)
00147 {
00148 corba_priority =
00149 RTCORBA::minPriority
00150 + ((RTCORBA::maxPriority - RTCORBA::minPriority)
00151 * (native_priority - this->min_) / delta);
00152 }
00153 else
00154 {
00155
00156 if (native_priority != this->min_)
00157 return 0;
00158 corba_priority = RTCORBA::minPriority;
00159 }
00160
00161 return 1;
00162
00163 #endif
00164 }
00165
00166 TAO_END_VERSIONED_NAMESPACE_DECL
00167
00168 #endif