Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / InterfaceRepo / IFRBrowser.cpp
blobd2bda4bf1bc892f8feb4af6e482467f8872bc85a
1 //
2 // IFRBrowser.cpp
3 //
4 // A rudimentary interface repository
5 // browser, very rudimentary
6 //
8 #include "tao/IFR_Client/IFR_BasicC.h"
9 #include "tao/ORB.h"
10 #include "ace/Log_Msg.h"
12 #include <iostream>
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[])
27 try
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()))
38 ACE_DEBUG((LM_ERROR,
39 ACE_TEXT("(%N) failed to narrow interface repository referece.\n")
40 ));
41 return -1;
44 CORBA::ContainedSeq_var repoContents = ifrRepo->contents(CORBA::dk_all, 1);
46 ACE_DEBUG((LM_INFO,
47 ACE_TEXT("%s: the interface repository contains %d elements.\n"),
48 programLabel,
49 repoContents->length()
50 ));
51 listContents(repoContents.in());
53 return 0;
55 catch(const CORBA::Exception& ex)
57 std::cerr << "main() Caught CORBA::Exception : " << ex << std::endl;
59 return 1;
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();
70 switch(desc->kind)
72 case CORBA::dk_Constant:
73 ACE_DEBUG((LM_INFO,
74 ACE_TEXT("%s: element[%d] is a constant definition.\n"),
75 programLabel,
76 i + 1
77 ));
78 break;
79 case CORBA::dk_Typedef:
80 ACE_DEBUG((LM_INFO,
81 ACE_TEXT("%s: element[%d] is a typedef definition.\n"),
82 programLabel,
83 i + 1
84 ));
85 break;
86 case CORBA::dk_Exception:
87 ACE_DEBUG((LM_INFO,
88 ACE_TEXT("%s: element[%d] is an exception definition.\n"),
89 programLabel,
90 i + 1
91 ));
92 break;
93 case CORBA::dk_Interface:
95 ACE_DEBUG((LM_INFO,
96 ACE_TEXT("%s: element[%d] is an interface definition.\n")
97 ACE_TEXT("%s: listing element[%d]...\n"),
98 programLabel,
99 i + 1,
100 programLabel,
101 i + 1
103 CORBA::InterfaceDef_var interfaceDef =
104 CORBA::InterfaceDef::_narrow(repoContents[i]);
105 listInterface(interfaceDef.in());
106 break;
108 case CORBA::dk_Module: {
109 ACE_DEBUG((LM_INFO,
110 ACE_TEXT("%s: element[%d] is a module definition.\n"),
111 programLabel,
112 i + 1
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();
121 ACE_DEBUG((LM_INFO,
122 ACE_TEXT("%s:\n// %s\nmodule %s\n{\n")
123 ACE_TEXT("%s: the module contains %d elements.\n"),
124 programLabel,
125 moduleId.in(),
126 moduleName.in(),
127 programLabel,
128 moduleContents->length()
130 listContents(moduleContents.in());
131 ACE_DEBUG((LM_INFO, ACE_TEXT("}\n")));
132 break;
134 default:
135 break;
140 void listInterface(CORBA::InterfaceDef_ptr interfaceDef)
142 CORBA::InterfaceDef::FullInterfaceDescription_var fullDescr =
143 interfaceDef->describe_interface();
145 const char* interfaceName =
146 fullDescr->name;
147 const char* interfaceRepoId =
148 fullDescr->id;
150 ACE_DEBUG((LM_INFO,
151 ACE_TEXT("%s:\n\t// %s\n\tinterface %s\n\t{"),
152 programLabel,
153 interfaceRepoId,
154 interfaceName
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)
170 ACE_DEBUG((LM_INFO,
171 ACE_TEXT("%s: %s has %d attribute(s).\n"),
172 programLabel,
173 interfaceName,
174 attributesCount
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 =
186 operationDescr->id;
187 const char* operationResult =
188 decodeTypeCode(operationDescr->result.in());
189 const char* operationMode =
190 decodeOperationMode(operationDescr->mode);
192 ACE_DEBUG((LM_INFO,
193 ACE_TEXT("\n\t\t// %s \n\t\t%s %s %s"),
194 operationRepoId,
195 operationResult,
196 operationName,
197 operationMode
200 CORBA::ParDescriptionSeq* params = &(operationDescr->parameters);
201 CORBA::ULong paramsCount = params->length();
202 if (paramsCount > 0)
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"));
215 else
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);
227 ACE_DEBUG((LM_INFO,
228 ACE_TEXT("%s %s %s"),
229 paramMode,
230 typCode,
231 parameterDescr->name.in()
235 const char* decodeTypeCode(const CORBA::TypeCode_ptr typeCode)
237 const char* code = "";
238 if (typeCode->equivalent(CORBA::_tc_void)) {
239 code = "void";
240 } else if (typeCode->equivalent(CORBA::_tc_boolean)) {
241 code = "boolean";
242 } else if (typeCode->equivalent(CORBA::_tc_string)) {
243 code = "string";
245 return code;
248 const char* decodeParameterMode(CORBA::ParameterMode mode)
250 const char* paramMode;
251 switch(mode)
253 case CORBA::PARAM_IN:
255 paramMode = "in";
256 break;
258 case CORBA::PARAM_OUT:
260 paramMode = "out";
261 break;
263 case CORBA::PARAM_INOUT:
265 paramMode = "inout";
266 break;
268 default:
269 paramMode = "";
271 return paramMode;
274 const char* decodeOperationMode(CORBA::OperationMode mode)
276 return (mode == CORBA::OP_NORMAL) ? "synchronous" : "asynchronous";