Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_1476_Test / client.cpp
blobccd22cbbdc610647f432c5daab5eae4eaaf3676d
1 #include "HelloC.h"
3 #include "tao/Messaging/Messaging.h"
5 #include "tao/Transport_Cache_Manager.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/Thread_Lane_Resources.h"
8 #include "tao/Base_Transport_Property.h"
9 #include "tao/Stub.h"
10 #include "tao/Profile.h"
11 #include "tao/Transport.h"
13 #include "ace/Get_Opt.h"
15 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
16 bool level_obj = false;
17 bool level_thread = false;
18 bool level_orb = false;
20 bool synch_none = false;
21 bool synch_delayed = false;
23 int
24 parse_args (int argc, ACE_TCHAR *argv[])
26 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:l:s:"));
27 int c;
28 level_obj = true; //default
29 synch_none = true; //default
31 while ((c = get_opts ()) != -1)
32 switch (c)
34 case 'k':
35 ior = get_opts.opt_arg ();
36 break;
37 case 'l':
39 ACE_TCHAR *level = get_opts.opt_arg ();
40 level_obj = false;
42 if (ACE_OS::strcmp (level, ACE_TEXT("orb")) == 0) {
43 level_orb = true;
45 else if (ACE_OS::strcmp (level, ACE_TEXT("thread")) == 0) {
46 level_thread = true;
48 else {
49 level_obj = true;
51 break;
53 case 's':
55 ACE_TCHAR *synch = get_opts.opt_arg ();
56 synch_none = false;
58 if (ACE_OS::strcmp (synch, ACE_TEXT("delayed")) == 0) {
59 synch_delayed = true;
61 else {
62 synch_none = true;
64 break;
67 case '?':
68 default:
69 ACE_ERROR_RETURN ((LM_ERROR,
70 "usage: %s "
71 "-k <ior> "
72 "-l <obj|orb|thread> "
73 "-s <none|delayed> "
74 "\n",
75 argv [0]),
76 -1);
78 // Indicates successful parsing of the command line
79 return 0;
82 int
83 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
85 try
87 CORBA::ORB_var orb =
88 CORBA::ORB_init (argc, argv, "test");
90 if (parse_args (argc, argv) != 0)
91 return 1;
93 CORBA::Object_var tmp = orb->string_to_object(ior);
95 if (CORBA::is_nil (tmp.in ()))
97 ACE_ERROR_RETURN ((LM_ERROR, "Invalid IOR.\n")
98 ,1);
102 // Set the Synch Scopes
104 CORBA::Any scope_as_any;
106 if (synch_none == true)
108 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Applying SYNC_NONE.\n"));
109 scope_as_any <<= Messaging::SYNC_NONE;
111 else if (synch_delayed == true)
113 ACE_DEBUG ((LM_DEBUG,
114 "(%P|%t) - Applying SYNC_DELAYED_BUFFERING.\n"));
115 scope_as_any <<= TAO::SYNC_DELAYED_BUFFERING;
118 CORBA::PolicyList policies (1);
119 policies.length (1);
120 policies[0] =
121 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
122 scope_as_any);
124 if (level_thread == true)
126 ACE_DEBUG ((LM_DEBUG,
127 "(%P|%t) - Applying Synch Scope at thread level.\n"));
129 CORBA::Object_var object =
130 orb->resolve_initial_references ("PolicyCurrent");
131 CORBA::PolicyCurrent_var policy_current =
132 CORBA::PolicyCurrent::_narrow (object.in ());
134 policy_current->set_policy_overrides (policies,
135 CORBA::ADD_OVERRIDE);
137 else if (level_orb == true)
139 ACE_DEBUG ((LM_DEBUG,
140 "(%P|%t) - Applying Synch Scope at orb level.\n"));
142 CORBA::Object_var obj =
143 orb->resolve_initial_references("ORBPolicyManager");
144 CORBA::PolicyManager_var policy_manager =
145 CORBA::PolicyManager::_narrow(obj.in());
147 policy_manager->set_policy_overrides (policies,
148 CORBA::ADD_OVERRIDE);
150 else if (level_obj == true)
152 ACE_DEBUG ((LM_DEBUG,
153 "(%P|%t) - Applying Synch Scope at Object level.\n"));
155 tmp = tmp->_set_policy_overrides (policies, CORBA::SET_OVERRIDE);
158 policies[0]->destroy ();
161 Test::Hello_var hello =
162 Test::Hello::_unchecked_narrow(tmp.in ());
164 if (CORBA::is_nil (hello.in ()))
166 ACE_ERROR_RETURN ((LM_ERROR,
167 "Nil Test::Hello reference <%s>\n",
168 ior),
172 // If a blocking connection is initiated in the next step
173 // the test will get an exception indicating test failure.
174 // Be sure you IOR is for the localhost endpoint, else
175 // grab a book and wait around for timeout.
176 hello->get_string ();
178 TAO::Transport_Cache_Manager &tcm =
179 hello->orb_core ()->lane_resources ().transport_cache ();
181 TAO_Base_Transport_Property desc (hello->_stubobj ()->profile_in_use ()->endpoint ());
183 if (tcm.current_size() == 0)
185 ACE_ERROR_RETURN ((LM_ERROR,
186 "The Transport Cache shouldn't be empty here.\n"),
190 size_t busy_count = 0;
191 TAO_Transport *transport = 0;
192 TAO::Transport_Cache_Manager::Find_Result find_result =
193 tcm.find_transport (&desc, transport, busy_count);
194 // We don't need this transport any more. Release the ownership.
195 transport->remove_reference ();
197 switch (find_result){
198 case TAO::Transport_Cache_Manager::CACHE_FOUND_NONE:
200 ACE_ERROR_RETURN ((LM_ERROR,
201 ACE_TEXT("Expected to find a transport in the cache.\n")
202 ),1);
204 case TAO::Transport_Cache_Manager::CACHE_FOUND_CONNECTING:
206 ACE_DEBUG (( LM_DEBUG,
207 ACE_TEXT ("Transport Cache contains connecting entry as expected.\n")
209 break; // that's what we expected
211 case TAO::Transport_Cache_Manager::CACHE_FOUND_BUSY:
213 ACE_ERROR_RETURN ((LM_ERROR,
214 ACE_TEXT("Cached Transport is busy. Should not happen because there's no server.\n")
215 ),1);
217 case TAO::Transport_Cache_Manager::CACHE_FOUND_AVAILABLE:
219 ACE_ERROR_RETURN ((LM_ERROR,
220 ACE_TEXT("Cached Transport is available. Should not happen because there's no server.\n")
221 ),1);
223 default:
225 ACE_ERROR_RETURN ((LM_ERROR,
226 ACE_TEXT("Transport_Cache::find returned unknown status.\n")
227 ),1);
231 orb->destroy ();
233 catch (const CORBA::Exception &ex)
235 ACE_ERROR ((LM_ERROR, "ERROR: Exception caught: %s\"%s\"\n"
236 , ex._name(), ex._rep_id ()));
237 return 1;
240 return 0;