00001 #include "orbsvcs/PortableGroup/PG_Utils.h"
00002
00003 #include "tao/MProfile.h"
00004 #include "tao/Profile.h"
00005 #include "tao/Stub.h"
00006 #include "tao/Tagged_Components.h"
00007 #include "tao/CDR.h"
00008
00009 #include "ace/OS_NS_string.h"
00010
00011
00012 ACE_RCSID (PortableGroup,
00013 PG_Utils,
00014 "PG_Utils.cpp,v 1.8 2006/03/14 06:14:34 jtc Exp")
00015
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017
00018 namespace TAO
00019 {
00020 CORBA::Boolean
00021 PG_Utils::set_tagged_component (
00022 PortableGroup::ObjectGroup *&ior,
00023 PortableGroup::TagGroupTaggedComponent &tg)
00024 {
00025 if (ior->_stubobj () == 0)
00026 return 0;
00027
00028
00029 TAO_MProfile &tmp_pfiles =
00030 ior->_stubobj ()->base_profiles ();
00031
00032
00033 TAO_OutputCDR cdr;
00034
00035 IOP::TaggedComponent tagged_components;
00036 tagged_components.tag = IOP::TAG_FT_GROUP;
00037
00038
00039 CORBA::Boolean retval =
00040 PG_Utils::encode_properties (cdr,
00041 tg);
00042
00043 if (retval == 0)
00044 return retval;
00045
00046
00047 CORBA::ULong length = static_cast<CORBA::ULong> (cdr.total_length ());
00048
00049
00050 tagged_components.component_data.length (length);
00051
00052
00053 CORBA::Octet *buf =
00054 tagged_components.component_data.get_buffer ();
00055
00056 for (const ACE_Message_Block *i = cdr.begin ();
00057 i != 0;
00058 i = i->cont ())
00059 {
00060
00061 ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
00062 buf += i->length ();
00063 }
00064 const IOP::TaggedComponent &tmp_tc = tagged_components;
00065
00066
00067 CORBA::ULong count =
00068 ior->_stubobj ()->base_profiles ().profile_count ();
00069
00070
00071 for (CORBA::ULong p_idx = 0; p_idx < count ; ++p_idx)
00072 {
00073
00074 TAO_Tagged_Components &tag_comp =
00075 tmp_pfiles.get_profile (p_idx)->tagged_components ();
00076
00077
00078
00079 tag_comp.set_component (tmp_tc);
00080 }
00081
00082
00083 return 1;
00084 }
00085
00086 CORBA::Boolean
00087 PG_Utils::get_tagged_component (
00088 PortableGroup::ObjectGroup *&ior,
00089 PortableGroup::TagGroupTaggedComponent &tg)
00090 {
00091 if (ior->_stubobj () == 0)
00092 return 0;
00093
00094 TAO_MProfile &mprofile =
00095 ior->_stubobj ()->base_profiles ();
00096
00097
00098 IOP::TaggedComponent tc;
00099 tc.tag = IOP::TAG_FT_GROUP;
00100
00101 CORBA::ULong count =
00102 mprofile.profile_count ();
00103
00104 for (CORBA::ULong i = 0;
00105 i < count;
00106 i++)
00107 {
00108
00109
00110 const TAO_Tagged_Components &pfile_tagged =
00111 mprofile.get_profile (i)->tagged_components ();
00112
00113
00114 if (pfile_tagged.get_component (tc) == 1)
00115 {
00116 TAO_InputCDR cdr (reinterpret_cast<const char*> (tc.component_data.get_buffer ()),
00117 tc.component_data.length ());
00118
00119 CORBA::Boolean byte_order;
00120
00121 cdr >> ACE_InputCDR::to_boolean (byte_order);
00122
00123 if (!cdr.good_bit ())
00124 return 0;
00125
00126 cdr.reset_byte_order (static_cast<int> (byte_order));
00127
00128 cdr >> tg;
00129
00130 if (cdr.good_bit ())
00131 return 1;
00132 }
00133 }
00134
00135 return 0;
00136 }
00137
00138 CORBA::Boolean
00139 PG_Utils::encode_properties (
00140 TAO_OutputCDR &cdr,
00141 PortableGroup::TagGroupTaggedComponent &tg)
00142 {
00143 cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
00144
00145 if (!cdr.good_bit ())
00146 return 0;
00147
00148
00149 cdr << tg.component_version;
00150
00151 if (!cdr.good_bit ())
00152 return 0;
00153
00154
00155 cdr << tg.group_domain_id.in ();
00156
00157 if (!cdr.good_bit ())
00158 return 0;
00159
00160
00161 cdr << tg.object_group_id;
00162
00163 if (!cdr.good_bit ())
00164 return 0;
00165
00166
00167 cdr << tg.object_group_ref_version;
00168
00169 if (!cdr.good_bit ())
00170 return 0;
00171
00172 return cdr.good_bit ();
00173 }
00174 }
00175
00176 TAO_END_VERSIONED_NAMESPACE_DECL