Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / RTCORBA / Multi_Priority_Mapping.cpp
blob9cb022112f0c89cfbe46d93c3a3e82959cf66e1b
1 #include "tao/orbconf.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "tao/RTCORBA/Multi_Priority_Mapping.h"
6 #include "tao/debug.h"
7 #include "ace/Log_Msg.h"
8 #include "ace/Sched_Params.h"
10 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
12 TAO_Multi_Priority_Mapping::TAO_Multi_Priority_Mapping (
13 int base_native_priority,
14 int base_corba_priority,
15 int priority_spacing,
16 int priorities_contiguous,
17 int policy)
18 : base_native_priority_ (base_native_priority)
19 , base_corba_priority_ (base_corba_priority)
20 , priority_spacing_ (priority_spacing)
21 , priorities_contiguous_(priorities_contiguous)
22 , policy_ (policy)
23 , min_ (ACE_Sched_Params::priority_min (this->policy_))
24 , max_ (ACE_Sched_Params::priority_max (this->policy_))
26 if ( this->min_ < this->max_ )
28 if (base_native_priority_ < this->min_)
30 if (TAO_debug_level > 2)
32 TAOLIB_DEBUG ((LM_DEBUG,
33 "TAO (%P|%t) - Multi_Priority_Mapping::ctor: "
34 " base_native_priority %d out of range [%d,%d]\n",
35 base_native_priority_, this->min_, this->max_));
39 else
41 if (base_native_priority_ > this->min_)
43 if (TAO_debug_level > 2)
45 TAOLIB_DEBUG ((LM_DEBUG,
46 "TAO (%P|%t) - Multi_Priority_Mapping::ctor: "
47 " base_native_priority %d out of range [%d,%d]\n",
48 base_native_priority_, this->min_, this->max_));
53 if (base_corba_priority_ > RTCORBA::maxPriority)
55 if (TAO_debug_level > 2)
57 TAOLIB_DEBUG ((LM_DEBUG,
58 "TAO (%P|%t) - Multi_Priority_Mapping::ctor: "
59 " base_corba_priority %d out of range [%d,%d]\n",
60 base_corba_priority_, RTCORBA::minPriority, RTCORBA::maxPriority));
65 TAO_Multi_Priority_Mapping::~TAO_Multi_Priority_Mapping ()
69 CORBA::Boolean
70 TAO_Multi_Priority_Mapping::to_native (RTCORBA::Priority corba_priority,
71 RTCORBA::NativePriority &native_priority)
73 // Check for an invalid native priority
74 if (corba_priority < RTCORBA::minPriority || corba_priority > this->base_corba_priority_ )
76 if (TAO_debug_level > 2)
78 TAOLIB_DEBUG ((LM_DEBUG,
79 "TAO (%P|%t) - Multi_Priority_Mapping::to_native: "
80 " corba priority %d out of range [%d,%d]\n",
81 corba_priority, RTCORBA::minPriority, this->base_corba_priority_));
83 return 0;
86 if (corba_priority == base_corba_priority_)
88 // If this is the highest priority endpoint, then just give it the highest priority corba base priority
89 native_priority = static_cast<RTCORBA::NativePriority> (base_native_priority_);
91 else
93 if (priorities_contiguous_ == 1)
95 if ( this->min_ < this->max_ )
97 native_priority = static_cast<RTCORBA::NativePriority>
98 (((corba_priority - base_corba_priority_) / priority_spacing_) + base_native_priority_);
100 else
102 native_priority = static_cast<RTCORBA::NativePriority>
103 (((base_corba_priority_ - corba_priority) / priority_spacing_) + base_native_priority_);
106 else
108 // Start at the max priority and search until we reach the base priority
109 int last_priority = this->base_corba_priority_;
110 while (true)
112 if (last_priority == RTCORBA::minPriority) break;
113 if (base_corba_priority_ >= --last_priority) break;
116 int priority_ndx = 0;
117 while (true)
119 if (last_priority == RTCORBA::minPriority) break;
120 if (corba_priority >= --last_priority) break;
121 priority_ndx++;
124 // Start at the max priority and search until we reach the base priority
125 last_priority = this->base_native_priority_;
126 for (int current_ndx = 0; current_ndx < priority_ndx; current_ndx++)
128 native_priority = static_cast<RTCORBA::NativePriority>
129 (ACE_Sched_Params::previous_priority (this->policy_,
130 last_priority,
131 ACE_SCOPE_THREAD));
136 return 1;
139 CORBA::Boolean
140 TAO_Multi_Priority_Mapping::to_CORBA (RTCORBA::NativePriority native_priority,
141 RTCORBA::Priority &corba_priority)
143 // Check for an invalid native priority
144 if ((this->min_ < this->max_ && (native_priority < this->min_ || native_priority > this->base_native_priority_ )) ||
145 (this->min_ > this->max_ && (native_priority < this->base_corba_priority_ || native_priority > this->min_)))
147 if (TAO_debug_level > 2)
149 TAOLIB_DEBUG ((LM_DEBUG,
150 "TAO (%P|%t) - Multi_Priority_Mapping::to_CORBA: "
151 " priority %d out of range [%d,%d]\n",
152 native_priority, this->min_, this->base_corba_priority_));
154 return 0;
157 if (native_priority == base_native_priority_)
159 // If this is the highest priority endpoint, then just give it the highest priority corba base priority
160 corba_priority = static_cast<RTCORBA::Priority> (base_corba_priority_);
162 else
164 if (priorities_contiguous_ == 1)
166 if ( this->min_ < this->max_ )
168 corba_priority = static_cast<RTCORBA::Priority>
169 (((native_priority - base_native_priority_) * priority_spacing_) + base_corba_priority_);
171 else
173 corba_priority = static_cast<RTCORBA::Priority>
174 (((base_native_priority_ - native_priority) * priority_spacing_) + base_corba_priority_);
177 else
179 // Start at the max priority and search until we reach the base priority
180 int last_priority = this->base_native_priority_;
181 while (true)
183 int previous_priority = ACE_Sched_Params::previous_priority (this->policy_,
184 last_priority,
185 ACE_SCOPE_THREAD);
186 last_priority = previous_priority;
188 if (last_priority == this->min_)
190 break;
193 if ( this->min_ < this->max_ )
195 if (base_native_priority_ >= previous_priority) break;
197 else
199 if (base_native_priority_ <= previous_priority) break;
203 int priority_ndx = 1;
204 while (true)
206 if (last_priority == this->min_)
208 break;
211 if ( this->min_ < this->max_ )
213 if (native_priority >= last_priority) break;
215 else
217 if (native_priority <= last_priority) break;
220 int previous_priority = ACE_Sched_Params::previous_priority (this->policy_,
221 last_priority,
222 ACE_SCOPE_THREAD);
223 last_priority = previous_priority;
224 priority_ndx++;
227 corba_priority = static_cast<RTCORBA::Priority>
228 (base_corba_priority_ - priority_ndx);
232 return 1;
235 TAO_END_VERSIONED_NAMESPACE_DECL
237 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */