=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / BiDirectional / client.cpp
blob286816e91c4f2ea310b8fd0b9e1fa45e32e50654
1 #include "ace/Get_Opt.h"
2 #include "test_i.h"
3 #include "tao/BiDir_GIOP/BiDirGIOP.h"
4 #include "tao/AnyTypeCode/Any.h"
6 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
8 void do_nothing ()
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'k':
22 ior = get_opts.opt_arg ();
23 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-k <ior> "
30 "\n",
31 argv [0]),
32 -1);
34 // Indicates successful parsing of the command line
35 return 0;
38 int
39 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
41 try
43 CORBA::ORB_var orb =
44 CORBA::ORB_init (argc, argv);
46 CORBA::Object_var poa_object =
47 orb->resolve_initial_references ("RootPOA");
49 if (CORBA::is_nil (poa_object.in ()))
50 ACE_ERROR_RETURN ((LM_ERROR,
51 " (%P|%t) Unable to initialize the POA.\n"),
52 1);
54 PortableServer::POA_var root_poa =
55 PortableServer::POA::_narrow (poa_object.in ());
57 PortableServer::POAManager_var poa_manager =
58 root_poa->the_POAManager ();
60 // Policies for the childPOA to be created.
61 CORBA::PolicyList policies (1);
62 policies.length (1);
64 CORBA::Any pol;
65 pol <<= BiDirPolicy::BOTH;
66 policies[0] =
67 orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
68 pol);
70 // Create POA as child of RootPOA with the above policies. This POA
71 // will receive request in the same connection in which it sent
72 // the request
73 PortableServer::POA_var child_poa =
74 root_poa->create_POA ("childPOA",
75 poa_manager.in (),
76 policies);
78 // Creation of childPOA is over. Destroy the Policy objects.
79 for (CORBA::ULong i = 0;
80 i < policies.length ();
81 ++i)
83 policies[i]->destroy ();
86 poa_manager->activate ();
88 if (parse_args (argc, argv) != 0)
89 return 1;
91 CORBA::Object_var object =
92 orb->string_to_object (ior);
94 Simple_Server_var server =
95 Simple_Server::_narrow (object.in ());
97 if (CORBA::is_nil (server.in ()))
99 ACE_ERROR_RETURN ((LM_ERROR,
100 "Object reference <%s> is nil.\n",
101 ior),
105 Callback_i callback_impl (orb.in ());
107 PortableServer::ObjectId_var id =
108 root_poa->activate_object (&callback_impl);
110 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
112 Callback_var callback =
113 Callback::_narrow (object_act.in ());
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 return 0;