Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Stub.inl
blob02dc6e925830f125df0a60987901ee02f8915988
1 // -*- C++ -*-
2 #include "tao/ORB_Core.h"
3 #include "ace/Reverse_Lock_T.h"
5 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
7 ACE_INLINE void
8 TAO_Stub::reset_base ()
10   this->base_profiles_.rewind ();
11   this->profile_success_ = false;
13   this->set_profile_in_use_i (base_profiles_.get_next ());
17 ACE_INLINE const TAO_SYNCH_MUTEX&
18 TAO_Stub::profile_lock () const
20   return this->profile_lock_;
23 ACE_INLINE void
24 TAO_Stub::reset_forward ()
26   while (this->forward_profiles_ != 0
27          && this->forward_profiles_ != this->forward_profiles_perm_) // Disturbingly the permanent
28                                                                      // forwarded profile lives at the  bottom
29                                                                      // of this stack if it exists. Avoid deleting it.
30     this->forward_back_one ();
33 ACE_INLINE void
34 TAO_Stub::reset_profiles_i ()
36   this->reset_forward ();
37   this->reset_base ();
39   if (this->forward_profiles_perm_)
40     {
41       // The *permanent* forward is being kept in the transient
42       // forward queue (??!). We have just nuked it. Put it back the way it was.
43       // reset_base should have reset the profile success.
44       // @todo We have knives in the spoon draw - TAO_Stub needs total rewrite.
45       this->forward_profiles_ = this->forward_profiles_perm_;
46       this->forward_profiles_->rewind ();
47       this->set_profile_in_use_i (this->forward_profiles_->get_next ());
48     }
51 ACE_INLINE void
52 TAO_Stub::reset_profiles ()
54   ACE_MT (ACE_GUARD (TAO_SYNCH_MUTEX,
55                      guard,
56                      this->profile_lock_));
57   if (TAO_debug_level > 5)
58     {
59       TAOLIB_DEBUG ((LM_DEBUG,
60                   ACE_TEXT ("TAO (%P|%t) - Stub::reset_profiles, acquired ")
61                   ACE_TEXT ("profile lock this = 0x%x\n"),
62                   this));
63     }
65   this->reset_profiles_i ();
68 ACE_INLINE TAO_Profile *
69 TAO_Stub::profile_in_use ()
71   return this->profile_in_use_;
74 ACE_INLINE TAO_MProfile *
75 TAO_Stub::make_profiles ()
77   TAO_MProfile *mp = 0;
79   ACE_NEW_RETURN (mp,
80                   TAO_MProfile (base_profiles_),
81                   0);
83   return mp;
86 ACE_INLINE TAO_Profile *
87 TAO_Stub::next_forward_profile ()
89   TAO_Profile *pfile_next = 0;
91   while (this->forward_profiles_
92          && (pfile_next = this->forward_profiles_->get_next ()) == 0
93          && this->forward_profiles_ != this->forward_profiles_perm_)  // do not remove permanent forward from bottom of stack
94     // that was the last profile.  Now we clean up our forward profiles.
95     // since we own the forward MProfiles, we must delete them when done.
96     this->forward_back_one ();
98   return pfile_next;
101 ACE_INLINE TAO_Profile *
102 TAO_Stub::next_profile_i ()
104   TAO_Profile *pfile_next = 0;
106   // First handle the case that a permanent forward occurred
107   if (this->forward_profiles_perm_) // the permanent forward defined
108                                     // at bottom of stack
109                                     // forward_profiles_
110     {
111       // In case of permanent forward the base_profiles are ingored.
113       pfile_next = this->next_forward_profile ();
115       if (pfile_next == 0)
116         {
117           // COND: this->forward_profiles_ == this->forward_profiles_perm_
119           // reached end of list of permanent forward profiles
120           // now, reset forward_profiles_perm_
122           this->forward_profiles_->rewind ();
123           this->profile_success_ = false;
124           this->set_profile_in_use_i (this->forward_profiles_->get_next());
125         }
126       else
127         this->set_profile_in_use_i (pfile_next);
129       // We may have been forwarded to / from a collocated situation
130       // Check for this and apply / remove optimisation if required.
131       this->orb_core_->reinitialize_object (this);
133       return pfile_next;
134     }
135   else
136     {
137       if (this->forward_profiles_) // Now do the common operation
138         {
139           pfile_next = this->next_forward_profile ();
140           if (pfile_next == 0)
141             {
142               // Fall back to base profiles
143               pfile_next = this->base_profiles_.get_next ();
144             }
146           {
147             typedef ACE_Reverse_Lock<TAO_SYNCH_MUTEX> TAO_REVERSE_LOCK;
148             TAO_REVERSE_LOCK reverse (this->profile_lock_);
149             ACE_MT (ACE_GUARD_RETURN (TAO_REVERSE_LOCK, ace_mon, reverse, 0));
150             if (TAO_debug_level > 5)
151               {
152                 TAOLIB_DEBUG ((LM_DEBUG,
153                             ACE_TEXT ("TAO (%P|%t) - Stub::next_profile_i, ")
154                             ACE_TEXT ("released profile lock to reinitialize ")
155                             ACE_TEXT ("this = 0x%x\n"),
156                             this));
157               }
158             // We may have been forwarded to / from a collocated situation
159             // Check for this and apply / remove optimisation if required.
160             this->orb_core_->reinitialize_object (this);
161           }
162           if (TAO_debug_level > 5)
163             {
164               TAOLIB_DEBUG ((LM_DEBUG,
165                           ACE_TEXT ("TAO (%P|%t) - Stub::next_profile_i, ")
166                           ACE_TEXT ("reacquired profile lock on object ")
167                           ACE_TEXT ("this = 0x%x\n"),
168                           this));
169               }
170         }
171       else
172         pfile_next = this->base_profiles_.get_next ();
174       if (pfile_next == 0)
175         this->reset_base ();
176       else
177         this->set_profile_in_use_i (pfile_next);
179       return pfile_next;
180    }
183 ACE_INLINE TAO_Profile *
184 TAO_Stub::next_profile ()
186   ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
187                             guard,
188                             this->profile_lock_,
189                             0));
190   if (TAO_debug_level > 5)
191     {
192       TAOLIB_DEBUG ((LM_DEBUG,
193                   ACE_TEXT ("TAO (%P|%t) - Stub::next_profile, acquired profile lock this = 0x%x\n"), this));
194     }
195   return this->next_profile_i ();
198 ACE_INLINE CORBA::Boolean
199 TAO_Stub::valid_forward_profile ()
201   return (this->profile_success_ && this->forward_profiles_);
204 ACE_INLINE void
205 TAO_Stub::set_valid_profile ()
207   this->profile_success_ = true;
210 ACE_INLINE CORBA::Boolean
211 TAO_Stub::valid_profile () const
213   return this->profile_success_;
216 ACE_INLINE TAO_Profile *
217 TAO_Stub::base_profiles (const TAO_MProfile &mprofiles)
219   ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
220                             guard,
221                             this->profile_lock_,
222                             0));
223   if (TAO_debug_level > 5)
224     {
225       TAOLIB_DEBUG ((LM_DEBUG,
226                   ACE_TEXT ("TAO (%P|%t) - Stub::base_profiles, acquired profile lock this = 0x%x\n"), this));
227     }
230   // first reset things so we start from scratch!
232   // @note This reset forward could effect the collocation status
233   // but as this method is only used from the Stub ctr, when the status
234   // is already correctly set, we don't reinitialise here. sm.
235   this->reset_forward ();
236   this->base_profiles_.set (mprofiles);
237   this->reset_base ();
238   return this->profile_in_use_;
242 ACE_INLINE CORBA::Boolean
243 TAO_Stub::next_profile_retry ()
245   ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
246                             guard,
247                             this->profile_lock_,
248                             0));
249   if (TAO_debug_level > 5)
250     {
251       TAOLIB_DEBUG ((LM_DEBUG,
252                   ACE_TEXT ("TAO (%P|%t) - Stub::next_profile_retry, acquired profile lock this = 0x%x\n"), this));
253     }
255   if (this->profile_success_ && this->forward_profiles_)
256     {
257       // We have a forwarded reference that we have managed to *send* a message to
258       // previously in the remote path only (but not counting object proxy broker ops).
259       // @todo I can see little sense to this. It is at best highly inconsistent. sm.
261       // In this case we are falling back from the forwarded IOR stright to the base IOR
262       this->reset_profiles_i ();
264       // We used to return unconditional true at this point but this results in
265       // infinite retries of any permanent location forward. This is undesirable.
266       return !this->forward_profiles_perm_;
267     }
268   else if (this->next_profile_i ())
269     {
270       return true;
271     }
273   return false;
276 ACE_INLINE const TAO_MProfile&
277 TAO_Stub::base_profiles () const
279   return this->base_profiles_;
282 ACE_INLINE TAO_MProfile&
283 TAO_Stub::base_profiles ()
285   return this->base_profiles_;
288 ACE_INLINE const TAO_MProfile *
289 TAO_Stub::forward_profiles () const
291   return this->forward_profiles_;
294 ACE_INLINE TAO_MProfile *
295 TAO_Stub::forward_profiles ()
297   return this->forward_profiles_;
300 ACE_INLINE CORBA::Boolean
301 TAO_Stub::is_collocated () const
303   return this->is_collocated_;
306 ACE_INLINE TAO_ORB_Core*
307 TAO_Stub::orb_core () const
309   return this->orb_core_.get ();
312 ACE_INLINE CORBA::ORB_var &
313 TAO_Stub::servant_orb_var ()
315   // Simply pass back the ORB pointer for temporary use.
316   return this->servant_orb_;
319 ACE_INLINE CORBA::ORB_ptr
320 TAO_Stub::servant_orb_ptr ()
322   // Simply pass back the ORB pointer for temporary use.
323   return CORBA::ORB::_duplicate (this->servant_orb_.in ());
326 ACE_INLINE void
327 TAO_Stub::servant_orb (CORBA::ORB_ptr orb)
329   this->servant_orb_ = CORBA::ORB::_duplicate (orb);
332 ACE_INLINE TAO_Abstract_ServantBase *
333 TAO_Stub::collocated_servant () const
335   return collocated_servant_;
338 ACE_INLINE void
339 TAO_Stub::collocated_servant (TAO_Abstract_ServantBase * servant)
341   this->collocated_servant_ = servant;
344 ACE_INLINE TAO::Object_Proxy_Broker *
345 TAO_Stub::object_proxy_broker () const
347   return this->object_proxy_broker_;
350 ACE_INLINE void
351 TAO_Stub::object_proxy_broker (TAO::Object_Proxy_Broker * object_proxy_broker)
353   this->object_proxy_broker_ = object_proxy_broker;
356 ACE_INLINE void
357 TAO_Stub::destroy ()
359   // The reference count better be zero at this point!
360   delete this;
363 ACE_INLINE CORBA::Boolean
364 TAO_Stub::optimize_collocation_objects () const
366   return this->collocation_opt_;
369 ACE_INLINE TAO::Transport_Queueing_Strategy *
370 TAO_Stub::transport_queueing_strategy ()
372 #if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)
374   bool has_synchronization;
375   Messaging::SyncScope scope;
377   this->orb_core_->call_sync_scope_hook (this, has_synchronization, scope);
379   if (has_synchronization == true)
380     return this->orb_core_->get_transport_queueing_strategy  (this, scope);
381 #endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */
383   // No queueing strategy, let the transport use its default
384   return 0;
387 ACE_INLINE
388 void TAO_Stub::forwarded_on_exception (bool forwarded)
390   forwarded_on_exception_ = forwarded;
393 ACE_INLINE
394 bool TAO_Stub::forwarded_on_exception () const
396   return forwarded_on_exception_;
399 ACE_INLINE
400 void
401 TAO_Stub::_incr_refcnt ()
403   ++this->refcount_;
406 ACE_INLINE
407 void
408 TAO_Stub::_decr_refcnt ()
410   if (--this->refcount_ == 0)
411     delete this;
414 ACE_INLINE
415 CORBA::Boolean
416 TAO_Stub::at_starting_profile () const
418   return profile_in_use_ == base_profiles_.get_profile(0);
421 TAO_END_VERSIONED_NAMESPACE_DECL