2 //=============================================================================
8 * @author Irfan Pyarali
10 //=============================================================================
13 #include "ace/streams.h"
14 #include "ace/SString.h"
16 #include "ace/OS_NS_stdio.h"
17 #include "ace/Get_Opt.h"
19 const ACE_TCHAR
*ior_1
= ACE_TEXT ("ior_1");
20 const ACE_TCHAR
*ior_2
= ACE_TEXT ("ior_2");
21 const ACE_TCHAR
*ior_3
= ACE_TEXT ("ior_3");
22 const ACE_TCHAR
*ior_4
= ACE_TEXT ("ior_4");
23 const ACE_TCHAR
*ior_5
= ACE_TEXT ("ior_5");
24 const ACE_TCHAR
*ior_6
= ACE_TEXT ("ior_6");
27 parse_args (int argc
, ACE_TCHAR
*argv
[])
29 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("a:b:c:d:e:f:"));
32 while ((c
= get_opts ()) != -1)
36 ior_1
= get_opts
.opt_arg ();
39 ior_2
= get_opts
.opt_arg ();
42 ior_3
= get_opts
.opt_arg ();
45 ior_4
= get_opts
.opt_arg ();
48 ior_5
= get_opts
.opt_arg ();
51 ior_6
= get_opts
.opt_arg ();
55 ACE_ERROR_RETURN ((LM_ERROR
,
67 // Indicates successful parsing of the command line
72 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
79 ACE_OS::strcpy (str
, "CORBA::ORB_init");
81 // Initialize the ORB first.
82 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
84 if (parse_args (argc
, argv
) != 0)
86 // Obtain the RootPOA.
87 CORBA::Object_var obj
=
88 orb
->resolve_initial_references ("RootPOA");
90 ACE_OS::strcpy (str
, "PortableServer::POA::_narrow");
92 // Get the POA_var object from Object_var.
93 PortableServer::POA_var root_poa
=
94 PortableServer::POA::_narrow (obj
.in ());
96 ACE_OS::strcpy (str
, "PortableServer::POA::the_POAManager");
97 // Get the POAManager of the RootPOA.
98 PortableServer::POAManager_var poa_manager
=
99 root_poa
->the_POAManager ();
101 // Policies for the firstPOA to be created.
102 CORBA::PolicyList
policies (2);
105 ACE_OS::strcpy (str
,"PortableServer::POA::create_lifespan_policy");
108 root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
);
110 ACE_OS::strcpy (str
, "PortableServer::POA::create_implicit_activation_policy");
111 // Implicit activation policy
113 root_poa
->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION
);
115 ACE_OS::strcpy (str
, "PortableServer::POA::create_POA");
116 // Create the firstPOA under the RootPOA.
117 ACE_CString name
= "firstPOA";
118 PortableServer::POA_var first_poa
=
119 root_poa
->create_POA (name
.c_str (),
123 ACE_OS::strcpy (str
,"PortableServer::POA::create_POA");
125 // Creation of POAs is over. Destroy the Policy objects.
126 for (CORBA::ULong i
= 0;
127 i
< policies
.length ();
130 CORBA::Policy_ptr policy
= policies
[i
];
135 A_i
a_impl (27, first_poa
.in ());
138 Outer_i::B_i
b_impl (28, first_poa
.in ());
141 Outer_i::Inner_i::C_i
c_impl (29, first_poa
.in ());
145 POA_A_tie
<Tie_i
> a_tie_impl (a_tie_i
, first_poa
.in ());
149 POA_Outer::B_tie
<Tie_i
> b_tie_impl (b_tie_i
, first_poa
.in ());
153 POA_Outer::Inner::C_tie
<Tie_i
> c_tie_impl (c_tie_i
, first_poa
.in ());
155 ACE_OS::strcpy (str
, "POA_A::_this");
156 // Get Object Reference for the a_impl object.
157 A_var a
= a_impl
._this ();
159 ACE_OS::strcpy (str
, "POA_Outer::B::_this");
160 // Get Object Reference for the b_impl object.
161 Outer::B_var b
= b_impl
._this ();
163 ACE_OS::strcpy (str
, "POA_Outer::Inner::C::_this");
164 // Get Object Reference for the c_impl object.
165 Outer::Inner::C_var c
= c_impl
._this ();
167 ACE_OS::strcpy (str
, "POA_A::_this");
168 // Get Object Reference for the a_tie_impl object.
169 A_var a_tie
= a_tie_impl
._this ();
171 ACE_OS::strcpy (str
, "POA_Outer::B::_this");
172 // Get Object Reference for the a_tie_impl object.
173 Outer::B_var b_tie
= b_tie_impl
._this ();
175 ACE_OS::strcpy (str
, "POA_Outer::C::_this");
176 // Get Object Reference for the c_tie_impl object.
177 Outer::Inner::C_var c_tie
= c_tie_impl
._this ();
179 ACE_OS::strcpy (str
, "CORBA::ORB::object_to_string");
180 // Stringyfy all the object references and print them out.
181 CORBA::String_var first_ior
=
182 orb
->object_to_string (a
.in ());
184 // Stringyfy all the object references and print them out.
185 CORBA::String_var second_ior
=
186 orb
->object_to_string (b
.in ());
188 // Stringyfy all the object references and print them out.
189 CORBA::String_var third_ior
=
190 orb
->object_to_string (c
.in ());
192 // Stringyfy all the object references and print them out.
193 CORBA::String_var forth_ior
=
194 orb
->object_to_string (a_tie
.in ());
196 FILE *output_file_1
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_1
), "w");
197 FILE *output_file_2
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_2
), "w");
198 FILE *output_file_3
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_3
), "w");
199 FILE *output_file_4
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_4
), "w");
203 ACE_OS::fprintf (output_file_1
,
206 ACE_OS::fclose (output_file_1
);
211 ACE_OS::fprintf (output_file_2
,
214 ACE_OS::fclose (output_file_2
);
219 ACE_OS::fprintf (output_file_3
,
222 ACE_OS::fclose (output_file_3
);
227 ACE_OS::fprintf (output_file_4
,
230 ACE_OS::fclose (output_file_4
);
233 // Stringyfy all the object references and print them out.
234 CORBA::String_var fifth_ior
=
235 orb
->object_to_string (b_tie
.in ());
237 // Stringyfy all the object references and print them out.
238 CORBA::String_var sixth_ior
=
239 orb
->object_to_string (c_tie
.in ());
241 FILE *output_file_5
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_5
), "w");
242 FILE *output_file_6
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_6
), "w");
246 ACE_OS::fprintf (output_file_5
,
249 ACE_OS::fclose (output_file_5
);
254 ACE_OS::fprintf (output_file_6
,
257 ACE_OS::fclose (output_file_6
);
260 poa_manager
->activate ();
264 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
266 root_poa
->destroy (1, 1);
270 catch (const CORBA::Exception
& ex
)
272 ex
._tao_print_exception (str
);