Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / OBV / Supports / server.cpp
blob764f628537af63112e86fbb0207a4a0dff47ae9c
1 #include "Supports_Test_impl.h"
2 #include "tao/Strategies/advanced_resource.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior");
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'o':
17 ior_output_file = get_opts.opt_arg ();
18 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-o <iorfile>"
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 int
34 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
36 try
38 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
40 if (parse_args (argc, argv) != 0)
41 return 1;
43 CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA");
45 PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ());
47 if (CORBA::is_nil (root_poa.in ()))
48 ACE_ERROR_RETURN ((LM_ERROR,
49 " (%P|%t) Nil RootPOA\n"),
50 1);
52 PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
54 /* Create, register factories */
56 Supports_Test::Node_init * node_factory = 0;
58 ACE_NEW_RETURN (node_factory, node_init_impl, 1);
60 CORBA::ValueFactory returned_factory = orb->register_value_factory (
61 node_factory->tao_repository_id (),
62 node_factory);
64 ACE_ASSERT (returned_factory == 0);
66 node_factory->_remove_ref ();
68 Supports_Test::vt_graph_init * vt_graph_factory = 0;
70 ACE_NEW_RETURN (vt_graph_factory, vt_graph_init_impl, 1);
72 returned_factory = orb->register_value_factory (
73 vt_graph_factory->tao_repository_id (),
74 vt_graph_factory);
76 ACE_ASSERT (returned_factory == 0);
78 vt_graph_factory->_remove_ref ();
80 /* create and activate test servant */
82 test_impl * a_test_impl;
84 ACE_NEW_RETURN (a_test_impl, test_impl (orb.in ()), 1);
86 PortableServer::ServantBase_var owner_transfer = a_test_impl;
88 PortableServer::ObjectId_var id =
89 root_poa->activate_object (a_test_impl);
91 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
93 Supports_Test::test_var a_test = Supports_Test::test::_narrow (object.in ());
95 CORBA::String_var ior = orb->object_to_string (a_test.in ());
97 FILE * output_file = ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_output_file), "w");
99 if (output_file == 0)
100 ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", ior_output_file), 1);
102 ACE_OS::fprintf (output_file, "%s", ior.in ());
104 ACE_OS::fclose (output_file);
106 poa_manager->activate ();
108 orb->run ();
110 root_poa->destroy (0, 0);
112 orb->destroy ();
114 ACE_DEBUG ((LM_DEBUG, "Server (%P.%t) completed test successfully\n"));
116 catch (const CORBA::Exception& ex)
118 ex._tao_print_exception ("Exception caught:");
119 return 1;
122 return 0;