Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Servant_To_Reference_Test / server.cpp
blob2fcf8fd65e59c7c84f3fbc0bed0dcfc8272cc1e5
1 #include "Test_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/Task.h"
6 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
8 class MT_Task : public ACE_Task_Base
10 public:
11 MT_Task (PortableServer::POA_ptr p,
12 PortableServer::Servant one,
13 PortableServer::Servant two,
14 PortableServer::Servant three)
15 : p_ (PortableServer::POA::_duplicate (p))
16 , one_ (one)
17 , two_ (two)
18 , three_ (three)
22 int svc ();
24 private:
25 PortableServer::POA_var p_;
26 PortableServer::Servant one_;
27 PortableServer::Servant two_;
28 PortableServer::Servant three_;
31 int
32 MT_Task::svc ()
34 try
36 for (CORBA::Long i = 0;
37 i != 2000;
38 ++i)
40 CORBA::Object_var one_ref =
41 this->p_->servant_to_reference (this->one_);
43 CORBA::Object_var two_ref =
44 this->p_->servant_to_reference (this->two_);
46 CORBA::Object_var three_ref =
47 this->p_->servant_to_reference (this->three_);
50 catch (const CORBA::Exception& ex)
52 ex._tao_print_exception ("(%P|%t) Caugh exception\n");
55 return 0;
58 int
59 parse_args (int argc, ACE_TCHAR *argv[])
61 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
62 int c;
64 while ((c = get_opts ()) != -1)
65 switch (c)
67 case 'o':
68 ior_output_file = get_opts.opt_arg ();
69 break;
71 case '?':
72 default:
73 ACE_ERROR_RETURN ((LM_ERROR,
74 "usage: %s "
75 "-o <iorfile>"
76 "\n",
77 argv [0]),
78 -1);
80 // Indicates successful parsing of the command line
81 return 0;
84 int
85 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
87 try
89 CORBA::ORB_var orb =
90 CORBA::ORB_init (argc, argv);
92 CORBA::Object_var poa_object =
93 orb->resolve_initial_references("RootPOA");
95 PortableServer::POA_var root_poa =
96 PortableServer::POA::_narrow (poa_object.in ());
98 if (CORBA::is_nil (root_poa.in ()))
99 ACE_ERROR_RETURN ((LM_ERROR,
100 " (%P|%t) Panic: nil RootPOA\n"),
103 PortableServer::POAManager_var poa_manager =
104 root_poa->the_POAManager ();
106 if (parse_args (argc, argv) != 0)
107 return 1;
109 One_Impl *one_impl = 0;
110 ACE_NEW_RETURN (one_impl,
111 One_Impl (orb.in ()),
113 Two_Impl *two_impl = 0;
114 ACE_NEW_RETURN (two_impl,
115 Two_Impl (orb.in ()),
118 Three_Impl *three_impl = 0;
119 ACE_NEW_RETURN (three_impl,
120 Three_Impl (orb.in ()),
123 PortableServer::ServantBase_var owner_transfer1 (one_impl);
124 PortableServer::ServantBase_var owner_transfer2 (two_impl);
125 PortableServer::ServantBase_var owner_transfer3 (three_impl);
127 CORBA::PolicyList policies; // Empty policy list.
129 PortableServer::POA_var first_poa =
130 root_poa->create_POA ("first POA",
131 poa_manager.in (),
132 policies);
134 PortableServer::ObjectId_var oid1 =
135 first_poa->activate_object (one_impl);
137 PortableServer::ObjectId_var oid2 =
138 first_poa->activate_object (two_impl);
140 PortableServer::ObjectId_var oid3 =
141 first_poa->activate_object (three_impl);
143 // Output the IOR to the <ior_output_file>
144 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
145 if (output_file == 0)
146 ACE_ERROR_RETURN ((LM_ERROR,
147 "Cannot open output file for writing IOR: %s\n",
148 ior_output_file),
150 ACE_OS::fprintf (output_file, "%s", "started");
151 ACE_OS::fclose (output_file);
153 MT_Task task (first_poa.in (),
154 one_impl,
155 two_impl,
156 three_impl);
158 if (task.activate (THR_NEW_LWP | THR_JOINABLE,
159 32) != 0)
160 ACE_ERROR_RETURN ((LM_ERROR,
161 "Cannot activate threads\n"),
164 task.thr_mgr ()->wait ();
166 poa_manager->activate ();
168 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - test finished\n"));
170 root_poa->destroy (true, true);
172 orb->destroy ();
174 catch (const CORBA::Exception& ex)
176 ex._tao_print_exception ("Exception caught:");
177 return 1;
180 return 0;