Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / PI / ORBInitInfo.cpp
blob523c389a11f50e998db08a2a13e038f80824e520
1 #include "tao/PI/ORBInitInfo.h"
2 #include "tao/ORB_Core.h"
3 #include "tao/ORB.h"
4 #include "tao/Object_Loader.h"
5 #include "tao/PolicyFactory_Registry_Adapter.h"
7 #include "ace/Dynamic_Service.h"
8 #include "ace/Service_Config.h"
9 #include "ace/CORBA_macros.h"
11 #if TAO_HAS_INTERCEPTORS == 1
12 #include "tao/PI/PICurrent.h"
13 #endif /* TAO_HAS_INTERCEPTORS == 1 */
15 #if !defined (__ACE_INLINE__)
16 #include "tao/PI/ORBInitInfo.inl"
17 #endif /* defined INLINE */
19 #include <cstring>
21 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
23 // Traits specializations for TAO_ORBInitInfo.
25 TAO_ORBInitInfo_ptr
26 TAO::Objref_Traits<TAO_ORBInitInfo>::duplicate (TAO_ORBInitInfo_ptr p)
28 return TAO_ORBInitInfo::_duplicate (p);
31 void
32 TAO::Objref_Traits<TAO_ORBInitInfo>::release (TAO_ORBInitInfo_ptr p)
34 ::CORBA::release (p);
37 TAO_ORBInitInfo_ptr
38 TAO::Objref_Traits<TAO_ORBInitInfo>::nil ()
40 return TAO_ORBInitInfo::_nil ();
43 CORBA::Boolean
44 TAO::Objref_Traits<TAO_ORBInitInfo>::marshal (
45 TAO_ORBInitInfo_ptr p,
46 TAO_OutputCDR & cdr
49 return p->marshal (cdr);
52 TAO_ORBInitInfo::TAO_ORBInitInfo (TAO_ORB_Core *orb_core,
53 int argc,
54 char *argv[],
55 PortableInterceptor::SlotId slotid)
56 : orb_core_ (orb_core),
57 argc_ (argc),
58 argv_ (argv),
59 codec_factory_ (),
60 slot_count_ (slotid)
64 TAO_ORBInitInfo::~TAO_ORBInitInfo ()
68 CORBA::StringSeq *
69 TAO_ORBInitInfo::arguments ()
71 this->check_validity ();
73 // In accordance with the C++ mapping for sequences, it is up to the
74 // caller to deallocate storage for returned sequences.
76 CORBA::StringSeq *args = 0;
77 ACE_NEW_THROW_EX (args,
78 CORBA::StringSeq,
79 CORBA::NO_MEMORY (
80 CORBA::SystemException::_tao_minor_code (
82 ENOMEM),
83 CORBA::COMPLETED_NO));
85 CORBA::StringSeq_var safe_args (args);
87 // Copy the argument vector to the string sequence.
89 args->length (this->argc_); // Not a problem if argc is zero.
90 for (int i = 0; i < this->argc_; ++i)
91 (*args)[i] = CORBA::string_dup (this->argv_[i]);
93 return safe_args._retn ();
96 char *
97 TAO_ORBInitInfo::orb_id ()
99 this->check_validity ();
101 // In accordance with the C++ mapping for strings, return a copy.
103 return CORBA::string_dup (this->orb_core_->orbid ());
106 IOP::CodecFactory_ptr
107 TAO_ORBInitInfo::codec_factory ()
109 if (CORBA::is_nil (this->codec_factory_.in ()))
111 TAO_Object_Loader *loader =
112 ACE_Dynamic_Service<TAO_Object_Loader>::instance ("CodecFactory_Loader");
114 if (loader == 0)
116 ACE_Service_Config::process_directive (
117 ACE_DYNAMIC_VERSIONED_SERVICE_DIRECTIVE("CodecFactory",
118 "TAO_CodecFactory",
119 TAO_VERSION,
120 "_make_TAO_CodecFactory_Loader",
121 ""));
122 loader =
123 ACE_Dynamic_Service<TAO_Object_Loader>::instance ("CodecFactory_Loader");
126 if (loader != 0)
128 CORBA::Object_var cf =
129 loader->create_object (this->orb_core_->orb (), 0, 0);
131 this->codec_factory_ = IOP::CodecFactory::_narrow (cf.in ());
135 return IOP::CodecFactory::_duplicate (this->codec_factory_.in ());
138 void
139 TAO_ORBInitInfo::register_initial_reference (
140 const char * id,
141 CORBA::Object_ptr obj)
143 this->check_validity ();
145 if (id == 0 || std::strlen (id) == 0)
146 throw PortableInterceptor::ORBInitInfo::InvalidName ();
148 if (CORBA::is_nil (obj))
149 throw ::CORBA::BAD_PARAM (CORBA::OMGVMCID | 27, CORBA::COMPLETED_NO);
151 TAO_Object_Ref_Table &table = this->orb_core_->object_ref_table ();
153 if (table.register_initial_reference (id, obj) == -1)
154 throw PortableInterceptor::ORBInitInfo::InvalidName ();
157 CORBA::Object_ptr
158 TAO_ORBInitInfo::resolve_initial_references (const char * id)
160 this->check_validity ();
162 if (id == 0 || std::strlen (id) == 0)
163 throw PortableInterceptor::ORBInitInfo::InvalidName ();
165 // The ORB is practically fully initialized by the time this point
166 // is reached so just use the ORB's resolve_initial_references()
167 // mechanism.
168 return this->orb_core_->orb ()->resolve_initial_references (id);
171 void
172 TAO_ORBInitInfo::add_client_request_interceptor (
173 PortableInterceptor::ClientRequestInterceptor_ptr interceptor)
175 # if TAO_HAS_INTERCEPTORS == 1
176 this->check_validity ();
178 this->orb_core_->add_interceptor (interceptor);
179 #else
180 ACE_UNUSED_ARG (interceptor);
181 throw ::CORBA::NO_IMPLEMENT (
182 CORBA::SystemException::_tao_minor_code (
184 ENOTSUP),
185 CORBA::COMPLETED_NO);
186 #endif /* TAO_HAS_INTERCEPTORS == 1 */
189 void
190 TAO_ORBInitInfo::add_server_request_interceptor (
191 PortableInterceptor::ServerRequestInterceptor_ptr interceptor)
193 # if TAO_HAS_INTERCEPTORS == 1
194 this->check_validity ();
196 this->orb_core_->add_interceptor (interceptor);
198 #else
199 ACE_UNUSED_ARG (interceptor);
200 throw ::CORBA::NO_IMPLEMENT (
201 CORBA::SystemException::_tao_minor_code (
203 ENOTSUP),
204 CORBA::COMPLETED_NO);
205 #endif /* TAO_HAS_INTERCEPTORS == 1 */
208 void
209 TAO_ORBInitInfo::add_ior_interceptor (
210 PortableInterceptor::IORInterceptor_ptr interceptor)
212 this->check_validity ();
214 this->orb_core_->add_interceptor (interceptor);
217 void
218 TAO_ORBInitInfo::add_client_request_interceptor_with_policy (
219 PortableInterceptor::ClientRequestInterceptor_ptr interceptor,
220 const CORBA::PolicyList& policies)
222 # if TAO_HAS_INTERCEPTORS == 1
223 this->check_validity ();
225 this->orb_core_->add_interceptor (interceptor, policies);
226 #else
227 ACE_UNUSED_ARG (interceptor);
228 ACE_UNUSED_ARG (policies);
229 throw ::CORBA::NO_IMPLEMENT (
230 CORBA::SystemException::_tao_minor_code (
232 ENOTSUP),
233 CORBA::COMPLETED_NO);
234 #endif /* TAO_HAS_INTERCEPTORS == 1 */
237 void
238 TAO_ORBInitInfo::add_server_request_interceptor_with_policy (
239 PortableInterceptor::ServerRequestInterceptor_ptr interceptor,
240 const CORBA::PolicyList& policies)
242 # if TAO_HAS_INTERCEPTORS == 1
243 this->check_validity ();
245 this->orb_core_->add_interceptor (interceptor, policies);
247 #else
248 ACE_UNUSED_ARG (interceptor);
249 ACE_UNUSED_ARG (policies);
250 throw ::CORBA::NO_IMPLEMENT (
251 CORBA::SystemException::_tao_minor_code (
253 ENOTSUP),
254 CORBA::COMPLETED_NO);
255 #endif /* TAO_HAS_INTERCEPTORS == 1 */
258 void
259 TAO_ORBInitInfo::add_ior_interceptor_with_policy (
260 PortableInterceptor::IORInterceptor_ptr interceptor,
261 const CORBA::PolicyList& policies)
263 this->check_validity ();
265 // Since there are currently no PI Policies that pertain to
266 // IOR Interceptors, we will always raise the NO_IMPLEMENT
267 // CORBA System Exception here to indicate that this method
268 // is currently not implemented/supported.
269 ACE_UNUSED_ARG (interceptor);
270 ACE_UNUSED_ARG (policies);
271 throw ::CORBA::NO_IMPLEMENT (
272 CORBA::SystemException::_tao_minor_code (
274 ENOTSUP),
275 CORBA::COMPLETED_NO);
278 PortableInterceptor::SlotId
279 TAO_ORBInitInfo::allocate_slot_id ()
281 this->check_validity ();
283 #if TAO_HAS_INTERCEPTORS == 1
284 // No need to acquire a lock. This only gets called during ORB
285 // initialization. ORB initialization is already atomic.
286 return this->slot_count_++;
287 #else
288 throw ::CORBA::NO_IMPLEMENT (
289 CORBA::SystemException::_tao_minor_code (
291 ENOTSUP),
292 CORBA::COMPLETED_NO);
293 #endif /* TAO_HAS_INTERCEPTORS == 1 */
296 void
297 TAO_ORBInitInfo::register_policy_factory (
298 CORBA::PolicyType type,
299 PortableInterceptor::PolicyFactory_ptr policy_factory)
301 this->check_validity ();
303 TAO::PolicyFactory_Registry_Adapter *registry =
304 this->orb_core_->policy_factory_registry ();
306 if (registry == 0)
308 throw ::CORBA::INTERNAL ();
311 registry->register_policy_factory (type, policy_factory);
314 size_t
315 TAO_ORBInitInfo::allocate_tss_slot_id (ACE_CLEANUP_FUNC cleanup)
317 this->check_validity ();
319 size_t slot_id = 0;
321 const int result = this->orb_core_->add_tss_cleanup_func (cleanup, slot_id);
323 if (result != 0)
324 throw ::CORBA::INTERNAL (
325 CORBA::SystemException::_tao_minor_code (
327 errno),
328 CORBA::COMPLETED_NO);
330 return slot_id;
333 void
334 TAO_ORBInitInfo::check_validity ()
336 if (this->orb_core_ == 0)
338 // As defined by the Portable Interceptor specification, throw a
339 // CORBA::OBJECT_NOT_EXIST exception after CORBA::ORB_init() has
340 // completed. CORBA::ORB_init() sets the ORB core pointer in
341 // this instance to zero when it is done initializing the ORB,
342 // which is why we base "existence" on the validity of the ORB
343 // core pointer.
344 throw ::CORBA::OBJECT_NOT_EXIST (0, CORBA::COMPLETED_NO);
348 CORBA::ORB_ptr
349 TAO_ORBInitInfo::_get_orb ()
351 this->check_validity ();
353 return CORBA::ORB::_duplicate (this->orb_core_->orb ());
356 TAO_ORBInitInfo_ptr TAO_ORBInitInfo::_narrow (CORBA::Object_ptr _tao_objref)
358 if (CORBA::is_nil (_tao_objref))
360 return TAO_ORBInitInfo::_nil ();
363 TAO_ORBInitInfo_ptr proxy =
364 dynamic_cast<TAO_ORBInitInfo_ptr> (_tao_objref);
366 return TAO_ORBInitInfo::_duplicate (proxy);
369 TAO_ORBInitInfo_ptr
370 TAO_ORBInitInfo::_duplicate (TAO_ORBInitInfo_ptr obj)
372 if (!CORBA::is_nil (obj))
374 obj->_add_ref ();
377 return obj;
380 const char* TAO_ORBInitInfo::_interface_repository_id () const
382 return "IDL:TAO_ORBInitInfo:1.0";
385 TAO_END_VERSIONED_NAMESPACE_DECL