Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / HTIOP / BiDirectional / client.cpp
blob4d25836c6c1898760da421a871ff07e5eaf4c4e1
1 #include "ace/Get_Opt.h"
2 #include "test_i.h"
3 #include "tao/BiDir_GIOP/BiDirGIOP.h"
4 #include "tao/AnyTypeCode/Any.h"
7 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
9 void do_nothing ()
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.opt_arg ();
24 break;
26 case '?':
27 default:
28 ACE_ERROR_RETURN ((LM_ERROR,
29 "usage: %s "
30 "-k <ior> "
31 "\n",
32 argv [0]),
33 -1);
35 // Indicates successful parsing of the command line
36 return 0;
39 int
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;
46 try
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"),
56 1);
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);
66 policies.length (1);
68 CORBA::Any pol;
69 pol <<= BiDirPolicy::BOTH;
70 policies[0] =
71 orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
72 pol);
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
76 // the request
77 PortableServer::POA_var child_poa =
78 root_poa->create_POA ("childPOA",
79 poa_manager.in (),
80 policies);
82 // Creation of childPOA is over. Destroy the Policy objects.
83 for (CORBA::ULong i = 0;
84 i < policies.length ();
85 ++i)
87 policies[i]->destroy ();
90 poa_manager->activate ();
92 if (parse_args (argc, argv) != 0)
93 return 1;
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",
105 ior),
110 servant = new Callback_i (orb.in ());
112 Callback_var callback =
113 servant->_this ();
115 // Send the callback object to the server
116 server->callback_object (callback.in ());
118 // A method to kickstart callbacks from the server
119 CORBA::Long r =
120 server->test_method (1);
122 if (r != 0)
124 ACE_DEBUG ((LM_DEBUG,
125 "(%P|%t) unexpected result = %d ",
126 r));
129 orb->run ();
131 root_poa->destroy (true, true);
133 catch (const CORBA::Exception& ex)
135 ex._tao_print_exception ("Caught exception:");
136 return 1;
139 if (!CORBA::is_nil(root_poa.in()))
140 root_poa->destroy (true, true);
141 delete servant;
143 return 0;