// Get the length from the (possibly aliased) typecode. CORBA::ULong TAO_DynArray_i::get_tc_length (CORBA::TypeCode_ptr tc) { CORBA::TypeCode_var tctmp = CORBA::TypeCode::_duplicate (tc); CORBA::TCKind kind = tctmp->kind (); while (kind == CORBA::tk_alias) { tctmp = tctmp->content_type (); kind = tctmp->kind (); } return tctmp->length (); }
//---------------------------------------------------------------------- std::string AnyAide::getId(const CORBA::Any& any) { CORBA::TCKind kind = getRealType(any); //great - the identifier is already provided if ((kind==CORBA::tk_objref) || (kind==CORBA::tk_struct) || (kind==CORBA::tk_union) || (kind==CORBA::tk_enum) || (kind==CORBA::tk_except)) { //have to create an _var type because this is actually a CORBA object CORBA::TypeCode_var tc; //get the type from the any tc = any.type(); return std::string(tc->id()); } else if(kind==CORBA::tk_null) { return nullType_m; } else if(kind==CORBA::tk_string) { return stringType_m; } else if(kind==CORBA::tk_double) { return doubleType_m; } else if(kind==CORBA::tk_long) { return longType_m; } else if(kind==CORBA::tk_ulong) { return uLongType_m; } else if(kind==CORBA::tk_longlong) { return longLongType_m; } else if(kind==CORBA::tk_ulonglong) { return uLongLongType_m; } else if(kind==CORBA::tk_float) { return floatType_m; } //aliases can be ... else if(kind==CORBA::tk_alias) { //first get a hold of the IFR id CORBA::TypeCode_var tc; //get the type from the any tc = any.type(); return std::string(tc->id()); } // after TAO 1.5.2 we have to handel seqence separatly else if (kind==CORBA::tk_sequence) { //!!! here we play dirty !!! // this solution does not work with seq of seq // we can change it but first we have to change it on the places where seqences are used !! CORBA::TypeCode_var tc; //get the type from the any tc = any.type(); //create another any with type of content type (long/double ..) CORBA::Any a; a._tao_set_typecode(tc->content_type()); // get recursivly the ID of contained type std::string c = getId(a); return std::string("IDL:alma/ACS/" + c + "Seq:1.0"); // very dirty but should be OK } //bad case else { UnsupportedType except; except.type = unknownType_m; throw except; } }
bool recursive_union_test () { bool rc = true; ACE_DEBUG ((LM_INFO, "Executing recursive union test\n")); ACE_DEBUG ((LM_INFO, "* Simple marshaling -> demarshaling\n")); { CORBA::Any the_any, the_out_any; static CORBA::Short const test_short = 23901; Test::RecursiveUnion3 foo3; foo3.a (test_short); the_any <<= foo3; TAO_OutputCDR out; out << the_any; out.consolidate (); if (TAO_debug_level >= 2) { if (out.length () > 512) { ACE_HEX_DUMP ((LM_INFO, out.buffer (), 512, ACE_TEXT ("Encoded union (1):"))); ACE_HEX_DUMP ((LM_INFO, out.buffer ()+512, out.length ()-512, ACE_TEXT ("Encoded union (2):"))); } else { ACE_HEX_DUMP ((LM_INFO, out.buffer (), out.length (), ACE_TEXT ("Encoded union:"))); } } TAO_InputCDR in(out); if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> Extracting any\n")); in >> the_out_any; if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> Extracted any\n")); } // Any's typecode out of scope if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> Any destructed\n")); ACE_DEBUG ((LM_INFO, "* Marshaling -> demarshaling with external reference\n")); { CORBA::TypeCode_var tc; { CORBA::Any the_any, the_out_any; static CORBA::Short const test_short = 23901; Test::RecursiveUnion3 foo3; foo3.a (test_short); the_any <<= foo3; TAO_OutputCDR out; out << the_any; out.consolidate (); if (TAO_debug_level >= 2) { if (out.length () > 512) { ACE_HEX_DUMP ((LM_INFO, out.buffer (), 512, ACE_TEXT ("Encoded union (1):"))); ACE_HEX_DUMP ((LM_INFO, out.buffer ()+512, out.length ()-512, ACE_TEXT ("Encoded union (2):"))); } else { ACE_HEX_DUMP ((LM_INFO, out.buffer (), out.length (), ACE_TEXT ("Encoded union:"))); } } TAO_InputCDR in(out); if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> Extracting any\n")); in >> the_out_any; tc = the_out_any._tao_get_typecode ()->member_type (1); // union case type -> alias tc = tc->content_type (); // alias content type -> sequence tc = tc->content_type (); // sequence content type -> recursive struct tc = tc->member_type (0); // struct member type -> union tc = tc->member_type (1); // union case type -> alias tc = tc->content_type (); // alias content type -> sequence tc = tc->content_type (); // sequence content type -> indirected struct if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> Extracted any and stored external reference to Indirected_Type typecode\n")); } // Any's typecode out of scope if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> Any destructed\n")); } // referenced recursive typecode out of scope // Any's typecode out of scope if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> External Indirected_Type typecode reference destructed\n")); ACE_DEBUG ((LM_INFO, "* Marshaling -> demarshaling -> marshaling -> demarshaling\n")); { CORBA::Any the_any, the_out_any, the_out_any2; static CORBA::Short const test_short = 23901; Test::RecursiveUnion3 foo3; foo3.a (test_short); the_any <<= foo3; TAO_OutputCDR out; out << the_any; out.consolidate (); if (TAO_debug_level >= 2) { if (out.length () > 512) { ACE_HEX_DUMP ((LM_INFO, out.buffer (), 512, ACE_TEXT ("Encoded union (1):"))); ACE_HEX_DUMP ((LM_INFO, out.buffer ()+512, out.length ()-512, ACE_TEXT ("Encoded union (2):"))); } else { ACE_HEX_DUMP ((LM_INFO, out.buffer (), out.length (), ACE_TEXT ("Encoded union:"))); } } TAO_InputCDR in(out); if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> Extracting any\n")); in >> the_out_any; if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> Extracted any\n")); TAO_OutputCDR out2; out2 << the_out_any; out2.consolidate (); if (TAO_debug_level >= 2) { if (out2.length () > 512) { ACE_HEX_DUMP ((LM_INFO, out2.buffer (), 512, ACE_TEXT ("Re-encoded union (1):"))); ACE_HEX_DUMP ((LM_INFO, out2.buffer ()+512, out2.length ()-512, ACE_TEXT ("Re-encoded union (2):"))); } else { ACE_HEX_DUMP ((LM_INFO, out2.buffer (), out2.length (), ACE_TEXT ("Re-encoded union:"))); } } // Unfortunately this test in unreliable due to the memory management optimizations of ACE, particularly // concerning the non-initialization of allocated memory. When running with Valgrind all memory is forcibly // initialized to 0 and than this test passes. // // if (out.length () != out2.length () || ACE_OS::memcmp (out.buffer (), out2.buffer (), out.length ()) != 0) // { // ACE_ERROR ((LM_ERROR, // "encoded representations of recursive typecodes differ\n")); // // rc = false; // } TAO_InputCDR in2(out2); if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> Re-extracting any\n")); in2 >> the_out_any2; if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> Re-extracted any\n")); if (!the_out_any._tao_get_typecode ()->equal (the_out_any2._tao_get_typecode ())) { ACE_ERROR ((LM_ERROR, "extracted recursive typecodes differ\n")); rc = false; } } // Any's typecodes out of scope if (TAO_debug_level >= 1) ACE_DEBUG ((LM_INFO, "> Anys destructed\n")); return rc; }
void DynAnyAnalyzer::analyze (DynamicAny::DynAny_ptr da) { CORBA::TypeCode_var tc = da->type (); CORBA::TCKind kind = tc->kind (); CORBA::TypeCode_var dup = CORBA::TypeCode::_duplicate (tc.in ()); // strip aliases while (kind == CORBA::tk_alias) { dup = dup->content_type (); kind = dup->kind (); } switch (kind) { case CORBA::tk_struct: { DynamicAny::DynStruct_var ds = DynamicAny::DynStruct::_narrow (da); tab (level_); if (debug_) { ACE_DEBUG ((LM_DEBUG, "STRUCT\n")); } if (da->seek (0) ) { level_++; do { DynamicAny::DynAny_var cc = ds->current_component (); DynamicAny::FieldName_var fn = ds->current_member_name (); tab(level_); if (debug_) { ACE_DEBUG ((LM_DEBUG, "Member = %C\n", fn.in ())); } if (!CORBA::is_nil (cc.in ())) { this->analyze (cc.in ()); } } while (da->next ()); level_--; } } break; // end tk_struct case CORBA::tk_sequence: { if (TAO_DynCommon::is_basic_type_seq (tc.in ())) { this->analyze_basic_seq (dup.in (), da); } else { DynamicAny::DynSequence_var ds = DynamicAny::DynSequence::_narrow (da); int i = 0; tab(level_); if (debug_) { ACE_DEBUG ((LM_DEBUG, "SEQUENCE\n")); } if (ds->seek (0UL)) { level_++; do { tab(level_); if (debug_) ACE_DEBUG ((LM_DEBUG, "[%d]\n", i)); DynamicAny::DynAny_var cc (ds->current_component ()); if (!CORBA::is_nil (cc.in ())) { analyze (cc.in ()); } i++; } while (da->next ()); level_--; } } } break; // end tk_sequence case CORBA::tk_array: { tab (level_); if (debug_) { ACE_DEBUG ((LM_DEBUG, "ARRAY\n")); } level_++; CORBA::ULong const len = dup->length (); for (CORBA::ULong i = 0 ; i < len; ++i) { tab (level_); if (debug_) { ACE_DEBUG ((LM_DEBUG, "[%d]\n", i)); } DynamicAny::DynAny_var cc = da->current_component(); if (!CORBA::is_nil (cc.in ())) { analyze (cc.in ()); } da->next (); } level_--; } break; case CORBA::tk_union: { DynamicAny::DynUnion_var value = DynamicAny::DynUnion::_narrow (da); if (!value->has_no_active_member ()) { DynamicAny::DynAny_var disc = value->member (); if (!CORBA::is_nil (disc.in ())) { this->analyze (disc.in ()); } } } break; case CORBA::tk_any: { DynamicAny::DynAny_var dynany; CORBA::Any_var any = da->get_any (); dynany = dynany_factory_->create_dyn_any (any.in ()); if (!CORBA::is_nil (dynany.in ())) { this->analyze (dynany.in ()); } dynany->destroy (); } break; case CORBA::tk_enum: { DynamicAny::DynEnum_var value = DynamicAny::DynEnum::_narrow (da); CORBA::String_var s = value->get_as_string (); tab (level_); if (debug_) { ACE_DEBUG ((LM_DEBUG, " Value (enum) = %C\n", s.in())); } } break; CASEE (boolean, Boolean, " Value (bool) = %d\n"); CASEE (short, Short, " Value (short) = %d\n"); CASEE (ushort, UShort, " Value (ushort) = %u\n"); CASEE (long, Long, " Value (long) = %d\n"); CASEE (ulong, ULong, " Value (ulong) = %u\n"); CASEE (longlong, LongLong, " Value (longlong) %Ld\n"); CASEE (ulonglong, ULongLong, " Value (ulonglong) %Lu\n"); CASEE (char, Char, " Value (char) = %c\n"); CASEE (float, Float, " Value (float) = %f\n"); CASEE (double, Double, " Value (double) = %f\n"); CASEE (octet, Octet, " Value (octet) = %c\n"); case CORBA::tk_string: { CORBA::String_var b (da->get_string ()); tab (level_); if (debug_) { ACE_DEBUG ((LM_DEBUG, " Value (string) = %C\n", b.in ())); } } break; case CORBA::tk_TypeCode: { tab (level_); if (debug_) { CORBA::TCKind const kind = da->get_typecode ()->kind (); ACE_DEBUG ((LM_DEBUG, " Value (TypeCode) = %d\n", static_cast<int> (kind))); } } break; default: { tab (level_); if (debug_) { CORBA::TCKind const kind = tc->kind (); ACE_DEBUG ((LM_DEBUG, " unhandled typecode = %d\n", static_cast<int> (kind))); } } break; } if (debug_) { ACE_DEBUG ((LM_DEBUG, "\n")); } }