Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Connector_Registry.cpp
blob004a3a801c1ca06d5e06e634add240f85763b155
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"
6 #include "tao/debug.h"
7 #include "tao/ORB_Constants.h"
8 #include "tao/CDR.h"
9 #include "tao/SystemException.h"
10 #include <memory>
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),
20 size_ (0)
24 TAO_Connector_Registry::~TAO_Connector_Registry ()
26 this->close_all ();
28 delete [] this->connectors_;
31 TAO_Connector *
32 TAO_Connector_Registry::get_connector (CORBA::ULong tag) const
34 const TAO_ConnectorSetIterator end = this->end ();
36 for (TAO_ConnectorSetIterator connector = this->begin ();
37 connector != end;
38 ++connector)
40 if ((*connector)->tag () == tag)
41 return *connector;
44 return nullptr;
47 int
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 ()],
58 -1);
60 // Open one connector for each loaded protocol!
61 const TAO_ProtocolFactorySetItor end = pfs->end ();
63 for (TAO_ProtocolFactorySetItor factory = pfs->begin ();
64 factory != end;
65 ++factory)
67 std::unique_ptr <TAO_Connector> connector ((*factory)->factory ()->make_connector ());
69 if (connector.get ())
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 ")
76 ACE_TEXT ("<%C>.\n"),
77 (*factory)->protocol_name ().c_str ()),
78 -1);
81 this->connectors_[this->size_++] = connector.release ();
83 else
84 return -1;
87 return 0;
90 int
91 TAO_Connector_Registry::close_all ()
93 const TAO_ConnectorSetIterator end = this->end ();
95 for (TAO_ConnectorSetIterator i = this->begin ();
96 i != end;
97 ++i)
99 if (*i == nullptr)
100 continue;
102 (*i)->close ();
104 delete *i;
107 this->size_ = 0;
109 return 0;
113 TAO_Connector_Registry::make_mprofile (const char *ior,
114 TAO_MProfile &mprofile)
116 if (!ior)
117 // Failure: Null IOR string pointer
118 throw ::CORBA::INV_OBJREF (
119 CORBA::SystemException::_tao_minor_code (
121 EINVAL),
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;
129 ++connector)
131 if (*connector)
133 const int mp_result =
134 (*connector)->make_mprofile (ior,
135 mprofile);
137 if (mp_result == 0)
138 return 0; // Success
140 else
141 // Failure: Null pointer to connector in connector registry.
142 throw ::CORBA::INV_OBJREF (
143 CORBA::SystemException::_tao_minor_code (
145 EINVAL),
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);
158 TAO_Profile *
159 TAO_Connector_Registry::create_profile (TAO_InputCDR &cdr)
161 CORBA::ULong tag = 0;
163 // If there is an error we abort.
164 if (!(cdr >> tag))
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")));
169 return nullptr;
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"),
182 tag));
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,
202 orb_core),
203 nullptr);
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 ();
210 pfile = nullptr;
213 return pfile;
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")));
228 return nullptr;
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")));
240 return nullptr;
243 TAO_Profile* profile = connector->create_profile (str);
245 if (!profile)
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));
252 return profile;
255 char
256 TAO_Connector_Registry::object_key_delimiter (const char *ior)
258 if (!ior)
260 errno = EINVAL;
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;
269 ++connector)
271 if (*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.
280 return 0;
283 TAO_END_VERSIONED_NAMESPACE_DECL