2 #include "tao/DynamicAny/DynCommon.h"
4 DynAnyAnalyzer::DynAnyAnalyzer (int argc
, ACE_TCHAR
*argv
[])
6 orb_ (CORBA::ORB_init (argc
, argv
)),
9 if (CORBA::is_nil (orb_
.in ()))
11 ACE_DEBUG ((LM_ERROR
, "Could not init orb\n"));
16 obj (orb_
->resolve_initial_references ("DynAnyFactory"));
17 dany_fact_
= DynamicAny::DynAnyFactory::_narrow(obj
.in ());
18 if (CORBA::is_nil (dany_fact_
.in ()))
20 ACE_DEBUG ((LM_ERROR
, "Nil dynamic any factory after narrow\n"));
25 DynamicAny::DynAny_ptr
26 DynAnyAnalyzer::DynAny_NoTrunc (const CORBA::Any
&any
)
28 return this->dany_fact_
29 ->create_dyn_any_without_truncation (any
);
32 DynamicAny::DynAny_ptr
33 DynAnyAnalyzer::DynAny (const CORBA::Any
&any
)
35 return this->dany_fact_
36 ->create_dyn_any (any
);
39 DynamicAny::DynAny_ptr
40 DynAnyAnalyzer::DynAny (const CORBA::TypeCode_ptr
&tc
)
42 return this->dany_fact_
43 ->create_dyn_any_from_type_code (tc
);
47 DynAnyAnalyzer::register_factory (
48 CORBA::ValueFactoryBase_var factory
)
50 factory_id
* new_fact (
51 dynamic_cast<factory_id
*> (factory
.in()));
54 tab("Registering factory for ValueType ");
55 ACE_DEBUG ((LM_DEBUG
, "%C\n", new_fact
->id ()));
56 CORBA::ValueFactoryBase_var
old_fact (
57 orb_
->register_value_factory (
58 new_fact
->id (), factory
.in () ));
63 DynAnyAnalyzer::get_base_types (
64 CORBA::TypeCode_ptr tc
,
65 BaseTypesList_t
&base_types
,
66 CORBA::ULong
*total_member_count
)
68 // First initalize to the fully derived type we are
71 CORBA::ULong numberOfBases
= 1u;
72 base_types
.size (numberOfBases
);
73 base_types
[0] = TAO_DynAnyFactory::strip_alias (tc
);
74 if (total_member_count
)
76 *total_member_count
= base_types
[0]->member_count ();
79 // Obtain each derived type's basetype and add this to the list
82 base (base_types
[0]->concrete_base_type());
83 while (0 != base
.in() &&
85 (base
= TAO_DynAnyFactory::strip_alias (base
.in()))
88 if (total_member_count
)
90 *total_member_count
+= base
->member_count ();
93 base_types
.size (numberOfBases
+ 1);
94 base_types
[numberOfBases
++] = CORBA::TypeCode::_duplicate (base
.in ());
95 base
= base
->concrete_base_type();
100 DynAnyAnalyzer::get_correct_base_type (
101 const BaseTypesList_t
&base_types
,
104 // We work backwards through the list of derived types,
105 // so index 0 is the first member of the extreme base type
106 // (assuming it has any members) once we run out of that
107 // base types members we move up the list to the next
108 // derived type until that type's members are exhausted
109 // and so on until we reach the member we have asked for.
112 currentBase
= base_types
.size ();
115 ACE_DEBUG ((LM_DEBUG
,
116 ACE_TEXT ("TAO_DynValue_i::get_correct_base_type () ")
117 ACE_TEXT ("BaseTypesList_t is not initialised\n")));
121 while (base_types
[--currentBase
]->member_count () <= index
)
123 index
-= base_types
[currentBase
]->member_count ();
126 ACE_DEBUG ((LM_DEBUG
,
127 ACE_TEXT ("TAO_DynValue_i::get_correct_base_type () ")
128 ACE_TEXT ("BaseTypesList_t is not large enough\n")));
133 // Note that the "index" has now been reduced to the range
134 // of the returning base_type.
135 return base_types
[currentBase
].in ();
138 #define CASEE(type,CT,str) case CORBA::tk_##type: {\
139 CORBA::CT b = da->get_##type();\
140 if (!newline) tab(""); ACE_DEBUG ((LM_DEBUG, str , b));\
144 DynAnyAnalyzer::analyze (
145 DynamicAny::DynAny_ptr da
,
146 CORBA::Boolean newline
)
148 CORBA::TypeCode_var
tc (da
->type ());
149 CORBA::TCKind
kind (tc
->kind ());
151 dup (CORBA::TypeCode::_duplicate (tc
.in ()));
154 while (CORBA::tk_alias
== kind
)
156 dup
= dup
->content_type ();
162 case CORBA::tk_value_box
:
164 DynamicAny::DynValueBox_var
165 box (DynamicAny::DynValueBox::_narrow (da
));
173 ACE_DEBUG ((LM_DEBUG
, "{NULL} "));
175 ACE_DEBUG ((LM_DEBUG
, "ValueBox Type: %C \"%C\": ",
176 tc
->name (), tc
->id ()));
179 ACE_DEBUG ((LM_DEBUG
, "\n"));
183 DynamicAny::DynAny_var
184 cc (box
->current_component ());
185 this->analyze (cc
.in (), true);
188 break; // end tk_valuebox
190 case CORBA::tk_value
:
192 DynamicAny::DynValue_var
193 dvt (DynamicAny::DynValue::_narrow (da
));
201 ACE_DEBUG ((LM_DEBUG
, "{NULL} "));
204 BaseTypesList_t base_types
;
205 get_base_types (tc
.in (), base_types
);
207 for (CORBA::ULong i
= 0u; i
< base_types
.size(); ++i
)
215 ACE_DEBUG ((LM_DEBUG
, "ValueType: "));
218 switch (base_types
[i
]->type_modifier ())
220 case CORBA::VM_CUSTOM
:
221 ACE_DEBUG ((LM_DEBUG
, "Custom "));
224 case CORBA::VM_ABSTRACT
:
225 ACE_DEBUG ((LM_DEBUG
, "Abstract "));
228 case CORBA::VM_TRUNCATABLE
:
229 ACE_DEBUG ((LM_DEBUG
, "Truncatable "));
236 ACE_DEBUG ((LM_DEBUG
, "%C \"%C\"\n",
237 base_types
[i
]->name (),
238 base_types
[i
]->id () ));
241 level_
-= base_types
.size();
243 if (!(dvt
->is_null ()))
245 CORBA::ULong member_number
= 0u;
249 DynamicAny::DynAny_var
250 cc (dvt
->current_component ());
251 DynamicAny::FieldName_var
252 fn (dvt
->current_member_name ());
253 CORBA::ULong sub_member_number
= member_number
;
254 const CORBA::TypeCode_ptr
255 base
= get_correct_base_type (
258 const char *const visability
=
259 ((CORBA::PRIVATE_MEMBER
==
260 base
->member_visibility (sub_member_number
)) ?
261 "Private" : "Public ");
263 ACE_DEBUG ((LM_DEBUG
, "%03u] %C \"%C\": ",
264 ++member_number
, visability
, fn
.in () ));
265 if (CORBA::is_nil (cc
.in ()))
267 ACE_DEBUG ((LM_DEBUG
, " {Null}\n"));
271 this->analyze (cc
.in (), true);
273 } while (da
->next ());
276 tab("{Has No Members}\n");
281 break; // end tk_value
283 case CORBA::tk_struct
:
285 DynamicAny::DynStruct_var
286 ds (DynamicAny::DynStruct::_narrow (da
));
290 ACE_DEBUG ((LM_DEBUG
, "\n"));
293 ACE_DEBUG ((LM_DEBUG
, "%C \"%C\"",
294 tc
->name (), tc
->id () ));
297 ACE_DEBUG ((LM_DEBUG
, "\n"));
301 DynamicAny::DynAny_var
302 cc (ds
->current_component ());
303 DynamicAny::FieldName_var
304 fn (ds
->current_member_name ());
307 ACE_DEBUG ((LM_DEBUG
, "%C\n", fn
.in ()));
308 if (!CORBA::is_nil (cc
.in ()))
310 this->analyze (cc
.in ());
312 } while (da
->next ());
317 ACE_DEBUG ((LM_DEBUG
, " Null\n"));
320 break; // end tk_struct
322 case CORBA::tk_union
:
326 ACE_DEBUG ((LM_DEBUG
, "\n"));
329 ACE_DEBUG ((LM_DEBUG
, "%C \"%C\"",
330 tc
->name (), tc
->id () ));
331 DynamicAny::DynUnion_var
332 value (DynamicAny::DynUnion::_narrow (da
));
333 if (value
->has_no_active_member ())
335 ACE_DEBUG ((LM_DEBUG
, " No Active member\n"));
339 ACE_DEBUG ((LM_DEBUG
, "\n"));
340 DynamicAny::DynAny_var
disc (value
->member ());
341 if (!CORBA::is_nil (disc
.in ()))
344 this->analyze (disc
.in ());
349 break; // end tk_union
353 DynamicAny::DynEnum_var
354 value (DynamicAny::DynEnum::_narrow (da
));
358 ACE_DEBUG ((LM_DEBUG
, "\n"));
361 ACE_DEBUG ((LM_DEBUG
, "%C \"%C\"",
362 tc
->name (), tc
->id () ));
363 CORBA::String_var
s (value
->get_as_string ());
364 ACE_DEBUG ((LM_DEBUG
, " value %C\n", s
.in()));
366 break; // end tk_enum
368 case CORBA::tk_sequence
:
370 if (TAO_DynCommon::is_basic_type_seq (tc
.in ()))
372 if (newline
) ACE_DEBUG ((LM_DEBUG
, "\n"));
373 this->analyze_basic_seq (dup
.in (), da
);
377 DynamicAny::DynSequence_var
378 ds (DynamicAny::DynSequence::_narrow (da
));
383 ACE_DEBUG ((LM_DEBUG
, "\n"));
392 ACE_DEBUG ((LM_DEBUG
, "[%03d]\n", i
));
393 DynamicAny::DynAny_var
394 cc (ds
->current_component ());
395 if (!CORBA::is_nil (cc
.in ()))
400 } while (da
->next ());
405 break; // end tk_sequence
407 case CORBA::tk_array
:
411 ACE_DEBUG ((LM_DEBUG
, "\n"));
416 CORBA::ULong
const len
= dup
->length ();
417 for (CORBA::ULong i
= 0u; i
< len
; ++i
)
420 ACE_DEBUG ((LM_DEBUG
, "[%03d]\n", i
));
421 DynamicAny::DynAny_var
422 cc (da
->current_component());
423 if (!CORBA::is_nil (cc
.in ()))
431 break; // end tk_array
436 CORBA::Any_var
any (da
->get_any ());
437 DynamicAny::DynAny_var
438 dynany (DynAny (any
.in ()));
439 if (!CORBA::is_nil (dynany
.in ()))
442 this->analyze (dynany
.in ());
448 CASEE (boolean
, Boolean
, "(bool) = %d\n");
449 CASEE (short, Short
, "(short) = %hd\n");
450 CASEE (ushort
, UShort
, "(unsigned short) = %hu\n");
451 CASEE (long, Long
, "(long) = %d\n");
452 CASEE (ulong
, ULong
, "(unsigned long) = %u\n");
453 CASEE (longlong
, LongLong
, "(longlong) %Ld\n");
454 CASEE (ulonglong
, ULongLong
, "(unsigned longlong) %Lu\n");
455 CASEE (char, Char
, "(char) = %c\n");
456 CASEE (float, Float
, "(float) = %f\n");
457 CASEE (double, Double
, "(double) = %f\n");
458 CASEE (octet
, Octet
, "(octet) = %c\n");
460 case CORBA::tk_string
:
462 CORBA::String_var
b (da
->get_string ());
467 ACE_DEBUG ((LM_DEBUG
, "(string) = \"%C\"\n",
470 break; // end tk_string
472 case CORBA::tk_TypeCode
:
475 kind
=da
->get_typecode ()->kind ();
480 ACE_DEBUG ((LM_DEBUG
, "(TypeCode) = %d\n",
481 static_cast<int> (kind
) ));
483 break; // end tk_TypeCode
491 ACE_DEBUG ((LM_DEBUG
, "\n"));
493 tab ("***Unhandled*** TypeCode = ");
494 ACE_DEBUG ((LM_DEBUG
, "%d\n",
495 static_cast<int> (kind
) ));
501 #define CASEBS(type,CT,str) case CORBA::tk_##type: {\
502 CORBA::CT##Seq_var seq (da->get_##type##_seq ());\
503 ++level_; CORBA::ULong len = seq->length ();\
504 tab ("length = "); ACE_DEBUG ((LM_DEBUG, "%u\n", len));\
505 for (CORBA::ULong i = 0; i < len; ++i) {\
506 CORBA::CT b = seq[i];\
507 tab (""); ACE_DEBUG ((LM_DEBUG, "[%3d] ", i));\
508 ACE_DEBUG ((LM_DEBUG, str, b)); }\
513 DynAnyAnalyzer::analyze_basic_seq (
514 CORBA::TypeCode_ptr tc
,
515 DynamicAny::DynAny_ptr da
)
517 CORBA::TypeCode_var
ct (tc
->content_type ());
518 CORBA::TCKind tk
= ct
->kind ();
520 tab ("BASIC Type Sequence - ");
523 CASEBS (boolean
, Boolean
, "Value (bool) = %d\n");
524 CASEBS (octet
, Octet
, "Value (octet) = %c\n");
525 CASEBS (char, Char
, "Value (char) = %c\n");
526 CASEBS (wchar
, WChar
, "Value (wchar) = %u\n");
527 CASEBS (short, Short
, "Value (short) = %d\n");
528 CASEBS (ushort
, UShort
, "Value (ushort) = %u\n");
529 CASEBS (long, Long
, "Value (long) = %d\n");
530 CASEBS (ulong
, ULong
, "Value (ulong) = %u\n");
531 CASEBS (longlong
, LongLong
, "Value (longlong) = %Ld\n");
532 CASEBS (ulonglong
, ULongLong
, "Value (ulonglong) = %Lu\n");
533 CASEBS (float, Float
, "Value (float) = %f\n");
534 CASEBS (double, Double
, "Value (double) = %f\n");
536 case CORBA::tk_longdouble
:
538 ACE_DEBUG ((LM_DEBUG
,
539 "***Unhandled*** TypeCode = %d\n",
540 static_cast<int> (tk
) ));