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"
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
,
16 int priorities_contiguous
,
18 : base_native_priority_ (base_native_priority
)
19 , base_corba_priority_ (base_corba_priority
)
20 , priority_spacing_ (priority_spacing
)
21 , priorities_contiguous_(priorities_contiguous
)
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_
));
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 ()
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_
));
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_
);
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_
);
102 native_priority
= static_cast<RTCORBA::NativePriority
>
103 (((base_corba_priority_
- corba_priority
) / priority_spacing_
) + base_native_priority_
);
108 // Start at the max priority and search until we reach the base priority
109 int last_priority
= this->base_corba_priority_
;
112 if (last_priority
== RTCORBA::minPriority
) break;
113 if (base_corba_priority_
>= --last_priority
) break;
116 int priority_ndx
= 0;
119 if (last_priority
== RTCORBA::minPriority
) break;
120 if (corba_priority
>= --last_priority
) break;
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_
,
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_
));
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_
);
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_
);
173 corba_priority
= static_cast<RTCORBA::Priority
>
174 (((base_native_priority_
- native_priority
) * priority_spacing_
) + base_corba_priority_
);
179 // Start at the max priority and search until we reach the base priority
180 int last_priority
= this->base_native_priority_
;
183 int previous_priority
= ACE_Sched_Params::previous_priority (this->policy_
,
186 last_priority
= previous_priority
;
188 if (last_priority
== this->min_
)
193 if ( this->min_
< this->max_
)
195 if (base_native_priority_
>= previous_priority
) break;
199 if (base_native_priority_
<= previous_priority
) break;
203 int priority_ndx
= 1;
206 if (last_priority
== this->min_
)
211 if ( this->min_
< this->max_
)
213 if (native_priority
>= last_priority
) break;
217 if (native_priority
<= last_priority
) break;
220 int previous_priority
= ACE_Sched_Params::previous_priority (this->policy_
,
223 last_priority
= previous_priority
;
227 corba_priority
= static_cast<RTCORBA::Priority
>
228 (base_corba_priority_
- priority_ndx
);
235 TAO_END_VERSIONED_NAMESPACE_DECL
237 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */