1 #include "ace/Get_Opt.h"
3 #include "tao/BiDir_GIOP/BiDirGIOP.h"
4 #include "tao/AnyTypeCode/Any.h"
7 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
14 parse_args (int argc
, ACE_TCHAR
*argv
[])
16 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
19 while ((c
= get_opts ()) != -1)
23 ior
= get_opts
.opt_arg ();
28 ACE_ERROR_RETURN ((LM_ERROR
,
35 // Indicates successful parsing of the command line
40 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
42 CORBA::ORB_var orb
= CORBA::ORB::_nil();
43 PortableServer::POA_var root_poa
= PortableServer::POA::_nil();
44 Callback_i
*servant
= 0;
48 orb
= CORBA::ORB_init (argc
, argv
);
50 CORBA::Object_var poa_object
=
51 orb
->resolve_initial_references ("RootPOA");
53 if (CORBA::is_nil (poa_object
.in ()))
54 ACE_ERROR_RETURN ((LM_ERROR
,
55 " (%P|%t) Unable to initialize the POA.\n"),
58 PortableServer::POA_var root_poa
=
59 PortableServer::POA::_narrow (poa_object
.in ());
61 PortableServer::POAManager_var poa_manager
=
62 root_poa
->the_POAManager ();
64 // Policies for the childPOA to be created.
65 CORBA::PolicyList
policies (1);
69 pol
<<= BiDirPolicy::BOTH
;
71 orb
->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
,
74 // Create POA as child of RootPOA with the above policies. This POA
75 // will receive request in the same connection in which it sent
77 PortableServer::POA_var child_poa
=
78 root_poa
->create_POA ("childPOA",
82 // Creation of childPOA is over. Destroy the Policy objects.
83 for (CORBA::ULong i
= 0;
84 i
< policies
.length ();
87 policies
[i
]->destroy ();
90 poa_manager
->activate ();
92 if (parse_args (argc
, argv
) != 0)
95 CORBA::Object_var object
=
96 orb
->string_to_object (ior
);
98 Simple_Server_var server
=
99 Simple_Server::_narrow (object
.in ());
101 if (CORBA::is_nil (server
.in ()))
103 ACE_ERROR_RETURN ((LM_ERROR
,
104 "Object reference <%s> is nil\n",
110 servant
= new Callback_i (orb
.in ());
112 Callback_var callback
=
115 // Send the callback object to the server
116 server
->callback_object (callback
.in ());
118 // A method to kickstart callbacks from the server
120 server
->test_method (1);
124 ACE_DEBUG ((LM_DEBUG
,
125 "(%P|%t) unexpected result = %d ",
131 root_poa
->destroy (true, true);
133 catch (const CORBA::Exception
& ex
)
135 ex
._tao_print_exception ("Caught exception:");
139 if (!CORBA::is_nil(root_poa
.in()))
140 root_poa
->destroy (true, true);