1 #include "tao/orbconf.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "tao/RTCORBA/Linear_Priority_Mapping.h"
7 #include "ace/Sched_Params.h"
8 #include "ace/Log_Msg.h"
10 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
12 TAO_Linear_Priority_Mapping::TAO_Linear_Priority_Mapping (long policy
)
14 , min_ (ACE_Sched_Params::priority_min (this->policy_
))
15 , max_ (ACE_Sched_Params::priority_max (this->policy_
))
19 TAO_Linear_Priority_Mapping::~TAO_Linear_Priority_Mapping ()
24 TAO_Linear_Priority_Mapping::to_native (
25 RTCORBA::Priority corba_priority
,
26 RTCORBA::NativePriority
&native_priority
)
28 if (corba_priority
< RTCORBA::minPriority
29 // The line below will always be false unless the value of
30 // RTCORBA::maxPriority, which is now assigned the value of
31 // 32767, is changed in RTCORBA.pidl.
32 // || corba_priority > RTCORBA::maxPriority
38 #if defined (ACE_WIN32)
39 // Count up the number of distinct native priorities on current
42 int current_priority
= this->min_
;
43 for (n
= 1; current_priority
!= this->max_
; ++n
)
46 ACE_Sched_Params::next_priority (this->policy_
,
49 int native_priority_index
=
52 * (corba_priority
- RTCORBA::minPriority
)
53 / (RTCORBA::maxPriority
- RTCORBA::minPriority
));
55 // Now, find the value corresponding to this index.
56 native_priority
= static_cast<RTCORBA::NativePriority
> (this->min_
);
57 for (int i
= 2; i
<= native_priority_index
; ++i
)
59 native_priority
= static_cast<RTCORBA::NativePriority
>
60 (ACE_Sched_Params::next_priority (this->policy_
, native_priority
));
68 + ((this->max_
- this->min_
)
69 * (corba_priority
- RTCORBA::minPriority
)
70 / (RTCORBA::maxPriority
- RTCORBA::minPriority
));
74 #endif /* ACE_WIN32 */
78 TAO_Linear_Priority_Mapping::to_CORBA (RTCORBA::NativePriority native_priority
,
79 RTCORBA::Priority
&corba_priority
)
81 #if defined (ACE_WIN32)
83 // Iterate over native priorities in order to 1) make sure
84 // <native_priority> argument contains a valid value, 2) count its
85 // index among all valid native pr. values, 3) get the total number
86 // of native priority values for the current platform.
89 int native_priority_index
= 0;
90 int current_priority
= this->min_
;
91 for (total
= 1; ; ++total
)
93 if (native_priority
== current_priority
)
94 native_priority_index
= total
;
96 if (current_priority
== this->max_
)
100 ACE_Sched_Params::next_priority (this->policy_
,
104 if (native_priority_index
== 0)
107 int delta
= total
- 1;
110 int numerator
= (RTCORBA::maxPriority
- RTCORBA::minPriority
)
111 * (native_priority_index
- 1);
113 div_t corba_offset
= div (numerator
, delta
);
117 if (corba_offset
.rem
)
119 rounding
= ((numerator
< 0 && delta
< 0) ||
120 (numerator
>= 0 && delta
>= 0) ? 1 : -1);
123 corba_priority
= static_cast<RTCORBA::Priority
>
124 (RTCORBA::minPriority
+ corba_offset
.quot
+ rounding
);
128 // There is only one native priority.
129 corba_priority
= RTCORBA::minPriority
;
136 if ((this->min_
< this->max_
137 && (native_priority
< this->min_
138 || native_priority
> this->max_
))
139 || (this->min_
> this->max_
140 && (native_priority
< this->max_
141 || native_priority
> this->min_
)))
143 TAOLIB_DEBUG ((LM_DEBUG
,
144 "TAO (%P|%t) - Linear_Priority_Mapping::to_CORBA: "
145 " priority %d out of range [%d,%d]\n",
146 native_priority
, this->min_
, this->max_
));
150 int delta
= this->max_
- this->min_
;
153 int numerator
= (RTCORBA::maxPriority
- RTCORBA::minPriority
)
154 * (native_priority
- this->min_
);
156 div_t corba_offset
= div (numerator
, delta
);
160 if (corba_offset
.rem
)
162 rounding
= ((numerator
< 0 && delta
< 0) ||
163 (numerator
>= 0 && delta
>= 0) ? 1 : -1);
167 RTCORBA::minPriority
+ corba_offset
.quot
+ rounding
;
171 // There is only one native priority.
172 if (native_priority
!= this->min_
)
174 corba_priority
= RTCORBA::minPriority
;
179 #endif /* ACE_WIN32 */
182 TAO_END_VERSIONED_NAMESPACE_DECL
184 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */