2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
6 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
8 class MT_Task
: public ACE_Task_Base
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
))
25 PortableServer::POA_var p_
;
26 PortableServer::Servant one_
;
27 PortableServer::Servant two_
;
28 PortableServer::Servant three_
;
36 for (CORBA::Long i
= 0;
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");
59 parse_args (int argc
, ACE_TCHAR
*argv
[])
61 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
64 while ((c
= get_opts ()) != -1)
68 ior_output_file
= get_opts
.opt_arg ();
73 ACE_ERROR_RETURN ((LM_ERROR
,
80 // Indicates successful parsing of the command line
85 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
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)
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",
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",
150 ACE_OS::fprintf (output_file
, "%s", "started");
151 ACE_OS::fclose (output_file
);
153 MT_Task
task (first_poa
.in (),
158 if (task
.activate (THR_NEW_LWP
| THR_JOINABLE
,
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);
174 catch (const CORBA::Exception
& ex
)
176 ex
._tao_print_exception ("Exception caught:");