1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
// $Id$
#include "DynStruct_Handler.h"
#include "DynAny_Handler.h"
#include "Basic_Deployment_Data.hpp"
#include "Common.h"
#include "ace/Null_Mutex.h"
//#include "tao/ORB.h"
#include "tao/IFR_Client/IFR_BasicC.h"
//#include "tao/TypeCodeFactory/TypeCodeFactory_Adapter_Impl.h"
#include "tao/AnyTypeCode/Struct_TypeCode.h"
namespace CIAO
{
namespace Config_Handlers
{
void create_type_map (const DataType &type,
std::map <std::basic_string<ACE_TCHAR>, DataType const *> &dt_map)
{
for (StructType::member_const_iterator i = type.struct_ ().begin_member ();
i != type.struct_ ().end_member (); ++i)
{
dt_map[(*i)->name ()] = &((*i)->type ());
}
}
DynamicAny::DynAny_ptr
DynStruct_Handler::extract_into_dynany (const DataType &type,
const DataValue &value,
CORBA::TypeCode_ptr req_tc)
{
try
{
CORBA::TypeCode_ptr tc;
if (req_tc)
tc = req_tc;
else
tc = DynStruct_Handler::create_typecode (type);
std::map <std::basic_string<ACE_TCHAR>, DataType const*> dt_map;
create_type_map (type, dt_map);
// Make the actual DynStruct
DynamicAny::DynAny_var temp =
DYNANY_HANDLER->daf ()->create_dyn_any_from_type_code (tc);
DynamicAny::DynStruct_var retval = DynamicAny::DynStruct::_narrow (temp.in ());
CORBA::ULong pos (0);
DynamicAny::NameDynAnyPairSeq values;
values.length (value.count_member ());
for (DataValue::member_const_iterator i = value.begin_member ();
i != value.end_member (); ++i)
{
values[pos].id = ACE_TEXT_ALWAYS_CHAR ((*i)->name ().c_str ());
values[pos].value = DYNANY_HANDLER->extract_into_dynany (*dt_map[(*i)->name ()],
(*i)->value ());
pos++;
}
retval->set_members_as_dyn_any (values);
return retval._retn ();
}
catch (Config_Error &ex)
{
if (type.struct_p ())
ex.add_name (type.struct_ ().typeId ());
throw ex;
}
catch (...)
{
throw Config_Error (type.struct_ ().typeId (),
ACE_TEXT ("Unknown exception"));
}
}
void
DynStruct_Handler::extract_out_of_dynany (const DynamicAny::DynAny_ptr dyn)
{
ACE_UNUSED_ARG (dyn);
ACE_ERROR ((LM_ERROR, ACE_TEXT ("Extracting Structs not yet supported\n")));
}
CORBA::TypeCode_ptr
DynStruct_Handler::create_typecode (const DataType &type)
{
if (!type.struct_p ())
{
ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: Struct type descriptioin required")));
throw Config_Error (ACE_TEXT (""), ACE_TEXT ("Expected struct type information, tc_kind may be incorrect\n"));
}
std::basic_string<ACE_TCHAR> rid (type.struct_ ().typeId ());
std::basic_string<ACE_TCHAR> name (type.struct_ ().name ());
CORBA::StructMemberSeq members;
members.length (type.struct_ ().count_member ());
CORBA::ULong pos (0);
for (StructType::member_const_iterator i = type.struct_ ().begin_member ();
i != type.struct_ ().end_member (); ++i)
{
members[pos].name = ACE_TEXT_ALWAYS_CHAR ((*i)->name ().c_str ());
members[pos].type = DYNANY_HANDLER->create_typecode ((*i)->type ());
++pos;
}
// @@ Leak this guy onto the heap to avoid a compile problem.
CORBA::TypeCode_ptr tc =
DYNANY_HANDLER->orb ()->create_struct_tc (ACE_TEXT_ALWAYS_CHAR (rid.c_str ()),
ACE_TEXT_ALWAYS_CHAR (name.c_str ()),
members);
DYNANY_HANDLER->register_typecode (type.struct_ ().typeId (),
tc);
return tc;
}
}
}
|