4 // A rudimentary interface repository
5 // browser, very rudimentary
8 #include "tao/IFR_Client/IFR_BasicC.h"
10 #include "ace/Log_Msg.h"
14 const char* programLabel
= "IFR Browser";
16 void listContents(const CORBA::ContainedSeq
&repoContents
);
17 void listInterface(CORBA::InterfaceDef_ptr interfaceDef
);
18 void listOperation(CORBA::OperationDescription
* operationDescr
);
19 void listParameter(CORBA::ParameterDescription
* parameterDescr
);
21 const char* decodeTypeCode(const CORBA::TypeCode_ptr typeCode
);
22 const char* decodeParameterMode(CORBA::ParameterMode mode
);
23 const char* decodeOperationMode(CORBA::OperationMode mode
);
25 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
29 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
31 CORBA::Object_var obj
=
32 orb
->resolve_initial_references("InterfaceRepository");
34 CORBA::Repository_var ifrRepo
= CORBA::Repository::_narrow(obj
.in());
36 if (CORBA::is_nil(ifrRepo
.in()))
39 ACE_TEXT("(%N) failed to narrow interface repository referece.\n")
44 CORBA::ContainedSeq_var repoContents
= ifrRepo
->contents(CORBA::dk_all
, 1);
47 ACE_TEXT("%s: the interface repository contains %d elements.\n"),
49 repoContents
->length()
51 listContents(repoContents
.in());
55 catch(const CORBA::Exception
& ex
)
57 std::cerr
<< "main() Caught CORBA::Exception : " << ex
<< std::endl
;
62 void listContents(const CORBA::ContainedSeq
& repoContents
)
65 // List the contents of each element.
67 for(unsigned int i
= 0; i
< repoContents
.length(); ++i
)
69 CORBA::Contained::Description_var desc
= repoContents
[i
]->describe();
72 case CORBA::dk_Constant
:
74 ACE_TEXT("%s: element[%d] is a constant definition.\n"),
79 case CORBA::dk_Typedef
:
81 ACE_TEXT("%s: element[%d] is a typedef definition.\n"),
86 case CORBA::dk_Exception
:
88 ACE_TEXT("%s: element[%d] is an exception definition.\n"),
93 case CORBA::dk_Interface
:
96 ACE_TEXT("%s: element[%d] is an interface definition.\n")
97 ACE_TEXT("%s: listing element[%d]...\n"),
103 CORBA::InterfaceDef_var interfaceDef
=
104 CORBA::InterfaceDef::_narrow(repoContents
[i
]);
105 listInterface(interfaceDef
.in());
108 case CORBA::dk_Module
: {
110 ACE_TEXT("%s: element[%d] is a module definition.\n"),
114 CORBA::ModuleDef_var moduleDef
=
115 CORBA::ModuleDef::_narrow(repoContents
[i
]);
116 CORBA::ContainedSeq_var moduleContents
=
117 moduleDef
->contents(CORBA::dk_all
,1);
118 CORBA::String_var moduleId
= moduleDef
->id();
119 CORBA::String_var moduleName
= moduleDef
->name();
122 ACE_TEXT("%s:\n// %s\nmodule %s\n{\n")
123 ACE_TEXT("%s: the module contains %d elements.\n"),
128 moduleContents
->length()
130 listContents(moduleContents
.in());
131 ACE_DEBUG((LM_INFO
, ACE_TEXT("}\n")));
140 void listInterface(CORBA::InterfaceDef_ptr interfaceDef
)
142 CORBA::InterfaceDef::FullInterfaceDescription_var fullDescr
=
143 interfaceDef
->describe_interface();
145 const char* interfaceName
=
147 const char* interfaceRepoId
=
151 ACE_TEXT("%s:\n\t// %s\n\tinterface %s\n\t{"),
158 unsigned int operationsCount
;
159 if ((operationsCount
= fullDescr
->operations
.length()) > 0)
161 for(unsigned int i
= 0; i
< operationsCount
; ++i
)
163 listOperation(&(fullDescr
->operations
[i
]));
167 unsigned int attributesCount
;
168 if ((attributesCount
= fullDescr
->attributes
.length()) > 0)
171 ACE_TEXT("%s: %s has %d attribute(s).\n"),
178 ACE_DEBUG((LM_INFO
, "\n\t}\n"));
181 void listOperation(CORBA::OperationDescription
* operationDescr
)
183 const char* operationName
=
184 operationDescr
->name
;
185 const char* operationRepoId
=
187 const char* operationResult
=
188 decodeTypeCode(operationDescr
->result
.in());
189 const char* operationMode
=
190 decodeOperationMode(operationDescr
->mode
);
193 ACE_TEXT("\n\t\t// %s \n\t\t%s %s %s"),
200 CORBA::ParDescriptionSeq
* params
= &(operationDescr
->parameters
);
201 CORBA::ULong paramsCount
= params
->length();
204 ACE_DEBUG((LM_INFO
, "\n\t\t(\n\t\t"));
205 for(CORBA::ULong i
=0; i
< paramsCount
; ++i
)
207 listParameter(&((*params
)[i
]));
208 if(i
< (paramsCount
- 1))
210 ACE_DEBUG((LM_INFO
, ",\n\t\t"));
213 ACE_DEBUG((LM_INFO
, "\n\t\t);\n"));
217 ACE_DEBUG((LM_INFO
, "();\n"));
221 void listParameter(CORBA::ParameterDescription
*parameterDescr
)
223 const char *typCode
=
224 decodeTypeCode(parameterDescr
->type
.in());
225 const char *paramMode
=
226 decodeParameterMode(parameterDescr
->mode
);
228 ACE_TEXT("%s %s %s"),
231 parameterDescr
->name
.in()
235 const char* decodeTypeCode(const CORBA::TypeCode_ptr typeCode
)
237 const char* code
= "";
238 if (typeCode
->equivalent(CORBA::_tc_void
)) {
240 } else if (typeCode
->equivalent(CORBA::_tc_boolean
)) {
242 } else if (typeCode
->equivalent(CORBA::_tc_string
)) {
248 const char* decodeParameterMode(CORBA::ParameterMode mode
)
250 const char* paramMode
;
253 case CORBA::PARAM_IN
:
258 case CORBA::PARAM_OUT
:
263 case CORBA::PARAM_INOUT
:
274 const char* decodeOperationMode(CORBA::OperationMode mode
)
276 return (mode
== CORBA::OP_NORMAL
) ? "synchronous" : "asynchronous";