3 //=============================================================================
7 * This file contains a DynAny analyzer that dumps the contents of a DynAny
10 * @author Johnny Willemsen (jwillemsen@remedy.nl)
12 //=============================================================================
16 #include "tao/DynamicAny/DynCommon.h"
17 #include "tao/DynamicAny/DynAnyFactory.h"
19 #define CASEE(type,CT,str) case CORBA::tk_##type: {\
20 CORBA::CT b = da->get_##type(); \
23 ACE_DEBUG ((LM_DEBUG, str , b)); \
26 #define CASEBS(type,CT,str) case CORBA::tk_##type: \
28 CORBA::CT##Seq_var seq = da->get_##type##_seq (); \
30 CORBA::ULong len = seq->length (); \
34 ACE_DEBUG ((LM_DEBUG, "length = %u\n", len)); \
36 for (CORBA::ULong i = 0; i < len; ++i) \
38 CORBA::CT b = seq[i]; \
42 ACE_DEBUG ((LM_DEBUG, "[%d]\n", i)); \
43 ACE_DEBUG ((LM_DEBUG, str, b)); \
50 DynAnyAnalyzer::DynAnyAnalyzer (CORBA::ORB_ptr orb
,
51 DynamicAny::DynAnyFactory_ptr dynany_factory
,
53 : orb_ (CORBA::ORB::_duplicate (orb
)),
54 dynany_factory_ (DynamicAny::DynAnyFactory::_duplicate (dynany_factory
)),
60 void DynAnyAnalyzer::tab (int t
)
64 for (int i
= 0 ; i
< t
; ++i
)
66 ACE_DEBUG ((LM_DEBUG
, "\t"));
71 DynAnyAnalyzer::~DynAnyAnalyzer ()
75 void DynAnyAnalyzer::resetTab ()
80 void DynAnyAnalyzer::analyze (DynamicAny::DynAny_ptr da
)
82 CORBA::TypeCode_var tc
= da
->type ();
84 CORBA::TCKind kind
= tc
->kind ();
86 CORBA::TypeCode_var dup
= CORBA::TypeCode::_duplicate (tc
.in ());
89 while (kind
== CORBA::tk_alias
)
91 dup
= dup
->content_type ();
98 case CORBA::tk_struct
:
100 DynamicAny::DynStruct_var ds
101 = DynamicAny::DynStruct::_narrow (da
);
107 ACE_DEBUG ((LM_DEBUG
,
117 DynamicAny::DynAny_var cc
=
118 ds
->current_component ();
120 DynamicAny::FieldName_var fn
=
121 ds
->current_member_name ();
127 ACE_DEBUG ((LM_DEBUG
,
128 "Member = %C\n", fn
.in ()));
131 if (!CORBA::is_nil (cc
.in ()))
133 this->analyze (cc
.in ());
136 } while (da
->next ());
141 break; // end tk_struct
143 case CORBA::tk_sequence
:
145 if (TAO_DynCommon::is_basic_type_seq (tc
.in ()))
147 this->analyze_basic_seq (dup
.in (), da
);
151 DynamicAny::DynSequence_var ds
=
152 DynamicAny::DynSequence::_narrow (da
);
159 ACE_DEBUG ((LM_DEBUG
,
172 ACE_DEBUG ((LM_DEBUG
,
175 DynamicAny::DynAny_var
cc (ds
->current_component ());
177 if (!CORBA::is_nil (cc
.in ()))
183 } while (da
->next ());
189 break; // end tk_sequence
191 case CORBA::tk_array
:
197 ACE_DEBUG ((LM_DEBUG
,
203 CORBA::ULong
const len
=
206 for (CORBA::ULong i
= 0 ; i
< len
; ++i
)
212 ACE_DEBUG ((LM_DEBUG
, "[%d]\n", i
));
215 DynamicAny::DynAny_var cc
= da
->current_component();
217 if (!CORBA::is_nil (cc
.in ()))
228 case CORBA::tk_union
:
230 DynamicAny::DynUnion_var value
=
231 DynamicAny::DynUnion::_narrow (da
);
233 if (!value
->has_no_active_member ())
235 DynamicAny::DynAny_var disc
= value
->member ();
237 if (!CORBA::is_nil (disc
.in ()))
239 this->analyze (disc
.in ());
247 DynamicAny::DynAny_var dynany
;
248 CORBA::Any_var any
= da
->get_any ();
251 dynany_factory_
->create_dyn_any (any
.in ());
253 if (!CORBA::is_nil (dynany
.in ()))
255 this->analyze (dynany
.in ());
264 DynamicAny::DynEnum_var value
=
265 DynamicAny::DynEnum::_narrow (da
);
267 CORBA::String_var s
= value
->get_as_string ();
272 ACE_DEBUG ((LM_DEBUG
, " Value (enum) = %C\n", s
.in()));
277 CASEE (boolean
, Boolean
, " Value (bool) = %d\n");
278 CASEE (short, Short
, " Value (short) = %d\n");
279 CASEE (ushort
, UShort
, " Value (ushort) = %u\n");
280 CASEE (long, Long
, " Value (long) = %d\n");
281 CASEE (ulong
, ULong
, " Value (ulong) = %u\n");
282 CASEE (longlong
, LongLong
, " Value (longlong) %Ld\n");
283 CASEE (ulonglong
, ULongLong
, " Value (ulonglong) %Lu\n");
284 CASEE (char, Char
, " Value (char) = %c\n");
285 CASEE (float, Float
, " Value (float) = %f\n");
286 CASEE (double, Double
, " Value (double) = %f\n");
287 CASEE (octet
, Octet
, " Value (octet) = %c\n");
289 case CORBA::tk_string
:
291 CORBA::String_var
b (da
->get_string ());
296 ACE_DEBUG ((LM_DEBUG
, " Value (string) = %C\n", b
.in ()));
301 case CORBA::tk_TypeCode
:
307 CORBA::TCKind
const kind
=
308 da
->get_typecode ()->kind ();
310 ACE_DEBUG ((LM_DEBUG
,
311 " Value (TypeCode) = %d\n",
312 static_cast<int> (kind
)));
323 CORBA::TCKind
const kind
=
326 ACE_DEBUG ((LM_DEBUG
,
327 " unhandled typecode = %d\n",
328 static_cast<int> (kind
)));
336 ACE_DEBUG ((LM_DEBUG
, "\n"));
341 DynAnyAnalyzer::analyze_basic_seq (CORBA::TypeCode_ptr tc
,
342 DynamicAny::DynAny_ptr da
)
344 CORBA::TypeCode_var ct
= tc
->content_type ();
345 CORBA::TCKind tk
= ct
->kind ();
351 ACE_DEBUG ((LM_DEBUG
,
352 "BASIC TYPE SEQUENCE\n"));
357 CASEBS (boolean
, Boolean
, " Value (bool) = %d\n");
358 CASEBS (octet
, Octet
, " Value (octet) = %c\n");
359 CASEBS (char, Char
, " Value (char) = %c\n");
360 CASEBS (wchar
, WChar
, " Value (wchar) = %u\n");
361 CASEBS (short, Short
, " Value (short) = %d\n");
362 CASEBS (ushort
, UShort
, " Value (ushort) = %u\n");
363 CASEBS (long, Long
, " Value (long) = %d\n");
364 CASEBS (ulong
, ULong
, " Value (ulong) = %u\n");
365 CASEBS (longlong
, LongLong
, " Value (longlong) = %Ld\n");
366 CASEBS (ulonglong
, ULongLong
, " Value (ulonglong) = %Lu\n");
367 CASEBS (float, Float
, " Value (float) = %f\n");
368 CASEBS (double, Double
, " Value (double) = %f\n");
369 case CORBA::tk_longdouble
:
375 ACE_DEBUG ((LM_DEBUG
,
376 " unhandled typecode = %d\n",
377 static_cast<int> (tk
)));