1 #include "bidir_giop_pch.h"
6 #include "ace/Get_Opt.h"
7 #include "tao/BiDir_GIOP/BiDirGIOP.h"
11 ACE_TString ior_output_file
;
12 int callback_count
= 10;
15 parse_args(int argc
, ACE_TCHAR
*argv
[])
17 ACE_Get_Opt
get_opts(argc
, argv
, ACE_TEXT("o:i:"));
20 while((c
= get_opts()) != -1)
24 ior_output_file
= get_opts
.optarg
;
27 callback_count
= ACE_OS::atoi(get_opts
.optarg
);
31 std::cerr
<< "usage: " << argv
[0] << "-o <iorfile> -i <no_iterations>" << std::endl
;
35 // Indicates successful parsing of the command line
40 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
44 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
46 if (parse_args(argc
, argv
) != 0) {
50 // Create a bidirectional POA
51 CORBA::Object_var obj
= orb
->resolve_initial_references("RootPOA");
52 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow(obj
.in());
53 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager();
54 // Policies for the childPOA to be created.
55 CORBA::PolicyList
policies(1);
58 pol
<<= BiDirPolicy::BOTH
;
60 orb
->create_policy(BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
, pol
);
61 // Create POA as child of RootPOA with the above policies. This POA
62 // will receive request in the same connection in which it sent
64 PortableServer::POA_var poa
= root_poa
->create_POA("bidirPOA", poa_manager
.in(), policies
);
65 // Creation of bidirPOA is over. Destroy the Policy objects.
66 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
) {
67 policies
[i
]->destroy ();
69 poa_manager
->activate ();
71 PortableServer::Servant_var
<Simple_i
> svt
= new Simple_i(orb
.in(), callback_count
);
73 // Register and activate Simple servant
74 PortableServer::ObjectId_var id
= poa
->activate_object(svt
.in());
75 obj
= poa
->id_to_reference(id
.in());
76 Simple_var server
= Simple::_narrow(obj
.in());
78 CORBA::String_var ior
= orb
->object_to_string(server
.in());
79 if (ior_output_file
!= ACE_TEXT("")) {
80 std::ofstream
outfile(ACE_TEXT_ALWAYS_CHAR(ior_output_file
.c_str()));
83 std::cout
<< "Activated as " << ior
.in() << std::endl
;
85 // Our own special orb->run() that knows how to callback clients
87 // returns 1 as soon as it has successfully called back.
88 if (svt
->call_client()) {
92 // We don't want to check for work pending, because we really want
93 // to simulate a normal orb->run() while adding the ability to call
94 // our routine which calls back to the client.
98 std::cout
<< "Event loop finished." << std::endl
;
100 CORBA::Boolean etherealize
= true, wait
= true;
101 poa
->destroy(etherealize
, wait
);
106 catch(const CORBA::Exception
& ex
) {
107 std::cerr
<< "Caught CORBA::Exception: " << std::endl
<< ex
<< std::endl
;