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");
8 parse_args (int argc
, ACE_TCHAR
*argv
[])
10 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
13 while ((c
= get_opts ()) != -1)
17 ior_output_file
= get_opts
.opt_arg ();
22 ACE_ERROR_RETURN ((LM_ERROR
,
29 // Indicates successful parsing of the command line
33 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
38 CORBA::ORB_var orb
=CORBA::ORB_init(argc
, argv
);
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)
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");
71 ACE_ERROR_RETURN ((LM_ERROR
,
72 "Cannot open output file for writing IOR: %s\n",
75 ACE_OS::fprintf (output_file
, "%s", messenger_ior_string
.in ());
76 ACE_OS::fclose (output_file
);
80 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
82 poa
->destroy (true, true);
86 catch (const CORBA::Exception
& ex
)
88 ex
._tao_print_exception ("Exception caught:");