More tests update
[ACE_TAO.git] / TAO / tests / POA / TIE / server.cpp
blob2021a0222474e829e0e4c922c5cd71f842ea201c
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * In this example,
8 * @author Irfan Pyarali
9 */
10 //=============================================================================
13 #include "ace/streams.h"
14 #include "ace/SString.h"
15 #include "test_i.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");
26 int
27 parse_args (int argc, ACE_TCHAR *argv[])
29 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("a:b:c:d:e:f:"));
30 int c;
32 while ((c = get_opts ()) != -1)
33 switch (c)
35 case 'a':
36 ior_1 = get_opts.opt_arg ();
37 break;
38 case 'b':
39 ior_2 = get_opts.opt_arg ();
40 break;
41 case 'c':
42 ior_3 = get_opts.opt_arg ();
43 break;
44 case 'd':
45 ior_4 = get_opts.opt_arg ();
46 break;
47 case 'e':
48 ior_5 = get_opts.opt_arg ();
49 break;
50 case 'f':
51 ior_6 = get_opts.opt_arg ();
52 break;
53 case '?':
54 default:
55 ACE_ERROR_RETURN ((LM_ERROR,
56 "usage: %s "
57 "-a <ior_1> "
58 "-b <ior_2> "
59 "-c <ior_3> "
60 "-d <ior_4> "
61 "-e <ior_5> "
62 "-f <ior_6> "
63 "\n",
64 argv [0]),
65 -1);
67 // Indicates successful parsing of the command line
68 return 0;
71 int
72 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
75 char str[256];
77 try
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)
85 return 1;
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);
103 policies.length (2);
105 ACE_OS::strcpy (str,"PortableServer::POA::create_lifespan_policy");
106 // Lifespan policy
107 policies[0] =
108 root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
110 ACE_OS::strcpy (str, "PortableServer::POA::create_implicit_activation_policy");
111 // Implicit activation policy
112 policies[1] =
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 (),
120 poa_manager.in (),
121 policies);
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 ();
128 ++i)
130 CORBA::Policy_ptr policy = policies[i];
131 policy->destroy ();
134 // Create A_i
135 A_i a_impl (27, first_poa.in ());
137 // Create B_i
138 Outer_i::B_i b_impl (28, first_poa.in ());
140 // Create C_i
141 Outer_i::Inner_i::C_i c_impl (29, first_poa.in ());
143 // Create A tie
144 Tie_i a_tie_i (30);
145 POA_A_tie <Tie_i> a_tie_impl (a_tie_i, first_poa.in ());
147 // Create B tie
148 Tie_i b_tie_i (31);
149 POA_Outer::B_tie <Tie_i> b_tie_impl (b_tie_i, first_poa.in ());
151 // Create C tie
152 Tie_i c_tie_i (32);
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");
201 if (output_file_1)
203 ACE_OS::fprintf (output_file_1,
204 "%s",
205 first_ior.in ());
206 ACE_OS::fclose (output_file_1);
209 if (output_file_2)
211 ACE_OS::fprintf (output_file_2,
212 "%s",
213 second_ior.in ());
214 ACE_OS::fclose (output_file_2);
217 if (output_file_3)
219 ACE_OS::fprintf (output_file_3,
220 "%s",
221 third_ior.in ());
222 ACE_OS::fclose (output_file_3);
225 if (output_file_4)
227 ACE_OS::fprintf (output_file_4,
228 "%s",
229 forth_ior.in ());
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");
244 if (output_file_5)
246 ACE_OS::fprintf (output_file_5,
247 "%s",
248 fifth_ior.in ());
249 ACE_OS::fclose (output_file_5);
252 if (output_file_6)
254 ACE_OS::fprintf (output_file_6,
255 "%s",
256 sixth_ior.in ());
257 ACE_OS::fclose (output_file_6);
260 poa_manager->activate ();
262 orb->run ();
264 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
266 root_poa->destroy (1, 1);
268 orb->destroy ();
270 catch (const CORBA::Exception& ex)
272 ex._tao_print_exception (str);
273 return -1;
276 return 0;