6 #include "ace/Get_Opt.h"
8 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("Logger.ior");
11 parse_args (int argc
, ACE_TCHAR
*argv
[])
13 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
16 while ((c
= get_opts ()) != -1)
20 ior_output_file
= get_opts
.opt_arg ();
25 ACE_ERROR_RETURN ((LM_ERROR
,
32 // Indicates successful parsing of the command line
37 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
40 // Initialize the ORB.
41 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
43 if (parse_args (argc
, argv
) != 0)
46 // Get a reference to Root POA.
47 CORBA::Object_var obj
= orb
->resolve_initial_references("RootPOA");
48 PortableServer::POA_var poa
= PortableServer::POA::_narrow(obj
.in());
50 // Activate the POA manager.
51 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
54 // Create a Logger_i servant.
55 PortableServer::Servant_var
<Logger_i
> logger_servant
= new Logger_i
;
57 // Register the servant with the RootPOA, obtain its object reference,
58 // stringify it, and write it to a file.
59 PortableServer::ObjectId_var oid
= poa
->activate_object(logger_servant
.in());
60 CORBA::Object_var logger_obj
= poa
->id_to_reference(oid
.in());
61 CORBA::String_var str
= orb
->object_to_string(logger_obj
.in());
62 std::ofstream
iorFile(ACE_TEXT_ALWAYS_CHAR(ior_output_file
));
63 iorFile
<< str
.in() << std::endl
;
65 std::cout
<< "IOR written to file " << ACE_TEXT_ALWAYS_CHAR(ior_output_file
) << std::endl
;
67 // Accept requests from clients.
73 catch(const CORBA::Exception
& ex
) {
74 std::cerr
<< "Caught a CORBA exception:" << ex
<< std::endl
;