Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_3768_Regression / server.cpp
blob4c4913109f1644828ceb262e342c39896b5b41ff
1 #include "TestServer.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/Task.h"
6 const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior");
8 class Worker : public ACE_Task_Base
10 public:
11 Worker(CORBA::ORB_ptr orb) : orb_(CORBA::ORB::_duplicate(orb))
15 int svc()
17 orb_->run();
18 return 0;
21 private:
22 CORBA::ORB_var orb_;
25 int
26 parse_args (int argc, ACE_TCHAR *argv[])
28 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
29 int c;
31 while ((c = get_opts ()) != -1)
32 switch (c)
34 case 'o':
35 ior_output_file = get_opts.opt_arg ();
36 break;
38 case '?':
39 default:
40 ACE_ERROR_RETURN ((LM_ERROR,
41 "usage: %s "
42 "-o <iorfile>"
43 "\n",
44 argv [0]),
45 -1);
47 // Indicates sucessful parsing of the command line
48 return 0;
51 int
52 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
54 try
56 CORBA::ORB_var orb =
57 CORBA::ORB_init (argc, argv);
59 CORBA::Object_var poa_object =
60 orb->resolve_initial_references("RootPOA");
62 PortableServer::POA_var root_poa =
63 PortableServer::POA::_narrow (poa_object.in ());
65 if (CORBA::is_nil (root_poa.in ()))
66 ACE_ERROR_RETURN ((LM_ERROR,
67 " (%P|%t) Panic: nil RootPOA\n"),
68 1);
70 PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
72 if (parse_args (argc, argv) != 0)
73 return 1;
75 TestServer *test_impl = 0;
76 ACE_NEW_RETURN (test_impl,
77 TestServer (),
78 1);
79 PortableServer::ServantBase_var owner_transfer(test_impl);
81 PortableServer::ObjectId_var id =
82 root_poa->activate_object (test_impl);
84 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
86 Test::TestServer_var test = Test::TestServer::_narrow (object.in ());
88 CORBA::String_var ior = orb->object_to_string (test.in ());
90 // Output the IOR to the <ior_output_file>
91 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
92 if (output_file == 0)
93 ACE_ERROR_RETURN ((LM_ERROR,
94 "Cannot open output file for writing IOR: %s\n",
95 ior_output_file),
96 1);
97 ACE_OS::fprintf (output_file, "%s", ior.in ());
98 ACE_OS::fclose (output_file);
100 poa_manager->activate ();
102 // Run a CORBA worker thread
103 Worker work (orb.in());
104 work.activate (THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED, 1);
105 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - waiting for client to call\n"));
106 ACE_OS::sleep (10);
107 if (test_impl->got_callback() == false) {
108 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - client did not make call\n"));
109 return 1;
112 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - making repeated calls to client\n"));
113 for (int i = 0; i < 10; i++)
115 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - calling client attempt %d\n", i));
116 test_impl->make_callback();
119 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - stopping client\n"));
120 test_impl->shutdown_client();
122 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - test completed\n"));
124 orb->shutdown (); // shutdown our ORB
126 work.wait (); // wait for the worker to finish
128 root_poa->destroy (true, true);
130 orb->destroy ();
132 catch (const CORBA::Exception& ex)
134 ex._tao_print_exception ("Exception caught:");
135 return 1;
138 return 0;