Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / IORTable / Table_Adapter.cpp
blob60d8c6297067f8c8995adb0d539a0e25e44c6726
1 /**
2 * @file Table_Adapter.cpp
4 * @author Carlos O'Ryan <coryan@uci.edu>
5 */
7 #include "tao/IORTable/Table_Adapter.h"
8 #include "tao/IORTable/IOR_Table_Impl.h"
10 #include "tao/ORB_Core.h"
11 #include "tao/Server_Strategy_Factory.h"
12 #include "tao/Object.h"
13 #include "tao/Stub.h"
14 #include "tao/ORB.h"
15 #include "tao/Profile.h"
16 #include "tao/TAO_Server_Request.h"
18 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
20 TAO_Table_Adapter::TAO_Table_Adapter (TAO_ORB_Core &orb_core)
21 : orb_core_ (orb_core),
22 root_ (),
23 closed_ (true),
24 thread_lock_ (),
25 lock_ (TAO_Table_Adapter::create_lock (thread_lock_))
29 TAO_Table_Adapter::~TAO_Table_Adapter ()
31 delete this->lock_;
34 /* static */
35 ACE_Lock *
36 TAO_Table_Adapter::create_lock (TAO_SYNCH_MUTEX &thread_lock)
38 ACE_Lock *the_lock = 0;
39 ACE_NEW_RETURN (the_lock,
40 ACE_Lock_Adapter<TAO_SYNCH_MUTEX> (thread_lock),
41 0);
42 return the_lock;
45 void
46 TAO_Table_Adapter::open ()
48 ACE_GUARD (ACE_Lock, ace_mon, *this->lock_);
49 TAO_IOR_Table_Impl *impl = 0;
50 ACE_NEW_THROW_EX (impl,
51 TAO_IOR_Table_Impl (),
52 CORBA::NO_MEMORY ());
54 this->root_ = impl;
55 this->closed_ = false;
58 void
59 TAO_Table_Adapter::close (int)
61 ACE_GUARD (ACE_Lock, ace_mon, *this->lock_);
62 this->closed_ = true;
63 this->root_ = 0;
66 void
67 TAO_Table_Adapter::check_close (int)
71 int
72 TAO_Table_Adapter::priority () const
74 return static_cast<int> (TAO_DEFAULT_ADAPTER_REGISTRY_SIZE);
77 int
78 TAO_Table_Adapter::dispatch (TAO::ObjectKey &key,
79 TAO_ServerRequest &request,
80 CORBA::Object_out forward_to)
82 if (this->find_object (key, forward_to))
84 request.forward_location (forward_to);
85 return TAO_Adapter::DS_FORWARD;
87 else
88 return TAO_Adapter::DS_MISMATCHED_KEY;
91 const char *
92 TAO_Table_Adapter::name () const
94 return "IORTable";
97 CORBA::Object_ptr
98 TAO_Table_Adapter::root ()
100 return CORBA::Object::_duplicate (this->root_.in());
103 CORBA::Object_ptr
104 TAO_Table_Adapter::create_collocated_object (TAO_Stub *stub,
105 const TAO_MProfile &)
107 CORBA::Object_ptr result = CORBA::Object::_nil ();
109 if (! this->initialize_collocated_object (stub)) // 0 == success
111 // A reference was found in the table. The stub has been forwarded
112 // to this. The collocation indicators are now correct on the stub
113 // (although they may well now indicate that the stub is not in fact
114 // collocated at all).
115 ACE_NEW_RETURN (result,
116 CORBA::Object (stub,
117 stub->is_collocated (),
118 stub->collocated_servant ()),
119 CORBA::Object::_nil ());
122 return result;
125 CORBA::Long
126 TAO_Table_Adapter::initialize_collocated_object (TAO_Stub *stub)
128 // Get the effective profile set.
129 const TAO_MProfile &mp = stub->forward_profiles () ? *(stub->forward_profiles ())
130 : stub->base_profiles ();
131 TAO_PHandle j = 0;
132 // We only look at the key from the 0th profile but we only really care about
133 // corbaloc's here where all profiles share a single object key
134 TAO::ObjectKey_var key = mp.get_profile (j)->_key ();
136 CORBA::Object_var forward_to = CORBA::Object::_nil ();
137 CORBA::Boolean found = false;
141 found = this->find_object (key, forward_to.out ());
143 catch (const ::CORBA::Exception&)
147 if (found)
149 // This call will set the appropriate collocation values
150 // to correspond to the reference we found in the table.
151 stub->add_forward_profiles (forward_to->_stubobj ()->base_profiles ());
152 stub->next_profile ();
155 // 0 for success
156 return ! found;
159 bool
160 TAO_Table_Adapter::find_object (TAO::ObjectKey &key,
161 CORBA::Object_out forward_to)
163 TAO_IOR_Table_Impl_var rootref;
165 ACE_GUARD_RETURN (ACE_Lock,
166 ace_mon,
167 *this->lock_,
168 false);
169 if (this->closed_)
171 return false;
173 rootref = this->root_;
176 CORBA::String_var object_key;
177 TAO::ObjectKey::encode_sequence_to_string (object_key.out (), key);
180 CORBA::String_var ior = this->root_->find (object_key.in ());
181 forward_to = this->orb_core_.orb ()->string_to_object (ior.in ());
183 catch (const ::IORTable::NotFound&)
185 return false;
187 return true;
190 // ****************************************************************
192 TAO_Table_Adapter_Factory::TAO_Table_Adapter_Factory ()
196 TAO_Adapter*
197 TAO_Table_Adapter_Factory::create (TAO_ORB_Core *oc)
199 TAO_Adapter* ptr = 0;
200 ACE_NEW_RETURN (ptr,
201 TAO_Table_Adapter (*oc),
203 return ptr;
206 TAO_END_VERSIONED_NAMESPACE_DECL
208 ACE_FACTORY_DEFINE (TAO_IORTable, TAO_Table_Adapter_Factory)
209 ACE_STATIC_SVC_DEFINE (TAO_Table_Adapter_Factory,
210 ACE_TEXT ("TAO_IORTable"),
211 ACE_SVC_OBJ_T,
212 &ACE_SVC_NAME (TAO_Table_Adapter_Factory),
213 ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,