1 #include "bidir_giop_pch.h"
3 #include "callback_i.h"
6 #include "ace/Get_Opt.h"
7 #include "tao/BiDir_GIOP/BiDirGIOP.h"
11 ACE_TString 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
.optarg
;
28 std::cerr
<< "usage: " << argv
[0] << " -k <ior>" << std::endl
;
36 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
39 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
41 if (parse_args (argc
, argv
) != 0) {
45 // Create a bidirectional POA
46 CORBA::Object_var obj
= orb
->resolve_initial_references("RootPOA");
47 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow(obj
.in());
48 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager();
49 // Policies for the childPOA to be created.
50 CORBA::PolicyList
policies(1);
53 pol
<<= BiDirPolicy::BOTH
;
55 orb
->create_policy(BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
, pol
);
56 // Create POA as child of RootPOA with the above policies. This POA
57 // will receive request in the same connection in which it sent
59 PortableServer::POA_var poa
= root_poa
->create_POA("bidirPOA", poa_manager
.in(), policies
);
60 // Creation of bidirPOA is over. Destroy the Policy objects.
61 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
) {
62 policies
[i
]->destroy ();
64 poa_manager
->activate ();
67 obj
= orb
->string_to_object(ior
.c_str());
68 Simple_var server
= Simple::_narrow (obj
.in());
70 PortableServer::Servant_var
<Callback_i
> callback_svt
= new Callback_i(orb
.in());
72 // Register and activate callback servant
73 PortableServer::ObjectId_var id
= poa
->activate_object(callback_svt
.in());
74 obj
= poa
->id_to_reference(id
.in());
75 Callback_var callback
= Callback::_narrow(obj
.in());
77 server
->callback_object (callback
.in());
79 CORBA::Long r
= server
->test_method(1); // Tell the server to call us back.
81 std::cout
<< "unexpected result = " << r
<< std::endl
;
86 CORBA::Boolean etherealize
= true, wait
= true;
87 poa
->destroy(etherealize
, wait
);
92 catch(const CORBA::Exception
& ex
) {
93 std::cerr
<< "Caught CORBA::Exception: " << std::endl
<< ex
<< std::endl
;