1 #include "ace/Get_Opt.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");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("k:"));
17 while ((c
= get_opts ()) != -1)
21 ior
= get_opts
.opt_arg ();
26 ACE_ERROR_RETURN ((LM_ERROR
, ACE_TEXT ("usage: %s -k <ior>\n"),
29 // Indicates successful parsing of the command line
34 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
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"),
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);
58 pol
<<= BiDirPolicy::BOTH
;
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
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)
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",
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",
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);
119 ACE_DEBUG ((LM_DEBUG
,
120 "(%P|%t) unexpected result = %d ",
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
,
140 root_poa
->destroy (1, 1);
142 catch (const CORBA::Exception
&excep
)
144 excep
._tao_print_exception ("Caught exception:");