1 #include "amh_ami_pch.h"
4 #include "ace/Get_Opt.h"
10 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("middle.ior");
11 const ACE_TCHAR
*ior_input_file
= ACE_TEXT ("file://inner.ior");
14 parse_args (int argc
, ACE_TCHAR
*argv
[])
16 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:i:n"));
19 while ((c
= get_opts ()) != -1)
23 ior_output_file
= get_opts
.opt_arg ();
26 ior_input_file
= get_opts
.opt_arg ();
33 ACE_ERROR_RETURN ((LM_ERROR
,
35 "-o <ior_output_file> "
36 "-i <ior_input_file> "
42 // Indicates successful parsing of the command line
48 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
51 // Initialize the ORB.
52 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
54 if (parse_args (argc
, argv
) != 0)
57 //Get reference to the RootPOA.
58 CORBA::Object_var obj
= orb
->resolve_initial_references( "RootPOA" );
59 PortableServer::POA_var poa
= PortableServer::POA::_narrow( obj
.in() );
61 // Activate the POAManager.
62 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
65 obj
= orb
->string_to_object(ior_input_file
);
67 Inner::_narrow(obj
.in());
68 if (CORBA::is_nil(peer
.in()))
70 std::cerr
<< "Could not initialize peer object reference" << std::endl
;
74 // create either a synchronous or AMH_based servant depending on command
76 PortableServer::ServantBase_var servant
;
78 servant
= new Middle_i (peer
.in());
80 servant
= new Asynch_Middle_i(poa
.in(), peer
.in());
82 // Register the servant with the RootPOA, obtain its object
83 // reference, stringify it, and write it to a file.
84 PortableServer::ObjectId_var oid
= poa
->activate_object(servant
.in());
85 obj
= poa
->id_to_reference( oid
.in() );
86 CORBA::String_var str
= orb
->object_to_string( obj
.in() );
88 ACE_CString
iorname(ACE_TEXT_ALWAYS_CHAR(ior_output_file
));
89 std::ofstream
iorFile (iorname
.c_str());
90 iorFile
<< str
.in() << std::endl
;
92 std::cout
<< "IOR written to " << iorname
<< std::endl
;
94 // Accept requests from clients.
100 catch(const CORBA::Exception
& ex
) {
101 std::cerr
<< "CORBA exception: " << ex
<< std::endl
;