Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Bug_2768_Regression / server.cpp
blobde073456bda71a35296f3c26dc46c32eaa323026
1 #include "ace/Get_Opt.h"
2 #include "tao/IORTable/IORTable.h"
3 #include "Messenger_i.h"
5 const ACE_TCHAR *ior_output_file = ACE_TEXT("server.ior");
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'o':
17 ior_output_file = get_opts.opt_arg ();
18 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-o <iorfile>"
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
35 try
37 //init the orb
38 CORBA::ORB_var orb=CORBA::ORB_init(argc, argv);
40 //get the root poa
41 CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA");
42 PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in ());
44 PortableServer::POAManager_var poa_manager = poa->the_POAManager ();
46 if (parse_args (argc, argv) != 0)
47 return 1;
49 poa_manager->activate ();
51 // Get a reference to the IOR Table
52 CORBA::Object_var tobj = orb->resolve_initial_references("IORTable");
53 IORTable::Table_var table = IORTable::Table::_narrow(tobj.in());
55 //get an object id for the name
56 PortableServer::ObjectId_var oid =
57 PortableServer::string_to_ObjectId ("Messenger");
59 //activate the object for the given id
60 Messenger_i messenger (orb.in ());
61 poa->activate_object_with_id(oid.in (), &messenger);
62 CORBA::Object_var messenger_obj = poa->id_to_reference (oid.in ());
64 //bind the ior string to the name
65 CORBA::String_var messenger_ior_string = orb->object_to_string(messenger_obj.in());
66 table->bind("Messenger", messenger_ior_string.in());
68 // Output the IOR to the <ior_output_file>
69 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
70 if (output_file == 0)
71 ACE_ERROR_RETURN ((LM_ERROR,
72 "Cannot open output file for writing IOR: %s\n",
73 ior_output_file),
74 1);
75 ACE_OS::fprintf (output_file, "%s", messenger_ior_string.in ());
76 ACE_OS::fclose (output_file);
78 orb->run ();
80 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
82 poa->destroy (true, true);
84 orb->destroy ();
86 catch (const CORBA::Exception& ex)
88 ex._tao_print_exception ("Exception caught:");
89 return 1;
92 return 0;