Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / POA / TIE / server.cpp
blobe67aedc672784d7ac884f1d7062a311a36973708
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[])
74 char str[256];
76 try
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)
84 return 1;
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);
102 policies.length (2);
104 ACE_OS::strcpy (str,"PortableServer::POA::create_lifespan_policy");
105 // Lifespan policy
106 policies[0] =
107 root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
109 ACE_OS::strcpy (str, "PortableServer::POA::create_implicit_activation_policy");
110 // Implicit activation policy
111 policies[1] =
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 (),
119 poa_manager.in (),
120 policies);
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 ();
127 ++i)
129 CORBA::Policy_ptr policy = policies[i];
130 policy->destroy ();
133 // Create A_i
134 A_i a_impl (27, first_poa.in ());
136 // Create B_i
137 Outer_i::B_i b_impl (28, first_poa.in ());
139 // Create C_i
140 Outer_i::Inner_i::C_i c_impl (29, first_poa.in ());
142 // Create A tie
143 Tie_i a_tie_i (30);
144 POA_A_tie <Tie_i> a_tie_impl (a_tie_i, first_poa.in ());
146 // Create B tie
147 Tie_i b_tie_i (31);
148 POA_Outer::B_tie <Tie_i> b_tie_impl (b_tie_i, first_poa.in ());
150 // Create C tie
151 Tie_i c_tie_i (32);
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");
200 if (output_file_1)
202 ACE_OS::fprintf (output_file_1,
203 "%s",
204 first_ior.in ());
205 ACE_OS::fclose (output_file_1);
208 if (output_file_2)
210 ACE_OS::fprintf (output_file_2,
211 "%s",
212 second_ior.in ());
213 ACE_OS::fclose (output_file_2);
216 if (output_file_3)
218 ACE_OS::fprintf (output_file_3,
219 "%s",
220 third_ior.in ());
221 ACE_OS::fclose (output_file_3);
224 if (output_file_4)
226 ACE_OS::fprintf (output_file_4,
227 "%s",
228 forth_ior.in ());
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");
243 if (output_file_5)
245 ACE_OS::fprintf (output_file_5,
246 "%s",
247 fifth_ior.in ());
248 ACE_OS::fclose (output_file_5);
251 if (output_file_6)
253 ACE_OS::fprintf (output_file_6,
254 "%s",
255 sixth_ior.in ());
256 ACE_OS::fclose (output_file_6);
259 poa_manager->activate ();
261 orb->run ();
263 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
265 root_poa->destroy (true, true);
267 orb->destroy ();
269 catch (const CORBA::Exception& ex)
271 ex._tao_print_exception (str);
272 return -1;
275 return 0;