Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_3558_Regression / client.cpp
blobc2bb4e016cda0c648bcb4ccc46e3cf3ce13f51b3
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Task.h"
4 #include "ace/Barrier.h"
5 #include "ace/OS_NS_unistd.h"
6 #include "ace/OS_NS_strings.h"
8 #include "tao/ORB_Core.h"
9 #include "tao/Transport_Cache_Manager.h"
10 #include "tao/Thread_Lane_Resources.h"
12 const ACE_TCHAR *ior1 = ACE_TEXT ("file://server1.ior");
13 const ACE_TCHAR *ior2 = ACE_TEXT ("file://server2.ior");
15 int debug_level = 0;
17 CORBA::ORB_var orb;
19 ACE_Barrier barrier(2);
21 int
22 parse_args (int argc, ACE_TCHAR *argv[])
24 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("k:l:d:"));
25 int c;
27 while ((c = get_opts ()) != -1)
28 switch (c)
30 case 'k':
31 ior1 = get_opts.opt_arg ();
32 break;
34 case 'l':
35 ior2 = get_opts.opt_arg ();
36 break;
37 case 'd':
38 debug_level = ACE_OS::atoi( get_opts.opt_arg ());
39 break;
40 case '?':
41 default:
42 ACE_ERROR_RETURN ((LM_ERROR,
43 ACE_TEXT ("usage: %s ")
44 ACE_TEXT ("-k <ior1>\n")
45 ACE_TEXT ("-l <ior2>\n"),
46 ACE_TEXT ("-d <debug_level>\n"),
47 argv [0]),
48 -1);
50 // Indicates successful parsing of the command line
51 return 0;
55 static void *
56 test_server (void *arg)
58 intptr_t server_nr = reinterpret_cast<intptr_t> (arg);
60 ACE_TCHAR ior[256];
62 if (server_nr == 1)
63 ACE_OS::sprintf(ior, ACE_TEXT ("%s"), ior1);
64 else if (server_nr == 2)
66 ACE_OS::sprintf(ior, ACE_TEXT ("%s"), ior2);
67 ACE_DEBUG((LM_DEBUG,
68 ACE_TEXT("%D Expecting an exception for server %d\n"),
69 server_nr));
72 Test::Hello_var hello;
73 try
75 ACE_DEBUG ((LM_DEBUG,
76 ACE_TEXT ("%D Starting connection with server %d\n"),
77 server_nr));
79 CORBA::Object_var server = orb->string_to_object(ior);
81 hello = Test::Hello::_narrow(server.in ());
83 if (CORBA::is_nil (hello.in ()))
85 ACE_Thread::exit ();
86 ACE_ERROR ((LM_ERROR,
87 ACE_TEXT ("%D (%t) Nil Test::Hello reference <%s> for server %d\n"),
88 ior, server_nr));
89 return 0;
92 ACE_DEBUG((LM_DEBUG,
93 ACE_TEXT ("%D Transport data before invocation to server %d: current size: %d\n"),
94 server_nr,
95 orb->orb_core ()->lane_resources ().transport_cache ().current_size ()));
97 CORBA::String_var the_string = hello->get_string ();
99 ACE_DEBUG((LM_DEBUG,
100 ACE_TEXT ("%D Transport data after invocation to server %d: current size: %d\n"),
101 server_nr,
102 orb->orb_core ()->lane_resources ().transport_cache ().current_size ()));
104 ACE_DEBUG ((LM_DEBUG,
105 ACE_TEXT ("%D (%P|%t) - string <%C> returned from server %d\n"),
106 the_string.in (), server_nr));
108 catch (const CORBA::TRANSIENT &e)
110 if (server_nr == 2)
112 ACE_DEBUG((LM_DEBUG,
113 ACE_TEXT ("%D Expected exception for server %d: %C\n"),
114 server_nr,
115 e._info().c_str()));
117 else
119 ACE_ERROR((LM_ERROR,
120 ACE_TEXT ("%D Unexpected exception for server %d: %C\n"),
121 server_nr,
122 e._info().c_str()));
125 catch (...)
127 ACE_ERROR((LM_ERROR,
128 ACE_TEXT ("%D Unexpected exception for server %d\n"),
129 server_nr));
133 if (server_nr == 2)
134 barrier.wait();
136 ACE_DEBUG ((LM_DEBUG,
137 ACE_TEXT ("%D Shutdown server %d\n"),
138 server_nr));
140 if (!CORBA::is_nil(hello.in ()))
144 hello->shutdown ();
146 catch (...)
151 if (server_nr == 1)
152 barrier.wait();
154 ACE_DEBUG ((LM_DEBUG,
155 ACE_TEXT ("%D Thread ended for server %d\n"),
156 server_nr));
158 return 0;
162 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
164 int extra_argc = 4;
168 if (parse_args (argc, argv) != 0)
169 return 1;
171 if (debug_level > 0)
172 extra_argc = 6;
174 ACE_TCHAR **extra = 0;
175 ACE_NEW_RETURN (extra, ACE_TCHAR *[extra_argc], -1);
176 extra[0] = ACE::strnew (ACE_TEXT ("-ORBSvcConfDirective"));
177 extra[1] = ACE::strnew (ACE_TEXT ("static Resource_Factory \"-ORBConnectionCacheMax 1 -ORBConnectionCachePurgePercentage 100\""));
178 extra[2] = ACE::strnew (ACE_TEXT ("-ORBSvcConfDirective"));
179 extra[3] = ACE::strnew (ACE_TEXT ("static Client_Strategy_Factory \"-ORBTransportMuxStrategy EXCLUSIVE\""));
180 if (debug_level > 0)
182 extra[4] = ACE::strnew (ACE_TEXT ("-ORBdebuglevel"));
183 extra[5] = ACE::strnew (ACE_TEXT ("10"));
186 ACE_TCHAR **largv = new ACE_TCHAR *[argc+extra_argc];
187 for (int i = 0; i < argc; i++)
188 largv[i] = argv[i];
190 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%D client adding args:\n")));
191 for (int i = 0; i < extra_argc; i++)
193 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\t\t%s\n"), extra[i]));
194 largv[argc+i] = extra[i];
197 argc += extra_argc;
199 orb = CORBA::ORB_init (argc, largv);
201 if (ACE_Thread_Manager::instance ()->spawn
202 ((ACE_THR_FUNC) test_server,
203 (void *) 1,
204 THR_NEW_LWP | THR_JOINABLE,
205 0) == -1)
207 ACE_ERROR_RETURN ((LM_ERROR,
208 ACE_TEXT ("Error spawning thread 1\n")),
212 ACE_OS::sleep(2);
214 if (ACE_Thread_Manager::instance ()->spawn
215 ((ACE_THR_FUNC) test_server,
216 (void *) 2,
217 THR_NEW_LWP | THR_JOINABLE,
218 0) == -1)
220 ACE_ERROR_RETURN ((LM_ERROR,
221 ACE_TEXT ("Error spawning thread 2")),
225 ACE_Thread_Manager::instance()->wait ();
227 ACE_DEBUG((LM_DEBUG,
228 ACE_TEXT ("%D Transport data when done: current size: %d\n"),
229 orb->orb_core ()->lane_resources ().transport_cache ().current_size ()));
231 orb->destroy ();
232 for (int i = 0; i < extra_argc; i++)
233 ACE::strdelete (extra[i]);
234 delete [] extra;
235 delete [] largv;
237 catch (const CORBA::Exception& ex)
239 ex._tao_print_exception ("Exception caught:");
240 return 1;
243 return 0;