Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Bug_1476_Regression / client.cpp
blob0ceddb42d74941d8a3a9f8e13b366548a0343d71
1 #include "Client_Task.h"
2 #include "Server_Task.h"
3 #include "ace/Get_Opt.h"
4 #include "tao/Messaging/Messaging.h"
5 #include "tao/Transport_Cache_Manager.h"
6 #include "tao/Transport.h"
7 #include "tao/ORB_Core.h"
8 #include "tao/Thread_Lane_Resources.h"
9 #include "tao/PortableServer/PortableServer.h"
10 #include "tao/AnyTypeCode/Any.h"
12 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
13 int number_of_oneways = 10;
14 int number_of_client_tasks = 2;
16 int
17 parse_args (int argc, ACE_TCHAR *argv[])
19 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:n:c:"));
20 int c;
22 while ((c = get_opts ()) != -1)
23 switch (c)
25 case 'k':
26 ior = get_opts.opt_arg ();
27 break;
28 case 'n' :
29 number_of_oneways = ACE_OS::atoi (get_opts.opt_arg ());
30 break;
31 case 'c' :
32 number_of_client_tasks = ACE_OS::atoi (get_opts.opt_arg ());
33 break;
34 case '?':
35 default:
36 ACE_ERROR_RETURN ((LM_ERROR,
37 "usage: %s "
38 "-k <ior>"
39 "-n <number of oneways>"
40 "-c <number of client tasks>"
41 "\n",
42 argv [0]),
43 -1);
45 // Indicates successful parsing of the command line
46 return 0;
49 int
50 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
52 try
54 CORBA::ORB_var orb =
55 CORBA::ORB_init (argc, argv);
57 CORBA::Object_var poa_object =
58 orb->resolve_initial_references("RootPOA");
60 if (CORBA::is_nil (poa_object.in ()))
61 ACE_ERROR_RETURN ((LM_ERROR,
62 " (%P|%t) Unable to initialize the POA.\n"),
63 1);
65 PortableServer::POA_var root_poa =
66 PortableServer::POA::_narrow (poa_object.in ());
68 PortableServer::POAManager_var poa_manager =
69 root_poa->the_POAManager ();
71 CORBA::Object_var object =
72 orb->resolve_initial_references ("PolicyCurrent");
74 CORBA::PolicyCurrent_var policy_current =
75 CORBA::PolicyCurrent::_narrow (object.in ());
77 if (CORBA::is_nil (policy_current.in ()))
79 ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n"));
80 return 1;
82 CORBA::Any scope_as_any;
83 scope_as_any <<= Messaging::SYNC_NONE;
85 CORBA::PolicyList policies (1); policies.length (1);
86 policies[0] =
87 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
88 scope_as_any);
89 policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
91 policies[0]->destroy ();
93 if (parse_args (argc, argv) != 0)
94 return 1;
96 // Get the sender reference..
97 CORBA::Object_var tmp =
98 orb->string_to_object(ior);
100 Test::Sender_var sender =
101 Test::Sender::_narrow(tmp.in ());
103 if (CORBA::is_nil (sender.in ()))
105 ACE_ERROR_RETURN ((LM_DEBUG,
106 "Nil coordinator reference <%s>\n",
107 ior),
111 Client_Task client_task (orb.in(),
112 sender.in (),
113 ACE_Thread_Manager::instance (),
114 number_of_oneways);
116 Server_Task server_task (orb.in (),
117 ACE_Thread_Manager::instance ());
119 // Before creating threads we will let the sender know that we
120 // will have two threads that would make invocations..
121 // this is the first oneway we do, so after this we would have a queue
122 // on one of the transports
123 sender->active_objects ((CORBA::Short) number_of_client_tasks);
125 TAO::Transport_Cache_Manager& manager = orb->orb_core()->lane_resources ().transport_cache ();
127 TAO::Transport_Cache_Manager::HASH_MAP& cachemap = manager.map();
128 TAO::Transport_Cache_Manager::HASH_MAP_ITER end_iter = cachemap.end ();
130 bool tranportwithqueue = false;
131 for (TAO::Transport_Cache_Manager::HASH_MAP_ITER iter = cachemap.begin ();
132 iter != end_iter;
133 ++iter)
135 TAO_Transport* transport = (*iter).int_id_.transport ();
136 if (transport->queue_is_empty() == 0 && transport->is_connected() == false)
138 tranportwithqueue = true;
139 break;
143 if (!tranportwithqueue)
145 ACE_ERROR ((LM_ERROR, "(%P|%t) Error: expect a not connected transport with a queue\n"));
147 else
149 ACE_DEBUG((LM_DEBUG, "(%P|%t) Found not connected transport with a queue\n"));
152 if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, 2,1) == -1)
154 ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
157 if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, number_of_client_tasks, 1) == -1)
159 ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
162 ACE_Thread_Manager::instance ()->wait ();
164 ACE_DEBUG ((LM_DEBUG,
165 "Event Loop finished\n"));
167 orb->destroy ();
169 if (tranportwithqueue == false)
171 return 1;
174 catch (const CORBA::Exception& ex)
176 ex._tao_print_exception ("Exception caught:");
177 return 1;
180 return 0;