1
#include "FT_IOGR_Property.h"
3
#include "tao/MProfile.h"
4
#include "tao/Profile.h"
6
#include "tao/ORB_Core.h"
7
#include "tao/Tagged_Components.h"
9
#include "ace/Auto_Ptr.h"
10
#include "tao/debug.h"
13
ACE_RCSID (FaultTolerance,
15
"FT_IOGR_Property.cpp,v 1.18 2003/12/22 01:44:38 wilson_d Exp")
17
#if !defined (__ACE_INLINE__)
18
# include "FT_IOGR_Property.inl"
19
#endif /* ! __ACE_INLINE__ */
23
TAO_FT_IOGR_Property::set_property (
24
CORBA::Object_ptr &ior
25
ACE_ENV_ARG_DECL_NOT_USED /*ACE_ENV_SINGLE_ARG_PARAMETER*/)
26
ACE_THROW_SPEC ((CORBA::SystemException,
27
TAO_IOP::Invalid_IOR))
29
// We need to apply the property for every profile in the IOR
31
// Make profiles from the sent <ior>
32
TAO_MProfile &tmp_pfiles =
33
ior->_stubobj ()->base_profiles ();
35
// Get the profile count.
37
ior->_stubobj ()->base_profiles ().profile_count ();
39
// Make the output CDR stream
41
CORBA::Boolean retval = 0;
43
cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
45
IOP::TaggedComponent tagged_components;
46
tagged_components.tag = IOP::TAG_FT_GROUP;
48
// Encode the property in to the tagged_components
50
this->encode_properties (cdr,
56
const IOP::TaggedComponent &tmp_tc = tagged_components;
58
// Go through every profile and set the TaggedComponent field
59
for (CORBA::ULong i = 0; i < count ; i++)
61
// Get the tagged components in the profile
62
TAO_Tagged_Components &tag_comp =
63
tmp_pfiles.get_profile (i)->tagged_components ();
65
// Finally set the <tagged_component> in the
66
// <TAO_Tagged_Component>
67
tag_comp.set_component (tmp_tc);
77
TAO_FT_IOGR_Property::is_primary_set (
79
ACE_ENV_ARG_DECL_NOT_USED /*ACE_ENV_SINGLE_ARG_PARAMETER*/)
81
CORBA::SystemException
84
if (this->get_primary_profile (ior) != 0)
92
TAO_FT_IOGR_Property::get_primary (
96
CORBA::SystemException,
102
this->get_primary_profile (ior);
105
ACE_THROW_RETURN (TAO_IOP::NotFound (),
106
CORBA::Object::_nil ());
108
// Search for the IOP::TAG_FT_PRIMARY in the tagged component of
111
// Get the repository id
112
CORBA::String_var id =
113
CORBA::string_dup (ior->_stubobj ()->type_id.in ());
115
TAO_ORB_Core *orb_core = TAO_ORB_Core_instance ();
117
// Make a stub Object
120
// Make a MProfile object for the primary profile alone. So, the
123
TAO_MProfile mpfile (sz);
124
if (mpfile.add_profile (pfile) != -1)
126
ACE_NEW_THROW_EX (stub,
127
TAO_Stub (id._retn (), // give the id string to stub
130
CORBA::NO_MEMORY ());
133
// Make the stub memory allocation exception safe for
134
// the duration of this method.
135
TAO_Stub_Auto_Ptr safe_stub (stub);
137
// Create the CORBA level proxy
138
CORBA::Object_ptr temp_obj = CORBA::Object::_nil ();
139
ACE_NEW_THROW_EX (temp_obj,
140
CORBA::Object (safe_stub.get ()),
141
CORBA::NO_MEMORY ());
143
CORBA::Object_var new_obj = temp_obj;
145
ACE_CHECK_RETURN (CORBA::Object::_nil ());
147
// Clean up in case of errors.
148
if (CORBA::is_nil (new_obj.in ()))
150
ACE_THROW_RETURN (TAO_IOP::NotFound (), // ** Changed from Invalid_IOR () **
151
CORBA::Object::_nil ());
154
// Release ownership of the pointers protected by the auto_ptrs since they
155
// no longer need to be protected by this point.
156
stub = safe_stub.release ();
158
return new_obj._retn ();
164
TAO_FT_IOGR_Property::set_primary (
165
CORBA::Object_ptr &ior1,
166
CORBA::Object_ptr ior2
169
CORBA::SystemException,
174
// Check for primary in <ior2>
175
IOP::TaggedComponent tagged_components;
176
tagged_components.tag = IOP::TAG_FT_PRIMARY;
178
TAO_MProfile &mprofile =
179
ior2->_stubobj ()->base_profiles ();
181
for (CORBA::ULong i = 0;
182
i < mprofile.profile_count ();
185
TAO_Tagged_Components &tag_comp =
186
mprofile.get_profile (i)->tagged_components ();
188
if (tag_comp.get_component (tagged_components) == 1)
189
ACE_THROW_RETURN (TAO_IOP::Duplicate (),
193
// Check whether ior1 exists in ior2
194
CORBA::Long index = -1;
196
// Even if it is a multi-profile (in case of multi-homed hosts we
197
// could get a multiple IOR profile), we are going to make the first one
199
TAO_Profile *prim_profile =
200
ior1->_stubobj ()->base_profiles ().get_profile (0);
203
ior2->_stubobj ()->base_profiles ().profile_count ();
206
for (CORBA::ULong ctr = 0;
210
if (prim_profile->is_equivalent (
211
ior2->_stubobj ()->base_profiles ().get_profile (ctr)) == 1)
213
// We know that <ior1> exists in <io2>
214
// Take the index of that and break out of the loop
220
// At the end of the loop check whether we have seen <ior1> in
223
ACE_THROW_RETURN (TAO_IOP::NotFound (),
226
CORBA::Boolean val = 1;
229
cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
230
cdr << ACE_OutputCDR::from_boolean (val);
232
// Get the length of the CDR stream
233
CORBA::ULong length = ACE_static_cast (CORBA::ULong,
234
cdr.total_length ());
237
tagged_components.component_data.length (length);
239
// Get the pointer to the underlying buffer
241
tagged_components.component_data.get_buffer ();
243
for (const ACE_Message_Block *mb = cdr.begin ();
247
ACE_OS::memcpy (buf, mb->rd_ptr (), mb->length ());
248
buf += mb->length ();
251
// Set the <tagged_component>
252
TAO_Tagged_Components &tagg =
253
ior2->_stubobj ()->base_profiles ().get_profile (index)->tagged_components ();
255
tagg.set_component (tagged_components);
261
TAO_FT_IOGR_Property::encode_properties (
263
IOP::TaggedComponent &tagged_components)
265
if (this->ft_group_tagged_component_ == 0)
267
if (TAO_debug_level > 2)
268
ACE_ERROR_RETURN ((LM_ERROR,
269
"TAO-FT (%P|%t) - The group tagged component ",
275
CORBA::Boolean status =
276
cdr << this->ft_group_tagged_component_->component_version;
280
cdr << this->ft_group_tagged_component_->group_domain_id.in ();
284
cdr << this->ft_group_tagged_component_->object_group_id;
286
// Object group reference version
288
cdr << this->ft_group_tagged_component_->object_group_ref_version;
290
// Get the length of the CDR stream
291
CORBA::ULong length = ACE_static_cast (CORBA::ULong,
292
cdr.total_length ());
295
tagged_components.component_data.length (length);
297
// Get the pointer to the underlying buffer
299
tagged_components.component_data.get_buffer ();
301
for (const ACE_Message_Block *i = cdr.begin ();
306
ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
316
TAO_FT_IOGR_Property::get_primary_profile (
317
CORBA::Object_ptr ior)
320
TAO_MProfile &mprofile =
321
ior->_stubobj ()->base_profiles ();
323
// Looking for a tagged component with a PRIMARY flag.
324
IOP::TaggedComponent tagged_components;
325
tagged_components.tag = IOP::TAG_FT_PRIMARY;
327
for (CORBA::ULong i = 0;
328
i < mprofile.profile_count ();
331
// Get the Tagged Components
332
const TAO_Tagged_Components &pfile_tagged =
333
mprofile.get_profile (i)->tagged_components ();
335
// Look for the primary
336
if (pfile_tagged.get_component (tagged_components) == 1)
338
// If there is one return the pfile
339
return mprofile.get_profile (i);
347
TAO_FT_IOGR_Property::get_tagged_component (
348
const CORBA::Object_ptr iogr,
349
FT::TagFTGroupTaggedComponent &fgtc
350
ACE_ENV_ARG_DECL) const
351
ACE_THROW_SPEC ((CORBA::SystemException))
360
TAO_MProfile &mprofile =
361
iogr->_stubobj ()->base_profiles ();
363
// Looking for a tagged component with a TAG_FT_GROUP flag.
364
IOP::TaggedComponent tc;
365
tc.tag = IOP::TAG_FT_GROUP;
367
for (CORBA::ULong i = 0;
368
i < mprofile.profile_count ();
372
// Get the Tagged Components
373
const TAO_Tagged_Components &pfile_tagged =
374
mprofile.get_profile (i)->tagged_components ();
376
// Look for the primary
377
if (pfile_tagged.get_component (tc) == 1)
379
TAO_InputCDR cdr (ACE_reinterpret_cast (
381
tc.component_data.get_buffer ()
383
tc.component_data.length ());
384
CORBA::Boolean byte_order;
386
if ((cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
387
ACE_THROW_RETURN (CORBA::MARSHAL (),
390
cdr.reset_byte_order (ACE_static_cast (int,byte_order));
392
if ((cdr >> fgtc) == 1)
395
ACE_THROW_RETURN (CORBA::MARSHAL (),
404
TAO_FT_IOGR_Property::remove_primary_tag (
405
CORBA::Object_ptr &iogr
406
ACE_ENV_ARG_DECL_NOT_USED)
407
ACE_THROW_SPEC ((CORBA::SystemException))
410
TAO_MProfile &mprofile =
411
iogr->_stubobj ()->base_profiles ();
413
for (CORBA::ULong i = 0;
414
i < mprofile.profile_count ();
417
TAO_Profile* profile = mprofile.get_profile (i);
419
// Get the Tagged Components
420
TAO_Tagged_Components &pfile_tagged =
421
profile->tagged_components ();
423
if (pfile_tagged.remove_component (IOP::TAG_FT_PRIMARY))