Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_3068_Regression / client.cpp
blob6ec734c777240105602da07433a49392897c556b
1 #include "ace/Get_Opt.h"
2 #include "test_i.h"
3 #include "tao/BiDir_GIOP/BiDirGIOP.h"
5 #include "tao/ORB_Core.h"
6 #include "tao/Transport_Cache_Manager.h"
7 #include "tao/Thread_Lane_Resources.h"
9 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("k:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 ior = get_opts.opt_arg ();
22 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("usage: %s -k <ior>\n"),
27 argv [0]), -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 int
34 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
36 try
38 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
40 CORBA::Object_var poa_object =
41 orb->resolve_initial_references ("RootPOA");
43 if (CORBA::is_nil (poa_object.in ()))
44 ACE_ERROR_RETURN ((LM_ERROR,
45 " (%P|%t) Unable to initialize the POA.\n"),
46 1);
48 PortableServer::POA_var root_poa =
49 PortableServer::POA::_narrow (poa_object.in ());
51 PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
53 // Policies for the childPOA to be created.
54 CORBA::PolicyList policies (1);
55 policies.length (1);
57 CORBA::Any pol;
58 pol <<= BiDirPolicy::BOTH;
59 policies[0] =
60 orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, pol);
62 // Create POA as child of RootPOA with the above policies. This POA
63 // will receive request in the same connection in which it sent
64 // the request
65 PortableServer::POA_var child_poa =
66 root_poa->create_POA ("childPOA", poa_manager.in (), policies);
68 // Creation of childPOA is over. Destroy the Policy objects.
69 for (CORBA::ULong i = 0; i < policies.length (); ++i)
71 policies[i]->destroy ();
74 poa_manager->activate ();
76 if (parse_args (argc, argv) != 0)
77 return 1;
79 CORBA::Object_var object = orb->string_to_object (ior);
81 Simple_Server_var server = Simple_Server::_narrow (object.in ());
83 if (CORBA::is_nil (server.in ()))
85 ACE_ERROR_RETURN ((LM_ERROR,
86 "Object reference <%C> is nil\n",
87 ior),
88 1);
91 Callback_i callback_impl (orb.in ());
93 PortableServer::ObjectId_var id =
94 PortableServer::string_to_ObjectId ("client_callback");
96 child_poa->activate_object_with_id (id.in (), &callback_impl);
98 CORBA::Object_var callback_object =
99 child_poa->id_to_reference (id.in ());
101 Callback_var callback = Callback::_narrow (callback_object.in ());
103 CORBA::String_var ior = orb->object_to_string (callback.in ());
105 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Client callback activated as <%C>\n",
106 ior.in ()));
108 // Send the callback object to the server
109 server->callback_object (callback.in ());
111 int pre_call_connections =
112 orb->orb_core ()->lane_resources ().transport_cache ().current_size ();
114 // A method to kickstart callbacks from the server
115 CORBA::Long r = server->test_method (1);
117 if (r != 0)
119 ACE_DEBUG ((LM_DEBUG,
120 "(%P|%t) unexpected result = %d ",
121 r));
124 orb->run ();
126 int cur_connections =
127 orb->orb_core ()->lane_resources ().transport_cache ().current_size ();
129 if (cur_connections > pre_call_connections)
131 ACE_ERROR ((LM_ERROR,
132 "(%P|%t) Expected %d "
133 "connections in the transport cache, but found "
134 "%d instead. Aborting.\n",
135 pre_call_connections,
136 cur_connections));
137 ACE_OS::abort ();
140 root_poa->destroy (true, true);
142 catch (const CORBA::Exception &excep)
144 excep._tao_print_exception ("Caught exception:");
145 return 1;
148 return 0;