Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / ORT / server.cpp
blob194326767905bdfb508a20114937837968850d52
1 #include "ORT_test_i.h"
2 #include "ServerORBInitializer.h"
4 #include "tao/ORBInitializer_Registry.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/OS_NS_stdio.h"
9 const ACE_TCHAR *ior_output_file = 0;
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 ACE_DEBUG ((LM_DEBUG, "FILE ==== %s\n", ior_output_file));
23 break;
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "Usage: %s "
27 "-o <iorfile>"
28 "\n",
29 argv[0]),
30 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
39 try
41 PortableInterceptor::ORBInitializer_ptr tmp;
43 ACE_NEW_RETURN (tmp,
44 ServerORBInitializer,
45 -1); // No CORBA exceptions yet!
47 PortableInterceptor::ORBInitializer_var orb_initializer = tmp;
49 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
51 // Initialize the ORB.
52 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "ORT Test ORB");
54 if (parse_args (argc, argv) != 0)
55 return -1;
57 CORBA::Object_var obj =
58 orb->resolve_initial_references ("RootPOA");
60 // Narrow
61 PortableServer::POA_var root_poa =
62 PortableServer::POA::_narrow (obj.in ());
64 // Check for nil references
65 if (CORBA::is_nil (root_poa.in ()))
66 ACE_ERROR_RETURN ((LM_ERROR,
67 "Unable to obtain RootPOA reference.\n"),
68 -1);
70 // Get poa_manager reference
71 PortableServer::POAManager_var poa_manager =
72 root_poa->the_POAManager ();
74 // Activate it.
75 poa_manager->activate ();
77 CORBA::PolicyList policies (0);
78 policies.length (0);
80 // Lets create some POA's
81 PortableServer::POA_var first_poa =
82 root_poa->create_POA ("FIRST_POA",
83 poa_manager.in (),
84 policies);
86 PortableServer::POA_var second_poa =
87 first_poa->create_POA ("SECOND_POA",
88 poa_manager.in (),
89 policies);
91 PortableServer::POA_var third_poa =
92 second_poa->create_POA ("THIRD_POA",
93 poa_manager.in (),
94 policies);
96 PortableServer::POA_var fourth_poa =
97 third_poa->create_POA ("FOURTH_POA",
98 poa_manager.in (),
99 policies);
101 ORT_test_i ort_test_impl (orb.in ());
103 PortableServer::ObjectId_var oid =
104 fourth_poa->activate_object (&ort_test_impl);
106 obj = fourth_poa->servant_to_reference (&ort_test_impl);
108 // Convert the object reference to a string format.
109 CORBA::String_var ior =
110 orb->object_to_string (obj.in ());
112 // Dump it to a file.
113 if (ior_output_file != 0)
115 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
116 if (output_file == 0)
117 ACE_ERROR_RETURN ((LM_ERROR,
118 "Cannot open output file %s for writing "
119 "IOR: %C",
120 ior_output_file,
121 ior.in ()),
123 ACE_OS::fprintf (output_file, "%s", ior.in ());
124 ACE_OS::fclose (output_file);
127 orb->run ();
129 orb->destroy ();
131 catch (const CORBA::Exception& ex)
133 ex._tao_print_exception ("ORT test server:");
134 return -1;
137 return 0;