Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / InterOp-Naming / INS_test_client.cpp
blobc4398122adce9d11ee3991853d522e901e66dad2
2 #include "INSC.h"
4 #include "tao/ObjectIdListC.h"
6 #include "ace/Log_Msg.h"
7 #include "ace/OS_NS_string.h"
9 int
10 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
12 int i = 0;
14 try
16 // Retrieve a reference to the ORB.
17 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
19 if (argc < 2)
21 ACE_DEBUG ((LM_DEBUG,
22 "No Name specified to be resolved\n"));
23 return -1;
26 CORBA::Object_var objref;
28 for (i = 1; i < argc; ++i)
30 if (ACE_OS::strcmp (argv[i], ACE_TEXT("-l")) == 0)
32 // List initial services
33 CORBA::ORB::ObjectIdList_var list =
34 orb->list_initial_services ();
36 size_t length = list->length ();
38 if (length > 0)
40 ACE_DEBUG ((LM_INFO,
41 "Listing initial references...\n"));
43 for (CORBA::ULong n = 0; n < length; ++n)
45 ACE_DEBUG ((LM_DEBUG,
46 " Reference %u: %C\n",
48 static_cast<char const*>(list[n])));
51 else
53 // We should at least get TAO's initial references,
54 // such as "RootPOA", "NameService", etc.
55 ACE_ERROR_RETURN ((LM_ERROR,
56 "\n"
57 "No initial references. "
58 "This condition shouldn't happen.\n"),
59 -1);
62 else
64 objref = orb->resolve_initial_references (ACE_TEXT_ALWAYS_CHAR(argv[i]));
66 if (CORBA::is_nil (objref.in ()))
67 ACE_ERROR_RETURN ((LM_ERROR,
68 " (%P|%t) Unable to resolve the "
69 "given name.\n"),
70 -1);
72 INS_var server = INS::_narrow (objref.in ());
74 CORBA::String_var iorstr =
75 orb->object_to_string (server.in ());
76 ACE_DEBUG ((LM_DEBUG,
77 "Resolved IOR for %s : %C\n",
78 argv[i],
79 iorstr.in()));
81 CORBA::String_var test_ins_result =
82 server->test_ins ();
84 ACE_DEBUG ((LM_DEBUG,
85 "\nResult of Remote Call : %C\n",
86 test_ins_result.in ()));
90 catch (const CORBA::ORB::InvalidName& )
92 ACE_DEBUG ((LM_DEBUG, "Cannot resolve <%s>\n", argv[i]));
94 catch (const CORBA::Exception& ex)
96 ex._tao_print_exception ("Exception:");
100 return 0;