TypeCode_CDR_Extraction.cpp File Reference

#include "tao/AnyTypeCode/TypeCode_CDR_Extraction.h"
#include "tao/AnyTypeCode/TypeCode_Constants.h"
#include "tao/AnyTypeCode/True_RefCount_Policy.h"
#include "tao/AnyTypeCode/Alias_TypeCode.h"
#include "tao/AnyTypeCode/Enum_TypeCode.h"
#include "tao/AnyTypeCode/TypeCode_Case_Enum_T.h"
#include "tao/AnyTypeCode/Fixed_TypeCode.h"
#include "tao/AnyTypeCode/Objref_TypeCode.h"
#include "tao/AnyTypeCode/Sequence_TypeCode.h"
#include "tao/AnyTypeCode/String_TypeCode.h"
#include "tao/AnyTypeCode/Struct_TypeCode.h"
#include "tao/AnyTypeCode/Union_TypeCode.h"
#include "tao/AnyTypeCode/Value_TypeCode.h"
#include "tao/AnyTypeCode/Any.h"
#include "tao/AnyTypeCode/Recursive_Type_TypeCode.h"
#include "tao/AnyTypeCode/TypeCode_Case_T.h"
#include "tao/AnyTypeCode/TypeCode_Struct_Field.h"
#include "tao/AnyTypeCode/TypeCode_Value_Field.h"
#include "tao/CDR.h"
#include "ace/Array_Base.h"
#include "ace/Value_Ptr.h"

Include dependency graph for TypeCode_CDR_Extraction.cpp:

Include dependency graph

Go to the source code of this file.

Namespaces

namespace  TAO
namespace  TAO::TypeCodeFactory

Typedefs

typedef ACE::Value_Ptr< TAO::TypeCode::Case<
CORBA::String_var, CORBA::TypeCode_var > > 
union_elem_type
typedef ACE_Array_Base< union_elem_typeunion_case_array_type

Functions

bool add_to_recursion_list (CORBA::TypeCode_ptr &tc, TAO::TypeCodeFactory::TC_Info_List &infos)
bool start_cdr_encap_extraction (TAO_InputCDR &cdr)
bool tc_demarshal (TAO_InputCDR &cdr, CORBA::TypeCode_ptr &tc, TAO::TypeCodeFactory::TC_Info_List &infos)
 Demarshal a TypeCode.

bool tc_demarshal_indirection (TAO_InputCDR &cdr, CORBA::TypeCode_ptr &tc, TAO::TypeCodeFactory::TC_Info_List &infos)
 Demarshal an indirected TypeCode.

bool find_recursive_tc (char const *id, TAO::TypeCodeFactory::TC_Info_List &tcs, TAO::TypeCodeFactory::TC_Info_List &infos)
bool tc_demarshal (TAO_InputCDR &cdr, CORBA::TypeCode_ptr &tc, TAO::TypeCodeFactory::TC_Info_List &infos)
bool tc_demarshal_indirection (TAO_InputCDR &cdr, CORBA::TypeCode_ptr &tc, TAO::TypeCodeFactory::TC_Info_List &infos)
CORBA::Boolean operator>> (TAO_InputCDR &cdr, CORBA::TypeCode_ptr &tc)

Variables

CORBA::ULong const  TYPECODE_INDIRECTION = 0xffffffffU


Typedef Documentation

typedef ACE_Array_Base<union_elem_type> union_case_array_type [static]
 

Definition at line 121 of file TypeCode_CDR_Extraction.cpp.

Referenced by tc_demarshal_indirection(), and TAO::TypeCodeFactory::tc_union_factory().

typedef ACE::Value_Ptr<TAO::TypeCode::Case<CORBA::String_var, CORBA::TypeCode_var> > union_elem_type [static]
 

Definition at line 120 of file TypeCode_CDR_Extraction.cpp.

Referenced by TAO::TypeCodeFactory::tc_union_factory().


Function Documentation

bool add_to_recursion_list CORBA::TypeCode_ptr tc,
TAO::TypeCodeFactory::TC_Info_List infos
[static]
 

Definition at line 67 of file TypeCode_CDR_Extraction.cpp.

References TAO::TypeCodeFactory::TC_Info::id, ACE_Array_Base< T >::size(), TAO::TypeCodeFactory::TC_Info_List, and TAO::TypeCodeFactory::TC_Info::type.

Referenced by tc_demarshal_indirection().

00069   {
00070     // Since we created a new tc, add it to the list.
00071     size_t const old_size = infos.size ();
00072     if (infos.size (old_size + 1) == -1)  // Incremental growth -- *sigh*
00073       {
00074         // Can't increase the list size.
00075         return false;
00076       }
00077 
00078     TAO::TypeCodeFactory::TC_Info & info = infos [old_size];
00079 
00080     try
00081       {
00082         // Append the new TC to the list.
00083         info.id = tc->id (); // Should never throw, but just incase!
00084         info.type = tc;
00085       }
00086     catch (...)
00087       {
00088         infos.size (old_size); // Remove the partially added new TC from the list.
00089         return false;
00090       }
00091     return true;
00092   }

bool find_recursive_tc char const *  id,
TAO::TypeCodeFactory::TC_Info_List tcs,
TAO::TypeCodeFactory::TC_Info_List infos
[static]
 

Definition at line 135 of file TypeCode_CDR_Extraction.cpp.

References TAO::TypeCodeFactory::TC_Info::id, ACE_Array_Base< T >::size(), ACE_OS::strcmp(), TAO::TypeCodeFactory::TC_Info_List, and TAO::TypeCodeFactory::TC_Info::type.

Referenced by tc_demarshal_indirection(), TAO::TypeCodeFactory::tc_struct_factory(), TAO::TypeCodeFactory::tc_union_factory(), and TAO::TypeCodeFactory::tc_value_factory().

00138   {
00139     // See comments above for rationale behind using an array instead
00140     // of a map.
00141 
00142     size_t const len = infos.size ();
00143 
00144     for (size_t i = 0; i < len; ++i)
00145       {
00146         TAO::TypeCodeFactory::TC_Info & info = infos[i];
00147 
00148         if (ACE_OS::strcmp (info.id, id) == 0)
00149           {
00150             // We have a matching id, so store the TypeCode in the out
00151             // array and then compare the others.
00152             size_t const old_size = tcs.size ();
00153             if (tcs.size (old_size + 1) == -1)  // Incremental growth -- *sigh*
00154               return false;
00155 
00156             TAO::TypeCodeFactory::TC_Info & new_info = tcs[old_size];
00157             new_info.type = info.type;
00158           }
00159       }
00160 
00161     return (tcs.size () > 0) ;
00162   }

CORBA::Boolean operator>> TAO_InputCDR cdr,
CORBA::TypeCode_ptr tc
 

Definition at line 1407 of file TypeCode_CDR_Extraction.cpp.

References tc_demarshal(), and TAO::TypeCodeFactory::TC_Info_List.

01408 {
01409   TAO::TypeCodeFactory::TC_Info_List infos;
01410 
01411   return tc_demarshal (cdr, tc, infos);
01412 }

bool start_cdr_encap_extraction TAO_InputCDR cdr  )  [static]
 

Definition at line 94 of file TypeCode_CDR_Extraction.cpp.

References ACE_InputCDR::reset_byte_order(), and ACE_InputCDR::skip_ulong().

Referenced by TAO::TypeCodeFactory::tc_alias_factory(), tc_demarshal_indirection(), TAO::TypeCodeFactory::tc_enum_factory(), TAO::TypeCodeFactory::tc_objref_factory(), TAO::TypeCodeFactory::tc_sequence_factory(), TAO::TypeCodeFactory::tc_struct_factory(), TAO::TypeCodeFactory::tc_union_factory(), and TAO::TypeCodeFactory::tc_value_factory().

00095   {
00096     CORBA::Boolean byte_order;
00097 
00098     // Don't bother demarshaling the encapsulation length.  Prefer
00099     // speed over early error checking.  Any CDR length related
00100     // failures will be detected when demarshaling the remainder of
00101     // the complex parameter list TypeCode.
00102 
00103     if (!(cdr.skip_ulong () // Skip encapsulation length.
00104           && cdr >> TAO_InputCDR::to_boolean (byte_order)))
00105       return false;
00106 
00107     cdr.reset_byte_order (byte_order);
00108 
00109     return true;
00110   }

bool tc_demarshal TAO_InputCDR cdr,
CORBA::TypeCode_ptr tc,
TAO::TypeCodeFactory::TC_Info_List infos
[static]
 

Definition at line 1156 of file TypeCode_CDR_Extraction.cpp.

References tc_demarshal_indirection(), TAO::TypeCodeFactory::TC_Info_List, and TYPECODE_INDIRECTION.

Referenced by operator>>(), TAO::TypeCodeFactory::tc_alias_factory(), tc_demarshal_indirection(), TAO::TypeCodeFactory::tc_sequence_factory(), TAO::TypeCodeFactory::tc_struct_factory(), TAO::TypeCodeFactory::tc_union_factory(), and TAO::TypeCodeFactory::tc_value_factory().

01159   {
01160     // ULong since we need to detect indirected TypeCodes, too.
01161 
01162     CORBA::ULong kind;
01163     if (!(cdr >> kind)
01164         || (kind >= static_cast<CORBA::ULong> (CORBA::TAO_TC_KIND_COUNT)
01165             && kind != TYPECODE_INDIRECTION))
01166       return false;
01167 
01168     if (kind == TYPECODE_INDIRECTION)
01169       return tc_demarshal_indirection (cdr, tc, infos);
01170 
01171     using namespace TAO::TypeCodeFactory;
01172 
01173     static factory const factory_map[] =
01174       {
01175         tc_null_factory,
01176         tc_void_factory,
01177         tc_short_factory,
01178         tc_long_factory,
01179         tc_ushort_factory,
01180         tc_ulong_factory,
01181         tc_float_factory,
01182         tc_double_factory,
01183         tc_boolean_factory,
01184         tc_char_factory,
01185         tc_octet_factory,
01186         tc_any_factory,
01187         tc_TypeCode_factory,
01188         tc_Principal_factory,
01189         tc_objref_factory,
01190         tc_struct_factory,
01191         tc_union_factory,
01192         tc_enum_factory,
01193         tc_string_factory,
01194         tc_sequence_factory,
01195         tc_array_factory,
01196         tc_alias_factory,
01197         tc_except_factory,
01198         tc_longlong_factory,
01199         tc_ulonglong_factory,
01200         tc_longdouble_factory,
01201         tc_wchar_factory,
01202         tc_wstring_factory,
01203         tc_fixed_factory,
01204         tc_value_factory,
01205         tc_value_box_factory,
01206         tc_native_factory,
01207         tc_abstract_interface_factory,
01208         tc_local_interface_factory,
01209         tc_component_factory,
01210         tc_home_factory,
01211         tc_event_factory
01212       };
01213 
01214     return factory_map[kind] (static_cast<CORBA::TCKind> (kind),
01215                               cdr,
01216                               tc,
01217                               infos);
01218   }

bool tc_demarshal TAO_InputCDR cdr,
CORBA::TypeCode_ptr tc,
TAO::TypeCodeFactory::TC_Info_List infos
[static]
 

Demarshal a TypeCode.

bool tc_demarshal_indirection TAO_InputCDR cdr,
CORBA::TypeCode_ptr tc,
TAO::TypeCodeFactory::TC_Info_List infos
[static]
 

Definition at line 1221 of file TypeCode_CDR_Extraction.cpp.

References ACE_NEW_RETURN, add_to_recursion_list(), ACE_InputCDR::byte_order(), find_recursive_tc(), ACE_InputCDR::good_bit(), ACE_InputCDR::rd_ptr(), start_cdr_encap_extraction(), tc_demarshal(), TAO::TypeCodeFactory::TC_Info_List, TYPECODE_INDIRECTION, and union_case_array_type.

Referenced by tc_demarshal().

01224   {
01225     CORBA::Long offset;
01226 
01227     if (!(cdr >> offset) || offset >= -4)
01228       {
01229         // Offsets must be negative since they point back to a
01230         // TypeCode found earlier in the CDR stream.  They must be
01231         // less than -4 since an offset of -4 points back to the
01232         // indirection TypeCode itself, meaning that it would be
01233         // self-indirecting.
01234         return false;
01235       }
01236 
01237     TAO_InputCDR indir_stream (cdr.rd_ptr () + offset - sizeof (CORBA::Long),
01238                                (-offset) + sizeof (CORBA::Long),
01239                                cdr.byte_order ());
01240 
01241     if (!indir_stream.good_bit ())
01242       {
01243         return false;
01244       }
01245 
01246     CORBA::TCKind kind;
01247     if (!(indir_stream >> kind)
01248 
01249         // Indirected TypeCode must point to top-level TypeCode.
01250         || static_cast<CORBA::ULong> (kind) == TYPECODE_INDIRECTION
01251 
01252         // Only struct, union, event and valuetype TypeCodes may be
01253         // recursive. However non-recursive ALIAS may be indirected.
01254         || !(kind == CORBA::tk_struct
01255              || kind == CORBA::tk_union
01256              || kind == CORBA::tk_value
01257              || kind == CORBA::tk_event
01258              || kind == CORBA::tk_alias)
01259 
01260         // Currently all recursive TypeCodes have complex parameter
01261         // lists, meaning they are encoded as CDR encapsulations.
01262         || !start_cdr_encap_extraction (indir_stream))
01263       {
01264         return false;
01265       }
01266 
01267     /**
01268      * @todo Recursive TypeCode demarshaling is currently suboptimal
01269      *       due to redundant demarshaling of TypeCode parameters,
01270      *       such as repository ID, and excessive
01271      *       allocations/copying.
01272      */
01273 
01274     CORBA::String_var id;
01275     if (!(indir_stream >> TAO_InputCDR::to_string (id.out (), 0)))
01276       return false;
01277 
01278     if (CORBA::tk_alias == kind)
01279     {
01280       // NOTE: Although Alias may be indirect, they are NOT recursive!
01281       // Just create another type code for this alias.
01282 
01283       CORBA::String_var name;
01284       CORBA::TypeCode_var content_type;
01285       if (!(indir_stream >> TAO_InputCDR::to_string (name.out (), 0)
01286           && tc_demarshal (indir_stream, content_type.out (), infos)))
01287         {
01288           return false;
01289         }
01290 
01291       typedef TAO::TypeCode::Alias<
01292                       CORBA::String_var,
01293                       CORBA::TypeCode_var,
01294                       TAO::True_RefCount_Policy> typecode_type;
01295 
01296       // NOTE: Although Alias may be indirect, they are NOT recursive!
01297       ACE_NEW_RETURN (tc,
01298           typecode_type (kind,
01299                         id.in (),
01300                         name.in (),
01301                         content_type),
01302           false);
01303       return true;
01304     }
01305 
01306     // Don't bother demarshaling the rest of the parameters.  They will
01307     // be handled by the top-level TypeCode demarshaling call.
01308 
01309     // Check if we already have a tc for this RECURSIVE type, if yes, use that
01310     TAO::TypeCodeFactory::TC_Info_List recursive_tc;
01311     if (find_recursive_tc (id.in (), recursive_tc, infos))
01312       {
01313         tc = recursive_tc[0].type;
01314       }
01315     else switch (kind)
01316       {
01317       case CORBA::tk_struct:
01318         {
01319           typedef ACE_Array_Base<
01320             TAO::TypeCode::Struct_Field<
01321               CORBA::String_var,
01322               CORBA::TypeCode_var> > member_array_type;
01323 
01324           typedef TAO::TypeCode::Struct<
01325             CORBA::String_var,
01326             CORBA::TypeCode_var,
01327             member_array_type,
01328             TAO::True_RefCount_Policy> typecode_type;
01329 
01330           typedef TAO::TypeCode::Recursive_Type<typecode_type,
01331                                                 CORBA::TypeCode_var,
01332                                                 member_array_type>
01333             recursive_typecode_type;
01334 
01335           ACE_NEW_RETURN (tc,
01336                           recursive_typecode_type (kind,
01337                                                   id.in ()),
01338                           false);
01339 
01340           // Since we created a new recursive tc, add it to the "Recursive" list.
01341           return add_to_recursion_list (tc, infos);
01342         }
01343         break;
01344       case CORBA::tk_union:
01345         {
01346           typedef union_case_array_type member_array_type;
01347 
01348           typedef TAO::TypeCode::Union<
01349             CORBA::String_var,
01350             CORBA::TypeCode_var,
01351             member_array_type,
01352             TAO::True_RefCount_Policy> typecode_type;
01353 
01354           typedef TAO::TypeCode::Recursive_Type<typecode_type,
01355                                                 CORBA::TypeCode_var,
01356                                                 member_array_type>
01357             recursive_typecode_type;
01358 
01359           ACE_NEW_RETURN (tc,
01360                           recursive_typecode_type (kind,
01361                                                   id.in ()),
01362                           false);
01363 
01364           // Since we created a new recursive tc, add it to the "Recursive" list.
01365           return add_to_recursion_list (tc, infos);
01366         }
01367         break;
01368       case CORBA::tk_value:
01369       case CORBA::tk_event:
01370         {
01371           typedef ACE_Array_Base<
01372             TAO::TypeCode::Value_Field<
01373               CORBA::String_var,
01374               CORBA::TypeCode_var> > member_array_type;
01375 
01376           typedef TAO::TypeCode::Value<
01377             CORBA::String_var,
01378             CORBA::TypeCode_var,
01379             member_array_type,
01380             TAO::True_RefCount_Policy> typecode_type;
01381 
01382           typedef TAO::TypeCode::Recursive_Type<typecode_type,
01383                                                 CORBA::TypeCode_var,
01384                                                 member_array_type>
01385             recursive_typecode_type;
01386 
01387           ACE_NEW_RETURN (tc,
01388                           recursive_typecode_type (kind,
01389                                                   id.in ()),
01390                           false);
01391 
01392           // Since we created a new recursive tc, add it to the "Recursive" list.
01393           return add_to_recursion_list (tc, infos);
01394         }
01395         break;
01396       default:
01397         return false;  // We should never get here.
01398       }
01399 
01400     return true;
01401   }

bool tc_demarshal_indirection TAO_InputCDR cdr,
CORBA::TypeCode_ptr tc,
TAO::TypeCodeFactory::TC_Info_List infos
[static]
 

Demarshal an indirected TypeCode.


Variable Documentation

CORBA::ULong const TYPECODE_INDIRECTION = 0xffffffffU [static]
 

Definition at line 114 of file TypeCode_CDR_Extraction.cpp.

Referenced by tc_demarshal(), and tc_demarshal_indirection().


Generated on Sun Jan 27 13:21:46 2008 for TAO_AnyTypeCode by doxygen 1.3.6