1 // ============================================================================
10 // Reads stringified IORs and outputs the encoded information.
13 // Jeff Hopper <jrhopper@cts.com>
14 // SCIOP and Tagged component modifications by:
15 // Jason Cohen, Lockheed Martin ATL <jcohen@atl.lmco.com>
17 // ============================================================================
20 #include "ace/Get_Opt.h"
21 #include "ace/streams.h"
23 #include "orbsvcs/CosNamingC.h"
26 ACE_TMAIN (int argcw
, ACE_TCHAR
*argvw
[])
28 CORBA::ORB_var orb_var
;
32 orb_var
= CORBA::ORB_init (argcw
, argvw
);
33 CORBA::Boolean b
= false;
34 CORBA::Boolean have_argument
= false;
37 ACE_Get_Opt
get_opt (argcw
, argvw
, ACE_TEXT ("f:n:x"));
39 while ((opt
= get_opt ()) != EOF
)
41 // some arguments have been supplied
47 // Read the CosName from the NamingService convert the
48 // object_ptr to a CORBA::String_var via the call to
51 "opening a connection to the NamingService\n"
52 "resolving the CosName %s\n",
55 CORBA::Object_var server_object
;
59 // Find the Naming Service.
60 CORBA::Object_var naming_context_object
=
61 orb_var
->resolve_initial_references ("NameService");
62 CosNaming::NamingContextExt_var naming_context
=
63 CosNaming::NamingContextExt::_narrow (naming_context_object
.in ());
65 if (CORBA::is_nil (naming_context
.in ()))
67 ACE_ERROR_RETURN ((LM_ERROR
,
68 "NameService cannot be resolved\n"),
72 CosNaming::Name
*name
=
73 naming_context
->to_name (ACE_TEXT_ALWAYS_CHAR (get_opt
.opt_arg ()));
77 server_object
= naming_context
->resolve (*name
);
78 if (CORBA::is_nil (server_object
.in ()))
80 ACE_ERROR_RETURN ((LM_ERROR
,
81 "name is not resolved to a valid object\n"),
85 catch (const CosNaming::NamingContext::NotFound
& nf
)
87 const ACE_TCHAR
*reason
;
91 case CosNaming::NamingContext::missing_node
:
92 reason
= ACE_TEXT ("missing node");
94 case CosNaming::NamingContext::not_context
:
95 reason
= ACE_TEXT ("not context");
97 case CosNaming::NamingContext::not_object
:
98 reason
= ACE_TEXT ("not object");
101 reason
= ACE_TEXT ("not known");
104 ACE_ERROR_RETURN ((LM_ERROR
,
105 "%s cannot be resolved, exception reason = %s\n",
110 catch (const CosNaming::NamingContext::InvalidName
&)
112 ACE_ERROR_RETURN ((LM_ERROR
,
113 "%s cannot be resolved, exception reason = "
119 catch (const CosNaming::NamingContext::CannotProceed
&)
121 ACE_ERROR_RETURN ((LM_ERROR
,
122 "%s cannot be resolved, exception reason = "
128 catch (const CORBA::Exception
&)
130 ACE_ERROR_RETURN ((LM_ERROR
,
131 "%s cannot be resolved, exception reason = "
132 "Unexpected Exception"
140 aString
= orb_var
->object_to_string (server_object
.in ());
142 ACE_DEBUG ((LM_DEBUG
,
143 "\nhere is the IOR\n%C\n\n",
147 b
= catior_impl
.decode(aString
, str
);
148 ACE_DEBUG ((LM_DEBUG
, "%s", str
.c_str()));
150 catch (const CORBA::Exception
&)
152 ACE_ERROR_RETURN ((LM_ERROR
,
153 "%s cannot be resolved, exception reason = "
154 "Unexpected Exception"
161 ACE_DEBUG ((LM_DEBUG
,
162 "catior returned true\n"));
164 ACE_DEBUG ((LM_DEBUG
,
165 "catior returned false\n"));
170 int have_some_input
= 0;
171 int decode_pass_count
= 0;
173 // Read the file into a CORBA::String_var.
174 ACE_DEBUG ((LM_DEBUG
,
175 "reading the file %s\n",
176 get_opt
.opt_arg ()));
178 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
179 ifstream
ifstr (ACE_TEXT_ALWAYS_CHAR(get_opt
.opt_arg ()));
184 ACE_ERROR_RETURN ((LM_ERROR
,
188 "Invalid IOR file nominated"
201 while (!ifstr
.eof ())
205 if (ifstr
.eof () || ch
== '\n' || ch
== '\r')
211 FILE* ifstr
= ACE_OS::fopen (get_opt
.opt_arg (), ACE_TEXT ("r"));
213 if (!ifstr
|| ferror (ifstr
))
217 ACE_OS::fclose (ifstr
);
219 ACE_ERROR_RETURN ((LM_ERROR
,
223 "Invalid IOR file nominated"
230 while (!feof (ifstr
))
237 while (!feof (ifstr
))
239 ch
= ACE_OS::fgetc (ifstr
);
240 if (ch
== EOF
|| ch
== '\n' || ch
== '\r')
245 #endif /* !defined (ACE_LACKS_IOSTREAM_TOTALLY) */
246 if (have_some_input
== 0 || !aString
.length())
248 if (!decode_pass_count
)
250 ACE_ERROR_RETURN ((LM_ERROR
,
254 "Empty IOR file nominated"
262 ACE_DEBUG ((LM_DEBUG
,
263 "catior returned true\n"));
264 return 0; // All done now
270 ACE_DEBUG ((LM_DEBUG
,
271 "IOR %d: here is the IOR\n%C\n\n",
272 decode_pass_count
, aString
.rep ()));
275 Catior_i fcatior_impl
;
277 b
= fcatior_impl
.decode(aString
, str
);
278 ACE_DEBUG ((LM_DEBUG
, "%s", str
.c_str()));
281 ACE_DEBUG ((LM_DEBUG
,
282 "catior returned true\n"));
284 ACE_DEBUG ((LM_DEBUG
,
285 "catior returned false\n"));
286 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
289 ACE_OS::fclose (ifstr
);
290 #endif /* !defined (ACE_LACKS_IOSTREAM_TOTALLY) */
295 int have_some_input
= 0;
296 int decode_pass_count
= 0;
298 // Read the input into a CORBA::String_var.
299 ACE_DEBUG ((LM_DEBUG
,
300 "reading from stdin\n"));
302 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
305 ACE_ERROR_RETURN ((LM_ERROR
,
309 "Invalid input stream"
325 if (cin
.eof () || ch
== '\n' || ch
== '\r')
333 if (!ifstr
|| ferror (ifstr
))
337 ACE_OS::fclose (ifstr
);
339 ACE_ERROR_RETURN ((LM_ERROR
,
343 "Invalid input stream"
349 while (!feof (ifstr
))
356 while (!feof (ifstr
))
358 ch
= ACE_OS::fgetc (ifstr
);
359 if (ch
== EOF
|| ch
== '\n' || ch
== '\r')
364 #endif /* !defined (ACE_LACKS_IOSTREAM_TOTALLY) */
366 if (have_some_input
== 0)
368 if (!decode_pass_count
)
370 ACE_ERROR_RETURN ((LM_ERROR
,
381 return 0; // All done now
387 ACE_DEBUG ((LM_DEBUG
,
388 "IOR: %d\nhere is the IOR\n%C\n\n",
389 decode_pass_count
, aString
.rep ()));
392 b
= catior_impl
.decode(aString
, str
);
393 ACE_DEBUG ((LM_DEBUG
, "%s", str
.c_str()));
396 ACE_DEBUG ((LM_DEBUG
,
397 "catior returned true\n"));
399 ACE_DEBUG ((LM_DEBUG
,
400 "catior returned false\n"));
406 ACE_ERROR_RETURN ((LM_ERROR
,
412 "and dumps the contents to stdout "
419 // check that some relevant arguments have been supplied
420 if (have_argument
== 0)
421 ACE_ERROR_RETURN ((LM_ERROR
,
427 "and dumps the contents to stdout "
432 catch (const CORBA::Exception
& ex
)
434 ACE_DEBUG ((LM_DEBUG
, "\nError:\n"));
435 ex
._tao_print_exception ("Exception in nsadd");