Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / ImplRepo / Bug_689_Regression / server.cpp
blob9738d4495e7aa0d9ac19adfcb923ca6731d8bca6
1 #include "tao/ORB.h"
2 #include "tao/PortableServer/PortableServer.h"
3 #include "tao/ImR_Client/ImR_Client.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/Argv_Type_Converter.h"
7 #include "bug_689_regression_i.h"
9 const ACE_TCHAR *ior_output_file = ACE_TEXT ("server.ior");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("o:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'o':
21 ior_output_file = get_opts.opt_arg ();
22 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-o <ior file> "
29 "\n",
30 argv [0]),
31 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 int
38 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
40 try
42 ACE_Argv_Type_Converter argcon (argc, argv);
43 CORBA::ORB_var orb = CORBA::ORB_init (argcon.get_argc (),
44 argcon.get_TCHAR_argv ());
46 if (parse_args (argc, argv) != 0)
47 return 1;
49 CORBA::Object_var poa_object =
50 orb->resolve_initial_references ("RootPOA");
52 PortableServer::POA_var root_poa =
53 PortableServer::POA::_narrow (poa_object.in ());
55 if (CORBA::is_nil (root_poa.in ()))
56 ACE_ERROR_RETURN ((LM_ERROR,
57 " (%P|%t) Panic: nil RootPOA\n"),
58 1);
60 PortableServer::POAManager_var poa_manager =
61 root_poa->the_POAManager ();
63 CORBA::PolicyList policies (5);
64 policies.length (5);
65 policies[0] =
66 root_poa->create_id_assignment_policy (PortableServer::USER_ID);
68 policies[1] =
69 root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
71 policies[2] =
72 root_poa->create_request_processing_policy (
73 PortableServer::USE_DEFAULT_SERVANT);
75 policies[3] =
76 root_poa->create_servant_retention_policy (
77 PortableServer::NON_RETAIN);
79 policies[4] =
80 root_poa->create_id_uniqueness_policy (
81 PortableServer::MULTIPLE_ID);
83 PortableServer::POA_var new_poa =
84 root_poa->create_POA ("test_server",
85 poa_manager.in (),
86 policies);
88 for (CORBA::ULong i = 0; i < policies.length (); ++i)
90 policies[i]->destroy ();
93 PortableServer::ObjectId_var id =
94 PortableServer::string_to_ObjectId ("server");
96 CORBA::Object_var object =
97 new_poa->create_reference_with_id (id.in (),
98 "IDL:bug_689_regression:1.0");
100 bug_689_regression_var bug_689_regression =
101 bug_689_regression::_unchecked_narrow (object.in ());
103 bug_689_regression_i impl (orb.in ());
104 new_poa->set_servant (&impl);
106 poa_manager->activate ();
108 CORBA::String_var ior = orb->object_to_string (bug_689_regression.in ());
110 // Output the IOR to the <ior_output_file>
111 FILE *output_file= ACE_OS::fopen (ior_output_file, ACE_TEXT ("w"));
112 if (output_file == 0)
113 ACE_ERROR_RETURN ((LM_ERROR,
114 ACE_TEXT ("Cannot open output file for writing IOR: %s\n"),
115 ior_output_file),
117 ACE_OS::fprintf (output_file, "%s", ior.in ());
118 ACE_OS::fclose (output_file);
120 orb->run ();
121 orb->destroy ();
123 catch (const CORBA::Exception& ex)
125 ex._tao_print_exception ("Exception caught:");
126 return 1;
129 return 0;