2 #include "tao/IORTable/IORTable.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "tao/Invocation_Utils.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
8 int expect_servant_calls
= 1;
9 int raise_exception
= TAO::FOE_NON
;
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:e:r:i:"));
18 while ((c
= get_opts ()) != -1)
22 ior_output_file
= get_opts
.opt_arg ();
25 raise_exception
= ACE_OS::atoi (get_opts
.opt_arg ());
28 expect_servant_calls
= ACE_OS::atoi (get_opts
.opt_arg ());
31 num_requests
= ACE_OS::atoi (get_opts
.opt_arg ());
35 ACE_ERROR_RETURN ((LM_ERROR
,
37 "-o <iorfile> -e <raise_exception> -r <expect_servant_calls>"
42 // Indicates successful parsing of the command line
47 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
52 CORBA::ORB_init (argc
, argv
);
54 CORBA::Object_var poa_object
=
55 orb
->resolve_initial_references("RootPOA");
57 PortableServer::POA_var root_poa
=
58 PortableServer::POA::_narrow (poa_object
.in ());
59 if (CORBA::is_nil (root_poa
.in ()))
60 ACE_ERROR_RETURN ((LM_ERROR
,
61 " (%P|%t) Unable to initialize the POA.\n"),
64 PortableServer::POAManager_var poa_manager
=
65 root_poa
->the_POAManager ();
67 if (parse_args (argc
, argv
) != 0)
70 Simple_Server_i
server_impl (orb
.in ());
72 PortableServer::ObjectId_var id
=
73 root_poa
->activate_object (&server_impl
);
75 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
77 Simple_Server_var server
=
78 Simple_Server::_narrow (object
.in ());
80 CORBA::String_var ior
=
81 orb
->object_to_string (server
.in ());
83 CORBA::Object_var table_object
=
84 orb
->resolve_initial_references("IORTable");
86 IORTable::Table_var table
=
87 IORTable::Table::_narrow (table_object
.in ());
88 if (CORBA::is_nil (table
.in ()))
89 ACE_ERROR_RETURN ((LM_ERROR
,
90 " (%P|%t) Unable to initialize the IORTable.\n"),
92 table
->bind ("Simple_Server", ior
.in ());
94 //ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
96 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
98 ACE_ERROR_RETURN ((LM_ERROR
,
99 "Cannot open output file for writing IOR: %s",
102 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
103 ACE_OS::fclose (output_file
);
105 poa_manager
->activate ();
109 ACE_DEBUG ((LM_DEBUG
, "(%P|%t)server: event loop finished\n"));
111 // If expect_servant_calls is 0, it means it's the request forward looping case so the
112 // servant continue receiving calls from a single request. We can not determine how many
113 // servant calls but it should be more than the number of requests.
114 if ((expect_servant_calls
== 0 && (server_impl
.ncalls () > num_requests
))
115 || (expect_servant_calls
> 0 && (server_impl
.ncalls () == expect_servant_calls
)))
120 ACE_ERROR_RETURN ((LM_ERROR
,
121 "server: Test failed - expected %d servant calls but got %d calls \n",
122 expect_servant_calls
, server_impl
.ncalls ()),
125 catch (const CORBA::Exception
& ex
)
127 ex
._tao_print_exception ("Exception caught:");