Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_2683_Regression / server.cpp
blob5b508e5c809ccb90e6fdffb8049b794d05fb4a41
1 #include "test_i.h"
2 #include "tao/IORTable/IORTable.h"
3 #include "ace/OS_NS_strings.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "ace/Thread_Manager.h"
6 #include "ace/Task.h"
7 #include "ace/Get_Opt.h"
9 const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.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 <iorfile>"
29 "\n",
30 argv [0]),
31 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 class ORB_Run_Task : public ACE_Task_Base
39 private:
40 CORBA::ORB_var orb_;
42 public:
43 ORB_Run_Task (CORBA::ORB_ptr orb)
44 : orb_(CORBA::ORB::_duplicate(orb))
48 int svc ()
50 try
52 this->orb_->run();
54 catch (const CORBA::Exception &ex)
56 ACE_DEBUG ((LM_DEBUG,
57 "(%P|%t) server orb run thread caught %s\n",ex._name()));
59 return 0;
63 int
64 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
66 try
68 bool endpoint_found = false;
69 for (int i = 0; i < argc; i++)
71 if ((ACE_OS::strcasecmp (argv[i],ACE_TEXT("-ORBEndpoint")) == 0) ||
72 (ACE_OS::strcasecmp (argv[i],ACE_TEXT("-ORBListenEndpoints")) == 0))
73 endpoint_found = 1;
76 if (!endpoint_found)
77 ACE_ERROR_RETURN ((LM_ERROR,
78 "ERROR: %s requires an explicit endpoint!\n",
79 argv[0]), 1);
80 ACE_DEBUG ((LM_DEBUG,"(%P|%t) server started\n"));
81 CORBA::ORB_var orb =
82 CORBA::ORB_init (argc, argv);
84 if (parse_args (argc, argv) != 0)
85 return 1;
87 CORBA::Object_var obj =
88 orb->resolve_initial_references("RootPOA");
90 PortableServer::POA_var root_poa =
91 PortableServer::POA::_narrow (obj.in ());
93 if (CORBA::is_nil (root_poa.in ()))
94 ACE_ERROR_RETURN ((LM_ERROR,
95 " (%P|%t) Panic: nil RootPOA\n"),
96 1);
98 obj = orb->resolve_initial_references("IORTable");
100 IORTable::Table_var iortable =
101 IORTable::Table::_narrow(obj.in());
103 if (CORBA::is_nil (root_poa.in ()))
104 ACE_ERROR_RETURN ((LM_ERROR,
105 " (%P|%t) Panic: nil IORTable\n"),
108 ORB_Killer killer (orb.in());
109 test_i *servant;
110 ACE_NEW_RETURN (servant,
111 test_i (&killer),
113 PortableServer::ServantBase_var owner_transfer(servant);
115 PortableServer::ObjectId_var id =
116 root_poa->activate_object (servant);
118 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
120 Test::IORTable_Shutdown_Race_var target =
121 Test::IORTable_Shutdown_Race::_narrow (object.in ());
123 CORBA::String_var ior =
124 orb->object_to_string (target.in ());
126 iortable->bind ("Racer",ior.in());
128 PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
130 poa_manager->activate ();
132 ACE_DEBUG ((LM_DEBUG,
133 "(%P|%t) server - activating ORB threads\n"));
135 ORB_Run_Task ort (orb.in());
136 ort.activate (THR_NEW_LWP | THR_JOINABLE, 3);
137 ACE_DEBUG ((LM_DEBUG,"(%P|%t) server - ORB running\n"));
140 // Output the IOR to the <ior_output_file> - to signal readiness.
141 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
142 if (output_file == 0)
143 ACE_ERROR_RETURN ((LM_ERROR,
144 "Cannot open output file for writing IOR: %s\n",
145 ior_output_file),
147 ACE_OS::fprintf (output_file, "%s", ior.in ());
148 ACE_OS::fclose (output_file);
150 ACE_Thread_Manager *tm = ort.thr_mgr();
151 tm->wait();
152 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
154 orb->destroy ();
156 catch (const CORBA::Exception &ex)
158 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server main - caught %s\n",ex._name()));
159 return 1;
162 return 0;