1 #include "Messenger_i.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("MessengerServer.ior");
8 unsigned int seconds_to_wait
= 0;
9 CORBA::Boolean servant_throws_exception
= false;
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:e:t:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.opt_arg ();
24 servant_throws_exception
= true;
25 std::cout
<< "Messenger_i::send_message() will throw an exception." << std::endl
;
28 seconds_to_wait
= ACE_OS::atoi(get_opts
.opt_arg ());
29 std::cout
<< "Messenger_i::send_message() will wait "
30 << seconds_to_wait
<< " seconds" << std::endl
;
34 ACE_ERROR_RETURN ((LM_ERROR
,
38 " -t <seconds_to_wait>"
44 // Indicates successful parsing of the command line
49 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
53 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
55 if (parse_args (argc
, argv
) != 0)
58 // Get reference to Root POA.
59 CORBA::Object_var obj
= orb
->resolve_initial_references("RootPOA");
60 PortableServer::POA_var poa
= PortableServer::POA::_narrow(obj
.in());
62 // Activate POA manager
63 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
67 PortableServer::Servant_var
<Messenger_i
> servant
= new
68 Messenger_i(seconds_to_wait
, servant_throws_exception
);
70 // Write its stringified reference to stdout
71 PortableServer::ObjectId_var oid
= poa
->activate_object(servant
.in());
72 obj
= poa
->id_to_reference(oid
.in());
73 Messenger_var messenger
= Messenger::_narrow(obj
.in());
74 CORBA::String_var str
= orb
->object_to_string(messenger
.in());
75 std::ofstream
fout(ACE_TEXT_ALWAYS_CHAR(ior_output_file
));
76 fout
<< str
.in() << std::endl
;
78 std::cout
<< "IOR written to file " << ACE_TEXT_ALWAYS_CHAR(ior_output_file
) << std::endl
;
84 catch(const CORBA::Exception
& ex
) {
85 std::cerr
<< "Caught a CORBA::Exception: " << ex
<< std::endl
;