Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Bug_3582 / server.cpp
blob11f45a914e79160930b3dc760344e7e497ddf8bb
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
3 #include "test_i.h"
4 #include "ace/OS_NS_stdio.h"
6 const ACE_TCHAR *ior_file = 0;
7 int number = 0;
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:c:n:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_file = get_opts.opt_arg ();
20 break;
21 case 'n':
22 number = ACE_OS::atoi (get_opts.opt_arg ());
23 break;
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "Usage: %s "
27 "-o <IOR> "
28 "-n <server number>\n",
29 argv[0]),
30 -1);
33 return 0;
36 int
37 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
39 try
41 CORBA::ORB_var orb =
42 CORBA::ORB_init (argc, argv, "Server ORB");
44 CORBA::Object_var poa_object =
45 orb->resolve_initial_references ("RootPOA");
47 if (CORBA::is_nil (poa_object.in ()))
48 ACE_ERROR_RETURN ((LM_ERROR,
49 " (%P|%t) Unable to initialize the POA.\n"),
50 1);
52 PortableServer::POA_var root_poa =
53 PortableServer::POA::_narrow (poa_object.in ());
55 PortableServer::POAManager_var poa_manager =
56 root_poa->the_POAManager ();
58 if (::parse_args (argc, argv) != 0)
59 return -1;
61 test_i *test_impl;
62 ACE_NEW_RETURN (test_impl, test_i (number, orb.in ()), 1);
63 PortableServer::ServantBase_var owner_transfer (test_impl);
65 PortableServer::ObjectId_var id =
66 root_poa->activate_object (test_impl);
68 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
70 RTTest::test_var test =
71 RTTest::test::_narrow (object.in ());
73 CORBA::String_var ior =
74 orb->object_to_string (test.in ());
76 FILE *output_file= ACE_OS::fopen (ior_file, "w");
77 if (output_file == 0)
78 ACE_ERROR_RETURN ((LM_ERROR,
79 "Cannot open output file <%s> for writing "
80 "IOR: %s",
81 ior.in ()),
82 1);
83 ACE_OS::fprintf (output_file, "%s", ior.in ());
84 ACE_OS::fclose (output_file);
86 poa_manager->activate ();
88 // Run the ORB event loop.
89 orb->run ();
91 root_poa->destroy (true, true);
93 orb->destroy ();
95 ACE_DEBUG ((LM_DEBUG, "Event loop finished.\n"));
97 catch (const CORBA::Exception& ex)
99 ex._tao_print_exception ("Caught exception:");
100 return -1;
103 return 0;