1 #include "tao/Strategies/COIOP_Acceptor.h"
3 #if defined (TAO_HAS_COIOP) && (TAO_HAS_COIOP != 0)
5 #include "tao/Strategies/COIOP_Profile.h"
6 #include "tao/MProfile.h"
7 #include "tao/ORB_Core.h"
9 #include "tao/Protocols_Hooks.h"
10 #include "tao/Codeset_Manager.h"
14 #include "ace/OS_NS_string.h"
16 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
18 TAO_COIOP_Acceptor::TAO_COIOP_Acceptor ()
19 : TAO_Acceptor (TAO_TAG_COIOP_PROFILE
),
20 uuid_ (*ACE_Utils::UUID_GENERATOR::instance ()->generate_UUID ()),
21 version_ (TAO_DEF_GIOP_MAJOR
, TAO_DEF_GIOP_MINOR
),
26 TAO_COIOP_Acceptor::~TAO_COIOP_Acceptor ()
28 // Make sure we are closed before we start destroying the
34 // 2) For V1.[1,2] there are tagged components
37 TAO_COIOP_Acceptor::create_profile (const TAO::ObjectKey
& object_key
,
38 TAO_MProfile
&mprofile
,
39 CORBA::Short priority
)
41 // Check if multiple endpoints should be put in one profile or if
42 // they should be spread across multiple profiles.
43 if (priority
== TAO_INVALID_PRIORITY
)
44 return this->create_new_profile (object_key
, mprofile
, priority
);
46 return this->create_shared_profile (object_key
, mprofile
, priority
);
50 TAO_COIOP_Acceptor::create_new_profile (const TAO::ObjectKey
&object_key
,
51 TAO_MProfile
&mprofile
,
52 CORBA::Short priority
)
54 // Adding this->endpoint_count_ to the TAO_MProfile.
55 if (mprofile
.grow (1) == -1)
58 TAO_COIOP_Profile
*pfile
= 0;
59 ACE_NEW_RETURN (pfile
,
60 TAO_COIOP_Profile (uuid_
,
65 pfile
->endpoint ()->priority (priority
);
67 if (mprofile
.give_profile (pfile
) == -1)
69 pfile
->_decr_refcnt ();
74 // Do not add any tagged components to the profile if configured
75 // by the user not to do so, or if an IIOP 1.0 endpoint is being
76 // created (IIOP 1.0 did not support tagged components).
77 if (this->orb_core_
->orb_params ()->std_profile_components () != 0
78 && (this->version_
.major
>= 1 && this->version_
.minor
> 0))
80 pfile
->tagged_components ().set_orb_type (TAO_ORB_TYPE
);
82 TAO_Codeset_Manager
*csm
= this->orb_core_
->codeset_manager();
84 csm
->set_codeset(pfile
->tagged_components());
91 TAO_COIOP_Acceptor::create_shared_profile (const TAO::ObjectKey
&object_key
,
92 TAO_MProfile
&mprofile
,
93 CORBA::Short priority
)
95 TAO_Profile
*pfile
= 0;
96 TAO_COIOP_Profile
*coiop_profile
= 0;
98 // First see if <mprofile> already contains a COIOP profile.
99 for (TAO_PHandle i
= 0; i
!= mprofile
.profile_count (); ++i
)
101 pfile
= mprofile
.get_profile (i
);
102 if (pfile
->tag () == TAO_TAG_COIOP_PROFILE
)
104 coiop_profile
= dynamic_cast<TAO_COIOP_Profile
*> (pfile
);
109 // If <mprofile> doesn't contain a COIOP_Profile, we need to create
111 if (coiop_profile
== 0)
113 ACE_NEW_RETURN (coiop_profile
,
114 TAO_COIOP_Profile (uuid_
,
119 coiop_profile
->endpoint ()->priority (priority
);
121 if (mprofile
.give_profile (coiop_profile
) == -1)
123 coiop_profile
->_decr_refcnt ();
128 if (this->orb_core_
->orb_params ()->std_profile_components () != 0
129 && (this->version_
.major
>= 1 && this->version_
.minor
>= 1))
131 coiop_profile
->tagged_components ().set_orb_type (TAO_ORB_TYPE
);
132 TAO_Codeset_Manager
*csm
= this->orb_core_
->codeset_manager();
134 csm
->set_codeset(pfile
->tagged_components());
138 TAO_COIOP_Endpoint
*endpoint
= 0;
139 ACE_NEW_RETURN (endpoint
,
140 TAO_COIOP_Endpoint (uuid_
),
142 endpoint
->priority (priority
);
143 coiop_profile
->add_endpoint (endpoint
);
149 TAO_COIOP_Acceptor::is_collocated (const TAO_Endpoint
*endpoint
)
151 const TAO_COIOP_Endpoint
*endp
=
152 dynamic_cast<const TAO_COIOP_Endpoint
*> (endpoint
);
154 // Make sure the dynamically cast pointer is valid.
158 return (endp
->uuid() == uuid_
);
162 TAO_COIOP_Acceptor::close ()
168 TAO_COIOP_Acceptor::open (TAO_ORB_Core
*orb_core
,
175 this->orb_core_
= orb_core
;
177 if (major
>=0 && minor
>= 0)
178 this->version_
.set_version (static_cast<CORBA::Octet
> (major
),
179 static_cast<CORBA::Octet
> (minor
));
181 if (this->parse_options (options
) == -1)
184 uuid_
.from_string (address
);
190 TAO_COIOP_Acceptor::open_default (TAO_ORB_Core
*orb_core
,
196 this->orb_core_
= orb_core
;
198 if (major
>=0 && minor
>= 0)
199 this->version_
.set_version (static_cast<CORBA::Octet
> (major
),
200 static_cast<CORBA::Octet
> (minor
));
203 if (this->parse_options (options
) == -1)
210 TAO_COIOP_Acceptor::endpoint_count ()
216 TAO_COIOP_Acceptor::object_key (IOP::TaggedProfile
&profile
,
217 TAO::ObjectKey
&object_key
)
219 // Create the decoding stream from the encapsulation in the buffer,
220 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
221 TAO_InputCDR
cdr (profile
.profile_data
.mb ());
223 TAO_InputCDR
cdr (reinterpret_cast<char*> (profile
.profile_data
.get_buffer ()),
224 profile
.profile_data
.length ());
225 #endif /* TAO_NO_COPY_OCTET_SEQUENCES == 1 */
227 CORBA::Octet major
= 0;
228 CORBA::Octet minor
= 0;
230 // Read the version. We just read it here. We don't*do any*
232 if (!(cdr
.read_octet (major
) && cdr
.read_octet (minor
)))
234 if (TAO_debug_level
> 0)
236 TAOLIB_DEBUG ((LM_DEBUG
,
237 ACE_TEXT ("TAO (%P|%t) COIOP_Profile::decode - v%d.%d\n"),
244 CORBA::String_var uuid
;
246 // Get host and port. No processing here too..
247 if (cdr
.read_string (uuid
.out ()) == 0)
249 if (TAO_debug_level
> 0)
251 TAOLIB_DEBUG ((LM_DEBUG
,
252 ACE_TEXT ("TAO (%P|%t) TAO_COIOP_Acceptor::object_key - ")
253 ACE_TEXT ("error while decoding host/port")));
258 // ... and object key.
259 if ((cdr
>> object_key
) == 0)
262 // We are NOT bothered about the rest.
268 TAO_COIOP_Acceptor::parse_options (const char *str
)
271 return 0; // No options to parse. Not a problem.
273 // Use an option format similar to the one used for CGI scripts in
275 // e.g.: option1=foo&option2=bar
277 ACE_CString
options (str
);
279 size_t len
= options
.length ();
281 const char option_delimiter
= '&';
283 // Count the number of options.
285 CORBA::ULong option_count
= 1;
286 // Number of endpoints in the string (initialized to 1).
288 // Only check for endpoints after the protocol specification and
289 // before the object key.
290 for (size_t i
= 0; i
< len
; ++i
)
291 if (options
[i
] == option_delimiter
)
294 // The idea behind the following loop is to split the options into
295 // (option, name) pairs.
297 // `option1=foo&option2=bar'
298 // will be parsed into:
302 ACE_CString::size_type begin
= 0;
303 ACE_CString::size_type end
= 0;
305 for (CORBA::ULong j
= 0; j
< option_count
; ++j
)
307 if (j
< option_count
- 1)
308 end
= options
.find (option_delimiter
, begin
);
314 TAOLIB_ERROR_RETURN ((LM_ERROR
,
315 ACE_TEXT ("TAO (%P|%t) Zero length COIOP option.\n")),
318 else if (end
!= ACE_CString::npos
)
320 ACE_CString opt
= options
.substring (begin
, end
);
322 ACE_CString::size_type
const slot
= opt
.find ("=");
325 || slot
== ACE_CString::npos
)
326 TAOLIB_ERROR_RETURN ((LM_ERROR
,
327 ACE_TEXT ("TAO (%P|%t) COIOP option <%C> is ")
328 ACE_TEXT ("missing a value.\n"),
332 ACE_CString name
= opt
.substring (0, slot
);
333 ACE_CString value
= opt
.substring (slot
+ 1);
337 if (name
.length () == 0)
338 TAOLIB_ERROR_RETURN ((LM_ERROR
,
339 ACE_TEXT ("TAO (%P|%t) Zero length COIOP ")
340 ACE_TEXT ("option name.\n")),
343 if (name
== "priority")
345 TAOLIB_ERROR_RETURN ((LM_ERROR
,
346 ACE_TEXT ("TAO (%P|%t) Invalid COIOP endpoint format: ")
347 ACE_TEXT ("endpoint priorities no longer supported.\n")),
352 TAOLIB_ERROR_RETURN ((LM_ERROR
,
353 ACE_TEXT ("TAO (%P|%t) Invalid COIOP option: <%C>\n"),
360 break; // No other options.
366 TAO_END_VERSIONED_NAMESPACE_DECL
368 #endif /* TAO_HAS_COIOP && TAO_HAS_COIOP != 0 */