Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / IOR_Endpoint_Hostnames / generate_ior.cpp
blob2b3c830f3ec24f00268aff9be5d1e8f2c61b876a
1 //
2 // This initializes an ORB, a POA, an Object within that POA, and
3 // obtains and prints an IOR for that Object.
4 #include "tao/corba.h"
5 #include "tao/PortableServer/PortableServer.h"
6 #include "ace/Get_Opt.h"
8 #include "bogus_i.h"
10 const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior");
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'o':
22 ior_output_file = get_opts.opt_arg ();
23 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-o <iorfile>"
30 "\n",
31 argv [0]),
32 -1);
34 // Indicates successful parsing of the command line
35 return 0;
38 int
39 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
41 try
43 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
45 CORBA::Object_var poa_object =
46 orb->resolve_initial_references ("RootPOA");
48 PortableServer::POA_var rp =
49 PortableServer::POA::_narrow(poa_object.in());
50 if (CORBA::is_nil (rp.in()))
51 ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) panic: nil root poa\n"), 1);
53 if (parse_args (argc, argv) != 0)
54 return 1;
56 bogus* bogus_impl = new bogus();
57 PortableServer::ServantBase_var owner_transfer(bogus_impl);
58 PortableServer::ObjectId_var id =
59 rp->activate_object (bogus_impl);
61 CORBA::Object_var object = rp->id_to_reference (id.in ());
63 Test::bogus_var b = Test::bogus::_narrow (object.in ());
64 CORBA::String_var ior =
65 orb->object_to_string (b.in());
67 // Output the IOR to the <ior_output_file>
68 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
69 if (output_file == 0)
70 ACE_ERROR_RETURN ((LM_ERROR,
71 "Cannot open output file for writing IOR: %s\n",
72 ior_output_file),
73 1);
74 ACE_OS::fprintf (output_file, "%s", ior.in ());
75 ACE_OS::fclose (output_file);
77 orb->shutdown();
78 orb->destroy();
80 catch (const CORBA::Exception& e)
82 e._tao_print_exception ("Caught exception:");
85 return 0;