Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2248_Regression / server.cpp
blob8db5270df68c2b5b70bd60b6515785154c4ae7b8
1 #include "Server_ORBInitializer.h"
2 #include "Server_Request_Interceptor.h"
3 #include "test_i.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
6 #include "orbsvcs/FaultTolerance/FT_Service_Activate.h"
7 #include "tao/ORBInitializer_Registry.h"
9 const ACE_TCHAR *ior_output_file = 0;
10 const ACE_TCHAR *merged_iorstr = 0;
11 const ACE_TCHAR *key = 0;
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:k:f:"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'o':
23 ior_output_file = get_opts.opt_arg ();
24 break;
25 case 'k':
26 key = get_opts.opt_arg ();
27 break;
28 case 'f':
29 merged_iorstr = get_opts.opt_arg ();
30 break;
32 case '?':
33 default:
34 ACE_ERROR_RETURN ((LM_ERROR,
35 "usage: %s "
36 "-o <iorfile>"
37 "-k <key> "
38 "-f merged_iorstr"
39 "\n",
40 argv [0]),
41 -1);
43 // Indicates successful parsing of the command line
44 return 0;
47 int
48 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
50 try
52 Server_ORBInitializer *temp_initializer = 0;
53 ACE_NEW_RETURN (temp_initializer,
54 Server_ORBInitializer,
55 -1); // No exceptions yet!
56 PortableInterceptor::ORBInitializer_var orb_initializer =
57 temp_initializer;
59 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
61 CORBA::ORB_var orb =
62 CORBA::ORB_init (argc, argv);
64 // We do the command line parsing first
65 if (parse_args (argc, argv) != 0)
66 return -1;
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 CORBA::PolicyList policies;
82 policies.length (3);
83 policies[0] = root_poa->create_id_assignment_policy (
84 PortableServer::USER_ID);
85 policies[1] = root_poa->create_implicit_activation_policy (
86 PortableServer::NO_IMPLICIT_ACTIVATION);
87 policies[2] = root_poa->create_lifespan_policy (
88 PortableServer::PERSISTENT);
90 PortableServer::POA_var poa = root_poa->create_POA (
91 "PERS_POA", poa_manager.in (), policies);
93 for (CORBA::ULong i = 0; i < policies.length (); ++i)
95 policies[i]->destroy ();
98 // Instantiate the LCD_Display implementation class
99 Simple_Server_i display_impl (orb.in (), ACE_TEXT_ALWAYS_CHAR(key));
100 PortableServer::ObjectId_var id =
101 PortableServer::string_to_ObjectId ("IOGR_OID");
103 poa->activate_object_with_id (id.in(), &display_impl);
105 CORBA::Object_var server =
106 poa->id_to_reference (id.in ());
108 CORBA::String_var ior =
109 orb->object_to_string (server.in ());
111 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
113 // If the ior_output_file exists, output the ior to it
114 if (ior_output_file != 0)
116 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
117 if (output_file == 0)
118 ACE_ERROR_RETURN ((LM_ERROR,
119 "Cannot open output file for writing IOR: %s",
120 ior_output_file),
121 -1);
122 ACE_OS::fprintf (output_file, "%s", ior.in ());
123 ACE_OS::fclose (output_file);
126 // Set the forward references in the server request interceptor.
127 PortableInterceptor::ServerRequestInterceptor_var
128 server_interceptor = temp_initializer->server_interceptor ();
130 Simple_ServerRequestInterceptor_var interceptor =
131 Simple_ServerRequestInterceptor::_narrow (
132 server_interceptor.in ());
134 if (CORBA::is_nil (interceptor.in ()))
135 ACE_ERROR_RETURN ((LM_ERROR,
136 "(%P|%t) Could not obtain reference to "
137 "server request interceptor.\n"),
138 -1);
140 interceptor->forward_reference (ACE_TEXT_ALWAYS_CHAR(merged_iorstr));
142 poa_manager->activate ();
144 orb->run ();
146 catch (const CORBA::Exception& ex)
148 ex._tao_print_exception ("Caught exception:");
149 return -1;
151 return 0;