Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Bug_3079 / server.cpp
blob89724f343bc458805dfe2da722a4afc32403d23b
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
3 #include "test_i.h"
4 #include "Server_ORBInitializer.h"
5 #include "Server_Request_Interceptor.h"
6 #include "tao/ORBInitializer_Registry.h"
7 #include "ace/OS_NS_stdio.h"
8 #include "CrashPoint.h"
10 const ACE_TCHAR *ior_file = 0;
11 int number = 0;
12 int server_number = 0;
14 int
15 parse_args (int argc, ACE_TCHAR *argv[])
17 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:c:n:s:"));
18 int c;
20 while ((c = get_opts ()) != -1)
21 switch (c)
23 case 'o':
24 ior_file = get_opts.opt_arg ();
25 break;
26 case 'c':
27 crash_point = ACE_OS::atoi (get_opts.opt_arg ());
28 break;
29 case 'n':
30 number = ACE_OS::atoi (get_opts.opt_arg ());
31 break;
32 case 's':
33 server_number = ACE_OS::atoi (get_opts.opt_arg ());
34 break;
35 default:
36 ACE_ERROR_RETURN ((LM_ERROR,
37 "Usage: %s "
38 "-o <IOR> "
39 "-c <CrashPoint> "
40 "-n <server number>\n",
41 argv[0]),
42 -1);
45 return 0;
48 int
49 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
51 try
53 #if TAO_HAS_INTERCEPTORS == 1
54 Server_ORBInitializer *temp_initializer = 0;
55 ACE_NEW_RETURN (temp_initializer,
56 Server_ORBInitializer,
57 -1); // No exceptions yet!
58 PortableInterceptor::ORBInitializer_var orb_initializer =
59 temp_initializer;
61 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
62 #endif /* TAO_HAS_INTERCEPTORS == 1 */
64 CORBA::ORB_var orb =
65 CORBA::ORB_init (argc, argv, "Server ORB");
67 CORBA::Object_var poa_object =
68 orb->resolve_initial_references ("RootPOA");
70 if (CORBA::is_nil (poa_object.in ()))
71 ACE_ERROR_RETURN ((LM_ERROR,
72 " (%P|%t) Unable to initialize the POA.\n"),
73 1);
75 PortableServer::POA_var root_poa =
76 PortableServer::POA::_narrow (poa_object.in ());
78 PortableServer::POAManager_var poa_manager =
79 root_poa->the_POAManager ();
81 if (::parse_args (argc, argv) != 0)
82 return -1;
84 test_i *test_impl;
85 ACE_NEW_RETURN (test_impl, test_i (number, orb.in ()), 1);
86 PortableServer::ServantBase_var owner_transfer (test_impl);
88 PortableServer::ObjectId_var id =
89 root_poa->activate_object (test_impl);
91 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
93 RedirectionTest::test_var test =
94 RedirectionTest::test::_narrow (object.in ());
96 CORBA::String_var ior =
97 orb->object_to_string (test.in ());
99 FILE *output_file= ACE_OS::fopen (ior_file, "w");
100 if (output_file == 0)
101 ACE_ERROR_RETURN ((LM_ERROR,
102 "Cannot open output file <%s> for writing "
103 "IOR: %C\n",
104 ior_file, ior.in ()),
106 ACE_OS::fprintf (output_file, "%s", ior.in ());
107 ACE_OS::fclose (output_file);
109 if (server_number == 2)
110 ACE_OS::exit (1);
112 poa_manager->activate ();
114 // Run the ORB event loop.
115 orb->run ();
117 root_poa->destroy (true, true);
119 orb->destroy ();
121 ACE_DEBUG ((LM_DEBUG, "Event loop finished.\n"));
123 catch (const CORBA::Exception& ex)
125 ex._tao_print_exception ("Caught exception:");
126 return -1;
129 return 0;