Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / BiDirectional / client.cpp
blobb2e4d80e1d8884d23c670acff662a3835cf5d8b6
1 #include "ace/Get_Opt.h"
2 #include "test_i.h"
3 #include "tao/BiDir_GIOP/BiDirGIOP.h"
4 #include "tao/AnyTypeCode/Any.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/Transport_Cache_Manager.h"
8 #include "tao/Thread_Lane_Resources.h"
11 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
13 void do_nothing ()
17 int
18 parse_args (int argc, ACE_TCHAR *argv[])
20 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
21 int c;
23 while ((c = get_opts ()) != -1)
24 switch (c)
26 case 'k':
27 ior = get_opts.opt_arg ();
28 break;
30 case '?':
31 default:
32 ACE_ERROR_RETURN ((LM_ERROR,
33 ACE_TEXT ("usage: %s ")
34 ACE_TEXT ("-k <ior> ")
35 ACE_TEXT ("\n"),
36 argv [0]),
37 -1);
39 // Indicates successful parsing of the command line
40 return 0;
43 int
44 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
46 try
48 CORBA::ORB_var orb =
49 CORBA::ORB_init (argc, argv);
51 CORBA::Object_var poa_object =
52 orb->resolve_initial_references ("RootPOA");
54 if (CORBA::is_nil (poa_object.in ()))
55 ACE_ERROR_RETURN ((LM_ERROR,
56 ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
57 1);
59 PortableServer::POA_var root_poa =
60 PortableServer::POA::_narrow (poa_object.in ());
62 PortableServer::POAManager_var poa_manager =
63 root_poa->the_POAManager ();
65 // Policies for the childPOA to be created.
66 CORBA::PolicyList policies (1);
67 policies.length (1);
69 CORBA::Any pol;
70 pol <<= BiDirPolicy::BOTH;
71 policies[0] =
72 orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
73 pol);
75 // Create POA as child of RootPOA with the above policies. This POA
76 // will receive request in the same connection in which it sent
77 // the request
78 PortableServer::POA_var child_poa =
79 root_poa->create_POA ("childPOA",
80 poa_manager.in (),
81 policies);
83 // Creation of childPOA is over. Destroy the Policy objects.
84 for (CORBA::ULong i = 0;
85 i < policies.length ();
86 ++i)
88 policies[i]->destroy ();
91 poa_manager->activate ();
93 if (parse_args (argc, argv) != 0)
94 return 1;
96 CORBA::Object_var object =
97 orb->string_to_object (ior);
99 Simple_Server_var server =
100 Simple_Server::_narrow (object.in ());
102 if (CORBA::is_nil (server.in ()))
104 ACE_ERROR_RETURN ((LM_ERROR,
105 "Object reference <%s> is nil\n",
106 ior),
111 Callback_i *callback_impl = 0;
112 callback_impl = new Callback_i (orb.in ());
113 PortableServer::ServantBase_var safe (callback_impl);
115 PortableServer::ObjectId_var id =
116 PortableServer::string_to_ObjectId ("client_callback");
118 child_poa->activate_object_with_id (id.in (),
119 callback_impl);
121 CORBA::Object_var callback_object =
122 child_poa->id_to_reference (id.in ());
124 Callback_var callback =
125 Callback::_narrow (callback_object.in ());
128 CORBA::String_var ior =
129 orb->object_to_string (callback.in ());
131 ACE_DEBUG ((LM_DEBUG,
132 ACE_TEXT ("(%P|%t) Client callback activated as <%C>\n"), ior.in ()));
134 // Send the callback object to the server
135 server->callback_object (callback.in ());
137 // This is a non-portable, but the only currently available way of
138 // determining the number of currently open connections.
139 size_t pre_call_connections =
140 orb->orb_core ()->lane_resources ().transport_cache ().current_size ();
142 // A method to kickstart callbacks from the server
143 CORBA::Long r =
144 server->test_method (1);
146 if (r != 0)
148 ACE_DEBUG ((LM_DEBUG,
149 ACE_TEXT ("(%P|%t) unexpected result = %d "),
150 r));
153 orb->run ();
155 // This is a non-portable, but the only currently available way of
156 // determining the number of currently open connections.
157 size_t cur_connections =
158 orb->orb_core()->lane_resources().transport_cache().current_size ();
160 if (cur_connections > pre_call_connections)
162 ACE_ERROR ((LM_ERROR,
163 ACE_TEXT ("(%P|%t) Expected %d ")
164 ACE_TEXT ("connections in the transport cache, but found ")
165 ACE_TEXT ("%d instead. Aborting.\n"),
166 pre_call_connections,
167 cur_connections));
169 ACE_OS::abort ();
172 root_poa->destroy (true, true);
174 orb->destroy ();
176 catch (const CORBA::Exception& ex)
178 ex._tao_print_exception ("Caught exception:");
179 return 1;
182 return 0;