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
[])
78 ACE_OS::strcpy (str
, "CORBA::ORB_init");
80 // Initialize the ORB first.
81 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
83 if (parse_args (argc
, argv
) != 0)
85 // Obtain the RootPOA.
86 CORBA::Object_var obj
=
87 orb
->resolve_initial_references ("RootPOA");
89 ACE_OS::strcpy (str
, "PortableServer::POA::_narrow");
91 // Get the POA_var object from Object_var.
92 PortableServer::POA_var root_poa
=
93 PortableServer::POA::_narrow (obj
.in ());
95 ACE_OS::strcpy (str
, "PortableServer::POA::the_POAManager");
96 // Get the POAManager of the RootPOA.
97 PortableServer::POAManager_var poa_manager
=
98 root_poa
->the_POAManager ();
100 // Policies for the firstPOA to be created.
101 CORBA::PolicyList
policies (2);
104 ACE_OS::strcpy (str
,"PortableServer::POA::create_lifespan_policy");
107 root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
);
109 ACE_OS::strcpy (str
, "PortableServer::POA::create_implicit_activation_policy");
110 // Implicit activation policy
112 root_poa
->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION
);
114 ACE_OS::strcpy (str
, "PortableServer::POA::create_POA");
115 // Create the firstPOA under the RootPOA.
116 ACE_CString name
= "firstPOA";
117 PortableServer::POA_var first_poa
=
118 root_poa
->create_POA (name
.c_str (),
122 ACE_OS::strcpy (str
,"PortableServer::POA::create_POA");
124 // Creation of POAs is over. Destroy the Policy objects.
125 for (CORBA::ULong i
= 0;
126 i
< policies
.length ();
129 CORBA::Policy_ptr policy
= policies
[i
];
134 A_i
a_impl (27, first_poa
.in ());
137 Outer_i::B_i
b_impl (28, first_poa
.in ());
140 Outer_i::Inner_i::C_i
c_impl (29, first_poa
.in ());
144 POA_A_tie
<Tie_i
> a_tie_impl (a_tie_i
, first_poa
.in ());
148 POA_Outer::B_tie
<Tie_i
> b_tie_impl (b_tie_i
, first_poa
.in ());
152 POA_Outer::Inner::C_tie
<Tie_i
> c_tie_impl (c_tie_i
, first_poa
.in ());
154 ACE_OS::strcpy (str
, "POA_A::_this");
155 // Get Object Reference for the a_impl object.
156 A_var a
= a_impl
._this ();
158 ACE_OS::strcpy (str
, "POA_Outer::B::_this");
159 // Get Object Reference for the b_impl object.
160 Outer::B_var b
= b_impl
._this ();
162 ACE_OS::strcpy (str
, "POA_Outer::Inner::C::_this");
163 // Get Object Reference for the c_impl object.
164 Outer::Inner::C_var c
= c_impl
._this ();
166 ACE_OS::strcpy (str
, "POA_A::_this");
167 // Get Object Reference for the a_tie_impl object.
168 A_var a_tie
= a_tie_impl
._this ();
170 ACE_OS::strcpy (str
, "POA_Outer::B::_this");
171 // Get Object Reference for the a_tie_impl object.
172 Outer::B_var b_tie
= b_tie_impl
._this ();
174 ACE_OS::strcpy (str
, "POA_Outer::C::_this");
175 // Get Object Reference for the c_tie_impl object.
176 Outer::Inner::C_var c_tie
= c_tie_impl
._this ();
178 ACE_OS::strcpy (str
, "CORBA::ORB::object_to_string");
179 // Stringyfy all the object references and print them out.
180 CORBA::String_var first_ior
=
181 orb
->object_to_string (a
.in ());
183 // Stringyfy all the object references and print them out.
184 CORBA::String_var second_ior
=
185 orb
->object_to_string (b
.in ());
187 // Stringyfy all the object references and print them out.
188 CORBA::String_var third_ior
=
189 orb
->object_to_string (c
.in ());
191 // Stringyfy all the object references and print them out.
192 CORBA::String_var forth_ior
=
193 orb
->object_to_string (a_tie
.in ());
195 FILE *output_file_1
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_1
), "w");
196 FILE *output_file_2
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_2
), "w");
197 FILE *output_file_3
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_3
), "w");
198 FILE *output_file_4
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_4
), "w");
202 ACE_OS::fprintf (output_file_1
,
205 ACE_OS::fclose (output_file_1
);
210 ACE_OS::fprintf (output_file_2
,
213 ACE_OS::fclose (output_file_2
);
218 ACE_OS::fprintf (output_file_3
,
221 ACE_OS::fclose (output_file_3
);
226 ACE_OS::fprintf (output_file_4
,
229 ACE_OS::fclose (output_file_4
);
232 // Stringyfy all the object references and print them out.
233 CORBA::String_var fifth_ior
=
234 orb
->object_to_string (b_tie
.in ());
236 // Stringyfy all the object references and print them out.
237 CORBA::String_var sixth_ior
=
238 orb
->object_to_string (c_tie
.in ());
240 FILE *output_file_5
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_5
), "w");
241 FILE *output_file_6
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_6
), "w");
245 ACE_OS::fprintf (output_file_5
,
248 ACE_OS::fclose (output_file_5
);
253 ACE_OS::fprintf (output_file_6
,
256 ACE_OS::fclose (output_file_6
);
259 poa_manager
->activate ();
263 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
265 root_poa
->destroy (true, true);
269 catch (const CORBA::Exception
& ex
)
271 ex
._tao_print_exception (str
);