Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Multiple_Retry_Tests / Retry_On_Reply_Failure / server.cpp
blob9d93f76d3f61558f441b36ff162ded2eb8480c87
1 #include "test_i.h"
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 num_exceptions_to_throw = 0;
9 int raise_exception = TAO::FOE_NON;
10 int num_requests = 1;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:e:n:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'o':
22 ior_output_file = get_opts.opt_arg ();
23 break;
24 case 'e':
25 raise_exception = ACE_OS::atoi (get_opts.opt_arg ());
26 break;
27 case 'n':
28 num_exceptions_to_throw = ACE_OS::atoi (get_opts.opt_arg ());
29 break;
30 case '?':
31 default:
32 ACE_ERROR_RETURN ((LM_ERROR,
33 "usage: %s "
34 "-o <iorfile> -e <raise_exception> -n <num_exceptions_to_throw>"
35 "\n",
36 argv [0]),
37 -1);
39 // Indicates successful parsing of the command line
40 return 0;
43 int
44 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
46 try
48 CORBA::ORB_var orb =
49 CORBA::ORB_init (argc, argv);
51 CORBA::Object_var poa_object =
52 orb->resolve_initial_references("RootPOA");
54 PortableServer::POA_var root_poa =
55 PortableServer::POA::_narrow (poa_object.in ());
56 if (CORBA::is_nil (root_poa.in ()))
57 ACE_ERROR_RETURN ((LM_ERROR,
58 " (%P|%t) Unable to initialize the POA.\n"),
59 1);
61 PortableServer::POAManager_var poa_manager =
62 root_poa->the_POAManager ();
64 if (parse_args (argc, argv) != 0)
65 return 1;
67 Simple_Server_i server_impl (orb.in (), num_exceptions_to_throw);
69 PortableServer::ObjectId_var id =
70 root_poa->activate_object (&server_impl);
72 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
74 Simple_Server_var server =
75 Simple_Server::_narrow (object.in ());
77 CORBA::String_var ior =
78 orb->object_to_string (server.in ());
80 CORBA::Object_var table_object =
81 orb->resolve_initial_references("IORTable");
83 IORTable::Table_var table =
84 IORTable::Table::_narrow (table_object.in ());
85 if (CORBA::is_nil (table.in ()))
86 ACE_ERROR_RETURN ((LM_ERROR,
87 " (%P|%t) Unable to initialize the IORTable.\n"),
88 1);
89 table->bind ("Simple_Server", ior.in ());
91 //ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
93 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
94 if (output_file == 0)
95 ACE_ERROR_RETURN ((LM_ERROR,
96 "Cannot open output file for writing IOR: %s",
97 ior_output_file),
98 1);
99 ACE_OS::fprintf (output_file, "%s", ior.in ());
100 ACE_OS::fclose (output_file);
102 poa_manager->activate ();
104 orb->run ();
106 ACE_DEBUG ((LM_DEBUG, "(%P|%t)server: event loop finished\n"));
108 root_poa->destroy (true, true);
110 orb->destroy ();
112 catch (const CORBA::Exception& ex)
114 ex._tao_print_exception ("Exception caught in server:");
115 return 1;
118 return 0;