1 #include "ace/Get_Opt.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");
18 parse_args (int argc
, ACE_TCHAR
*argv
[])
20 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
23 while ((c
= get_opts ()) != -1)
27 ior
= get_opts
.opt_arg ();
32 ACE_ERROR_RETURN ((LM_ERROR
,
33 ACE_TEXT ("usage: %s ")
34 ACE_TEXT ("-k <ior> ")
39 // Indicates successful parsing of the command line
44 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
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")),
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);
70 pol
<<= BiDirPolicy::BOTH
;
72 orb
->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
,
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
78 PortableServer::POA_var child_poa
=
79 root_poa
->create_POA ("childPOA",
83 // Creation of childPOA is over. Destroy the Policy objects.
84 for (CORBA::ULong i
= 0;
85 i
< policies
.length ();
88 policies
[i
]->destroy ();
91 poa_manager
->activate ();
93 if (parse_args (argc
, argv
) != 0)
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",
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 (),
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
144 server
->test_method (1);
148 ACE_DEBUG ((LM_DEBUG
,
149 ACE_TEXT ("(%P|%t) unexpected result = %d "),
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
,
172 root_poa
->destroy (true, true);
176 catch (const CORBA::Exception
& ex
)
178 ex
._tao_print_exception ("Caught exception:");