Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / DevGuideExamples / BiDirectionalGIOP / client.cpp
blob4f484c3f6c404de8ae48ea6f0a74ee04d975072a
1 #include "bidir_giop_pch.h"
3 #include "callback_i.h"
4 #include "simpleC.h"
6 #include "ace/Get_Opt.h"
7 #include "tao/BiDir_GIOP/BiDirGIOP.h"
9 #include <iostream>
11 ACE_TString ior = ACE_TEXT ("file://test.ior");
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'k':
23 ior = get_opts.optarg;
24 break;
26 case '?':
27 default:
28 std::cerr << "usage: " << argv[0] << " -k <ior>" << std::endl;
29 return -1;
30 break;
32 return 0;
35 int
36 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
38 try {
39 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
41 if (parse_args (argc, argv) != 0) {
42 return 1;
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);
51 policies.length(1);
52 CORBA::Any pol;
53 pol <<= BiDirPolicy::BOTH;
54 policies[0] =
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
58 // the request
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 ();
66 // get server object
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.
80 if (r != 0) {
81 std::cout << "unexpected result = " << r << std::endl;
84 orb->run();
86 CORBA::Boolean etherealize = true, wait = true;
87 poa->destroy(etherealize, wait);
88 orb->destroy();
90 return 0;
92 catch(const CORBA::Exception& ex) {
93 std::cerr << "Caught CORBA::Exception: " << std::endl << ex << std::endl;
96 return 1;