diff options
Diffstat (limited to 'TAO/tao/skip.cpp')
-rw-r--r-- | TAO/tao/skip.cpp | 325 |
1 files changed, 191 insertions, 134 deletions
diff --git a/TAO/tao/skip.cpp b/TAO/tao/skip.cpp index de8d3194ef1..77222f77387 100644 --- a/TAO/tao/skip.cpp +++ b/TAO/tao/skip.cpp @@ -103,19 +103,10 @@ TAO_Marshal_Any::skip (CORBA::TypeCode_ptr, TAO_InputCDR *stream = ACE_static_cast (TAO_InputCDR *, context); // Status of encode operation. - CORBA::TypeCode::traverse_status retval = - stream->decode (CORBA::_tc_TypeCode, - &elem_tc.inout (), - 0, - ACE_TRY_ENV); - ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + if (!(*stream >> elem_tc.inout ())) + return CORBA::TypeCode::TRAVERSE_STOP; - if (retval == CORBA::TypeCode::TRAVERSE_CONTINUE) - { - retval = stream->skip (elem_tc.in (), ACE_TRY_ENV); - ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); - } - return retval; + return stream->skip (elem_tc.in (), ACE_TRY_ENV); } CORBA::TypeCode::traverse_status @@ -356,145 +347,211 @@ TAO_Marshal_Union::skip (CORBA::TypeCode_ptr tc, void *context, CORBA::Environment &ACE_TRY_ENV) { - // Context is the CDR stream. - TAO_InputCDR *stream = ACE_static_cast (TAO_InputCDR *, context); - - CORBA::TypeCode::traverse_status retval = - CORBA::TypeCode::TRAVERSE_CONTINUE; + TAO_InputCDR *src = + ACE_reinterpret_cast (TAO_InputCDR*, context); - CORBA::TypeCode_var discrim_tc; - CORBA::TypeCode_var member_tc; - CORBA::Any_ptr member_label; - CORBA::ULongLong discrim_val; - CORBA::ULong member_count; - CORBA::Long default_index; - CORBA::ULong i; - CORBA::TypeCode_ptr default_tc = 0; - CORBA::Boolean discrim_matched = 0; - - // get the discriminator type which will enable us to skip the discriminator - // value - discrim_tc = tc->discriminator_type (ACE_TRY_ENV); + CORBA::TypeCode_ptr discrim_tc = + tc->discriminator_type (ACE_TRY_ENV); ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); - // decode the discriminator value - retval = stream->decode (discrim_tc.in (), &discrim_val, 0, ACE_TRY_ENV); + CORBA::ULong kind = + discrim_tc->kind (ACE_TRY_ENV); ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); - if (retval == CORBA::TypeCode::TRAVERSE_CONTINUE) + // Save the discriminator value in a temporary variable... + CORBA::Short short_v; + CORBA::UShort ushort_v; + CORBA::Long long_v; + CORBA::ULong ulong_v; + CORBA::ULong enum_v; + CORBA::Char char_v; + CORBA::WChar wchar_v; + CORBA::Boolean boolean_v; + + switch (kind) { - // now get ready to skip the actual union value - default_index = tc->default_index (ACE_TRY_ENV); - ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + case CORBA::tk_short: + { + if (!src->read_short (short_v)) + return CORBA::TypeCode::TRAVERSE_STOP; + } + break; - member_count = tc->member_count (ACE_TRY_ENV); - ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + case CORBA::tk_ushort: + { + if (!src->read_ushort (ushort_v)) + return CORBA::TypeCode::TRAVERSE_STOP; + } + break; - // check which label value matches with the discriminator - // value. Accordingly, marshal the corresponding - // member_type. If none match, check if default exists - // and marshal accordingly. Otherwise it is an error. + case CORBA::tk_long: + { + if (!src->read_long (long_v)) + return CORBA::TypeCode::TRAVERSE_STOP; + } + break; - for (i = 0; i < member_count; i++) - { - member_label = tc->member_label (i, ACE_TRY_ENV); - ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + case CORBA::tk_ulong: + { + if (!src->read_ulong (ulong_v)) + return CORBA::TypeCode::TRAVERSE_STOP; + } + break; - // do the matching - CORBA::TypeCode_var type = member_label->type (); - CORBA::ULong kind = type->kind (ACE_TRY_ENV); - ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + case CORBA::tk_enum: + { + if (!src->read_ulong (enum_v)) + return CORBA::TypeCode::TRAVERSE_STOP; + } + break; - switch (kind) - { - case CORBA::tk_short: - { - CORBA::Short s; - *member_label >>= s; - if (s == *(CORBA::Short *) &discrim_val) - discrim_matched = 1; - } - break; - case CORBA::tk_ushort: - { - CORBA::UShort s; - *member_label >>= s; - if (s == *(CORBA::UShort *) &discrim_val) - discrim_matched = 1; - } - break; - case CORBA::tk_long: - { - CORBA::Long l; - *member_label >>= l; - if (l == *(CORBA::Long *) &discrim_val) - discrim_matched = 1; - } - break; - case CORBA::tk_ulong: - { - CORBA::ULong l; - *member_label >>= l; - if (l == *(CORBA::ULong *) &discrim_val) - discrim_matched = 1; - } - break; - case CORBA::tk_enum: - { - CORBA::ULong ul; - TAO_InputCDR stream (member_label->_tao_get_cdr (), - member_label->_tao_byte_order ()); - (void)stream.decode (discrim_tc.in (), &ul, 0, ACE_TRY_ENV); - if (ul == *(CORBA::ULong *) &discrim_val) - discrim_matched = 1; - } - break; - case CORBA::tk_char: - { - CORBA::Char c; - *member_label >>= CORBA::Any::to_char (c); - if (c == *(CORBA::Char *) &discrim_val) - discrim_matched = 1; - } - break; - case CORBA::tk_wchar: - CORBA::WChar wc; - *member_label >>= CORBA::Any::to_wchar (wc); - if (wc == *(CORBA::WChar *) &discrim_val) - discrim_matched = 1; - break; - case CORBA::tk_boolean: - { - CORBA::Boolean b; - *member_label >>= CORBA::Any::to_boolean (b); - if (b == *(CORBA::Boolean *) &discrim_val) - discrim_matched = 1; - } - break; - default: - ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), - CORBA::TypeCode::TRAVERSE_STOP); - }// end of switch + case CORBA::tk_char: + { + if (!src->read_char (char_v)) + return CORBA::TypeCode::TRAVERSE_STOP; + } + break; + + case CORBA::tk_wchar: + { + if (!src->read_wchar (wchar_v)) + return CORBA::TypeCode::TRAVERSE_STOP; + } + break; + + case CORBA::tk_boolean: + { + if (!src->read_boolean (boolean_v)) + return CORBA::TypeCode::TRAVERSE_STOP; + } + break; - // get the member typecode - member_tc = tc->member_type (i, ACE_TRY_ENV); + default: + return CORBA::TypeCode::TRAVERSE_STOP; + } + + CORBA::ULong member_count = + tc->member_count (ACE_TRY_ENV); + ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + + CORBA::ULong current_member = ~0UL; + CORBA::ULong default_member = ~0UL; + for (CORBA::ULong i = 0; + i != member_count && current_member == ~0UL; + ++i) + { + CORBA::Any *any = + tc->member_label (i, ACE_TRY_ENV); + ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + + CORBA::Octet o; + if ((*any >>= CORBA::Any::to_octet (o)) && o == 0) + { + CORBA::ULong default_index = + tc->default_index (ACE_TRY_ENV); ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); - // have we reached the default label, if so save a handle to - // the typecode for the default + if (i != default_index) + ACE_THROW_RETURN (CORBA::BAD_TYPECODE (), + CORBA::TypeCode::TRAVERSE_STOP); + // Found the default branch, save its position and continue + // trying to find the current value... + default_member = i; + continue; + } - if (default_index >= 0 && default_index-- == 0) - default_tc = member_tc.in (); - if (discrim_matched) - { - // marshal according to the matched typecode - return stream->skip (member_tc.in (), ACE_TRY_ENV); - } + switch (kind) + { + case CORBA::tk_short: + { + CORBA::Short d; + if ((*any >>= d) && d == short_v) + current_member = i; + } + break; + + case CORBA::tk_ushort: + { + CORBA::UShort d; + if ((*any >>= d) && d == ushort_v) + current_member = i; + } + break; + + case CORBA::tk_long: + { + CORBA::Long d; + if ((*any >>= d) && d == long_v) + current_member = i; + } + break; + + case CORBA::tk_ulong: + { + CORBA::ULong d; + if ((*any >>= d) && d == ulong_v) + current_member = i; + } + break; + + case CORBA::tk_enum: + { + CORBA::ULong d; + // @@ Will this work???? + if ((*any >>= d) && d == enum_v) + current_member = i; + } + break; + + case CORBA::tk_char: + { + CORBA::Char d; + if ((*any >>= CORBA::Any::to_char (d)) && d == char_v) + current_member = i; + } + break; + + case CORBA::tk_wchar: + { + CORBA::WChar d; + if ((*any >>= CORBA::Any::to_wchar (d)) && d == wchar_v) + current_member = i; + } + break; + + case CORBA::tk_boolean: + { + CORBA::Boolean d; + if ((*any >>= CORBA::Any::to_boolean (d)) && d == boolean_v) + current_member = i; + } + break; + + default: + return CORBA::TypeCode::TRAVERSE_STOP; + } + } + + if (current_member == ~0UL) + { + // Cannot find the current member, check if there is a + // default... + if (default_member != ~0UL) + { + // Good, use the default to append... + CORBA::TypeCode_ptr member_tc = + tc->member_type (default_member, ACE_TRY_ENV); + ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + return src->skip (member_tc, ACE_TRY_ENV); } - if (default_tc != 0) - return stream->skip (default_tc, ACE_TRY_ENV); + return CORBA::TypeCode::TRAVERSE_STOP; } - return retval; + + // If we found the member successfully then just use that one... + CORBA::TypeCode_ptr member_tc = + tc->member_type (current_member, ACE_TRY_ENV); + ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + return src->skip (member_tc, ACE_TRY_ENV); } // decode string |