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_
;
37 for (CORBA::Long i
= 0;
41 CORBA::Object_var one_ref
=
42 this->p_
->servant_to_reference (this->one_
);
44 CORBA::Object_var two_ref
=
45 this->p_
->servant_to_reference (this->two_
);
47 CORBA::Object_var three_ref
=
48 this->p_
->servant_to_reference (this->three_
);
51 catch (const CORBA::Exception
& ex
)
53 ex
._tao_print_exception ("(%P|%t) Caugh exception\n");
60 parse_args (int argc
, ACE_TCHAR
*argv
[])
62 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
65 while ((c
= get_opts ()) != -1)
69 ior_output_file
= get_opts
.opt_arg ();
74 ACE_ERROR_RETURN ((LM_ERROR
,
81 // Indicates successful parsing of the command line
86 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
91 CORBA::ORB_init (argc
, argv
);
93 CORBA::Object_var poa_object
=
94 orb
->resolve_initial_references("RootPOA");
96 PortableServer::POA_var root_poa
=
97 PortableServer::POA::_narrow (poa_object
.in ());
99 if (CORBA::is_nil (root_poa
.in ()))
100 ACE_ERROR_RETURN ((LM_ERROR
,
101 " (%P|%t) Panic: nil RootPOA\n"),
104 PortableServer::POAManager_var poa_manager
=
105 root_poa
->the_POAManager ();
107 if (parse_args (argc
, argv
) != 0)
110 One_Impl
*one_impl
= 0;
111 ACE_NEW_RETURN (one_impl
,
112 One_Impl (orb
.in ()),
114 Two_Impl
*two_impl
= 0;
115 ACE_NEW_RETURN (two_impl
,
116 Two_Impl (orb
.in ()),
119 Three_Impl
*three_impl
= 0;
120 ACE_NEW_RETURN (three_impl
,
121 Three_Impl (orb
.in ()),
124 PortableServer::ServantBase_var
owner_transfer1 (one_impl
);
125 PortableServer::ServantBase_var
owner_transfer2 (two_impl
);
126 PortableServer::ServantBase_var
owner_transfer3 (three_impl
);
128 CORBA::PolicyList policies
; // Empty policy list.
130 PortableServer::POA_var first_poa
=
131 root_poa
->create_POA ("first POA",
135 PortableServer::ObjectId_var oid1
=
136 first_poa
->activate_object (one_impl
);
138 PortableServer::ObjectId_var oid2
=
139 first_poa
->activate_object (two_impl
);
141 PortableServer::ObjectId_var oid3
=
142 first_poa
->activate_object (three_impl
);
144 // Output the IOR to the <ior_output_file>
145 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
146 if (output_file
== 0)
147 ACE_ERROR_RETURN ((LM_ERROR
,
148 "Cannot open output file for writing IOR: %s\n",
151 ACE_OS::fprintf (output_file
, "%s", "started");
152 ACE_OS::fclose (output_file
);
154 MT_Task
task (first_poa
.in (),
159 if (task
.activate (THR_NEW_LWP
| THR_JOINABLE
,
161 ACE_ERROR_RETURN ((LM_ERROR
,
162 "Cannot activate threads\n"),
165 task
.thr_mgr ()->wait ();
167 poa_manager
->activate ();
169 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - test finished\n"));
171 root_poa
->destroy (1, 1);
175 catch (const CORBA::Exception
& ex
)
177 ex
._tao_print_exception ("Exception caught:");