2 #include "Server_Task.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/Get_Opt.h"
6 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
7 int number_of_oneways
= 10;
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
15 while ((c
= get_opts ()) != -1)
19 ior_output_file
= get_opts
.opt_arg ();
22 number_of_oneways
= ACE_OS::atoi (get_opts
.opt_arg ());
26 ACE_ERROR_RETURN ((LM_ERROR
,
29 "-n <number of oneways>"
34 // Indicates successful parsing of the command line
39 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
44 CORBA::ORB_init (argc
, argv
);
46 CORBA::Object_var poa_object
=
47 orb
->resolve_initial_references("RootPOA");
49 if (CORBA::is_nil (poa_object
.in ()))
50 ACE_ERROR_RETURN ((LM_ERROR
,
51 " (%P|%t) Unable to initialize the POA.\n"),
54 PortableServer::POA_var root_poa
=
55 PortableServer::POA::_narrow (poa_object
.in ());
57 PortableServer::POAManager_var poa_manager
=
58 root_poa
->the_POAManager ();
60 if (parse_args (argc
, argv
) != 0)
63 Sender_i
*sender_impl
;
64 ACE_NEW_RETURN (sender_impl
,
67 PortableServer::ServantBase_var
receiver_owner_transfer(sender_impl
);
69 PortableServer::ObjectId_var id
=
70 root_poa
->activate_object (sender_impl
);
72 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
74 Test::Sender_var sender
=
75 Test::Sender::_narrow (object
.in ());
77 CORBA::String_var ior
=
78 orb
->object_to_string (sender
.in ());
80 // If the ior_output_file exists, output the ior to it
81 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
83 ACE_ERROR_RETURN ((LM_ERROR
,
84 "Cannot open output file for writing IOR: %s",
87 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
88 ACE_OS::fclose (output_file
);
90 poa_manager
->activate ();
92 Server_Task
server_task (orb
.in (),
93 ACE_Thread_Manager::instance ());
95 if (server_task
.activate (THR_NEW_LWP
| THR_JOINABLE
, 4, 1) == -1)
97 ACE_ERROR ((LM_ERROR
, "Error activating server task\n"));
99 ACE_Thread_Manager::instance ()->wait ();
101 ACE_DEBUG ((LM_DEBUG
, "Now terminating test\n"));
103 CORBA::ULong activeobjects
= sender_impl
->get_active_objects ();
104 if (((number_of_oneways
* activeobjects
) !=
105 sender_impl
->get_number_received ()) && activeobjects
!= 0)
107 ACE_ERROR ((LM_ERROR
, "Error, expected %d oneways, received %d\n",
109 sender_impl
->get_number_received()));
113 if (sender_impl
->get_number_received () == 0)
115 ACE_ERROR ((LM_ERROR
, "Error: Received no calls\n"));
119 ACE_DEBUG ((LM_DEBUG
, "Corrected amount received\n"));
123 root_poa
->destroy (true, true);
127 catch (const CORBA::Exception
& ex
)
129 ex
._tao_print_exception ("Exception caught:");