1 #include "TestServer.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
6 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("test.ior");
8 class Worker
: public ACE_Task_Base
11 Worker(CORBA::ORB_ptr orb
) : orb_(CORBA::ORB::_duplicate(orb
))
26 parse_args (int argc
, ACE_TCHAR
*argv
[])
28 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
31 while ((c
= get_opts ()) != -1)
35 ior_output_file
= get_opts
.opt_arg ();
40 ACE_ERROR_RETURN ((LM_ERROR
,
47 // Indicates sucessful parsing of the command line
52 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
57 CORBA::ORB_init (argc
, argv
);
59 CORBA::Object_var poa_object
=
60 orb
->resolve_initial_references("RootPOA");
62 PortableServer::POA_var root_poa
=
63 PortableServer::POA::_narrow (poa_object
.in ());
65 if (CORBA::is_nil (root_poa
.in ()))
66 ACE_ERROR_RETURN ((LM_ERROR
,
67 " (%P|%t) Panic: nil RootPOA\n"),
70 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
72 if (parse_args (argc
, argv
) != 0)
75 TestServer
*test_impl
= 0;
76 ACE_NEW_RETURN (test_impl
,
79 PortableServer::ServantBase_var
owner_transfer(test_impl
);
81 PortableServer::ObjectId_var id
=
82 root_poa
->activate_object (test_impl
);
84 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
86 Test::TestServer_var test
= Test::TestServer::_narrow (object
.in ());
88 CORBA::String_var ior
= orb
->object_to_string (test
.in ());
90 // Output the IOR to the <ior_output_file>
91 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
93 ACE_ERROR_RETURN ((LM_ERROR
,
94 "Cannot open output file for writing IOR: %s\n",
97 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
98 ACE_OS::fclose (output_file
);
100 poa_manager
->activate ();
102 // Run a CORBA worker thread
103 Worker
work (orb
.in());
104 work
.activate (THR_NEW_LWP
| THR_JOINABLE
| THR_INHERIT_SCHED
, 1);
105 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - waiting for client to call\n"));
107 if (test_impl
->got_callback() == false) {
108 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - client did not make call\n"));
112 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - making repeated calls to client\n"));
113 for (int i
= 0; i
< 10; i
++)
115 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - calling client attempt %d\n", i
));
116 test_impl
->make_callback();
119 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - stopping client\n"));
120 test_impl
->shutdown_client();
122 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - test completed\n"));
124 orb
->shutdown (); // shutdown our ORB
126 work
.wait (); // wait for the worker to finish
128 root_poa
->destroy (true, true);
132 catch (const CORBA::Exception
& ex
)
134 ex
._tao_print_exception ("Exception caught:");