1 #include "tao/Connector_Registry.h"
2 #include "tao/ORB_Core.h"
3 #include "tao/Profile.h"
4 #include "tao/Transport_Connector.h"
5 #include "tao/Protocol_Factory.h"
7 #include "tao/ORB_Constants.h"
9 #include "tao/SystemException.h"
12 #if !defined(__ACE_INLINE__)
13 #include "tao/Connector_Registry.inl"
14 #endif /* __ACE_INLINE__ */
16 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
18 TAO_Connector_Registry::TAO_Connector_Registry ()
19 : connectors_ (nullptr),
24 TAO_Connector_Registry::~TAO_Connector_Registry ()
28 delete [] this->connectors_
;
32 TAO_Connector_Registry::get_connector (CORBA::ULong tag
) const
34 const TAO_ConnectorSetIterator end
= this->end ();
36 for (TAO_ConnectorSetIterator connector
= this->begin ();
40 if ((*connector
)->tag () == tag
)
48 TAO_Connector_Registry::open (TAO_ORB_Core
*orb_core
)
50 TAO_ProtocolFactorySet
* const pfs
=
51 orb_core
->protocol_factories ();
53 // The array containing the TAO_Connectors will never contain more
54 // than the number of loaded protocols in the ORB core.
55 if (this->connectors_
== nullptr)
56 ACE_NEW_RETURN (this->connectors_
,
57 TAO_Connector
*[pfs
->size ()],
60 // Open one connector for each loaded protocol!
61 const TAO_ProtocolFactorySetItor end
= pfs
->end ();
63 for (TAO_ProtocolFactorySetItor factory
= pfs
->begin ();
67 std::unique_ptr
<TAO_Connector
> connector ((*factory
)->factory ()->make_connector ());
71 if (connector
->open (orb_core
) != 0)
73 TAOLIB_ERROR_RETURN ((LM_ERROR
,
74 ACE_TEXT ("TAO (%P|%t) - TAO_Connector_Registry")
75 ACE_TEXT ("::open: unable to open connector for ")
77 (*factory
)->protocol_name ().c_str ()),
81 this->connectors_
[this->size_
++] = connector
.release ();
91 TAO_Connector_Registry::close_all ()
93 const TAO_ConnectorSetIterator end
= this->end ();
95 for (TAO_ConnectorSetIterator i
= this->begin ();
113 TAO_Connector_Registry::make_mprofile (const char *ior
,
114 TAO_MProfile
&mprofile
)
117 // Failure: Null IOR string pointer
118 throw ::CORBA::INV_OBJREF (
119 CORBA::SystemException::_tao_minor_code (
122 CORBA::COMPLETED_NO
);
124 const TAO_ConnectorSetIterator first_connector
= this->begin ();
125 const TAO_ConnectorSetIterator last_connector
= this->end ();
127 for (TAO_ConnectorSetIterator connector
= first_connector
;
128 connector
!= last_connector
;
133 const int mp_result
=
134 (*connector
)->make_mprofile (ior
,
141 // Failure: Null pointer to connector in connector registry.
142 throw ::CORBA::INV_OBJREF (
143 CORBA::SystemException::_tao_minor_code (
146 CORBA::COMPLETED_NO
);
149 // Failure: None of the connectors were able to parse the URL style
150 // IOR into an MProfile.
151 throw ::CORBA::INV_OBJREF (
152 CORBA::SystemException::_tao_minor_code (
153 TAO_CONNECTOR_REGISTRY_NO_USABLE_PROTOCOL
,
155 CORBA::COMPLETED_NO
);
159 TAO_Connector_Registry::create_profile (TAO_InputCDR
&cdr
)
161 CORBA::ULong tag
= 0;
163 // If there is an error we abort.
166 TAOLIB_ERROR ((LM_ERROR
,
167 ACE_TEXT ("TAO (%P|%t) - TAO_Connector_Registry::")
168 ACE_TEXT ("create_profile: Unable to extract tag from CDR stream\n")));
172 TAO_Connector
*connector
=
173 this->get_connector (tag
);
175 if (connector
== nullptr)
177 if (TAO_debug_level
> 0)
179 TAOLIB_DEBUG ((LM_DEBUG
,
180 ACE_TEXT ("TAO (%P|%t) - TAO_Connector_Registry::")
181 ACE_TEXT ("create_profile: Unknown profile tag <0x%x>\n"),
185 TAO_ORB_Core
*orb_core
= cdr
.orb_core ();
186 if (orb_core
== nullptr)
188 orb_core
= TAO_ORB_Core_instance ();
189 if (TAO_debug_level
> 0)
191 TAOLIB_DEBUG ((LM_WARNING
,
192 ACE_TEXT ("TAO (%P|%t) - TAO_Connector_Registry")
193 ACE_TEXT ("::create_profile: ")
194 ACE_TEXT ("WARNING: extracting object from ")
195 ACE_TEXT ("default ORB_Core\n")));
199 TAO_Profile
*pfile
= nullptr;
200 ACE_NEW_RETURN (pfile
,
201 TAO_Unknown_Profile (tag
,
204 if (pfile
->decode (cdr
) == -1)
206 TAOLIB_ERROR ((LM_ERROR
,
207 ACE_TEXT ("TAO (%P|%t) - TAO_Connector_Registry::")
208 ACE_TEXT ("create_profile: Unable to decode unknown profile from CDR stream\n")));
209 pfile
->_decr_refcnt ();
216 // OK, we've got a known profile. It's going to be encapsulated
217 // ProfileData. Create a new decoding stream and context for it,
218 // and skip the data in the parent stream
220 // ProfileData is encoded as a sequence of octet. So first get the
221 // length of the sequence.
222 CORBA::ULong encap_len
= 0;
223 if (!(cdr
>> encap_len
))
225 TAOLIB_ERROR ((LM_ERROR
,
226 ACE_TEXT ("TAO (%P|%t) - TAO_Connector_Registry::")
227 ACE_TEXT ("create_profile: Unable to extract encapsulated length from CDR stream\n")));
231 // Create the decoding stream from the encapsulation in the buffer,
232 // and skip the encapsulation.
233 TAO_InputCDR
str (cdr
, encap_len
);
235 if (!str
.good_bit () || !cdr
.skip_bytes (encap_len
))
237 TAOLIB_ERROR ((LM_ERROR
,
238 ACE_TEXT ("TAO (%P|%t) - TAO_Connector_Registry::")
239 ACE_TEXT ("create_profile: Unable to skip encapsulated stream from CDR stream\n")));
243 TAO_Profile
* profile
= connector
->create_profile (str
);
247 TAOLIB_ERROR ((LM_ERROR
,
248 ACE_TEXT ("TAO (%P|%t) - TAO_Connector_Registry::")
249 ACE_TEXT ("create_profile: Connector returned null profile for tag <0x%x>\n"), tag
));
256 TAO_Connector_Registry::object_key_delimiter (const char *ior
)
261 return 0; // Failure: Null IOR string pointer
264 const TAO_ConnectorSetIterator first_connector
= this->begin ();
265 const TAO_ConnectorSetIterator last_connector
= this->end ();
267 for (TAO_ConnectorSetIterator connector
= first_connector
;
268 connector
!= last_connector
;
273 if ((*connector
)->check_prefix (ior
) == 0)
274 return (*connector
)->object_key_delimiter ();
278 // Failure: None of the connectors were able to match their protocol
279 // against the provided string.
283 TAO_END_VERSIONED_NAMESPACE_DECL