Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / BiDirectional_NestedUpcall / client.cpp
blobdaa8ef6e573ef47027650684b688e19c197fc665
1 #include "ace/Get_Opt.h"
2 #include "test_i.h"
3 #include "ace/High_Res_Timer.h"
4 #include "tao/BiDir_GIOP/BiDirGIOP.h"
5 #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 try
44 CORBA::ORB_var orb =
45 CORBA::ORB_init (argc, argv);
47 CORBA::Object_var poa_object =
48 orb->resolve_initial_references ("RootPOA");
50 if (CORBA::is_nil (poa_object.in ()))
51 ACE_ERROR_RETURN ((LM_ERROR,
52 " (%P|%t) Unable to initialize the POA.\n"),
53 1);
55 PortableServer::POA_var root_poa =
56 PortableServer::POA::_narrow (poa_object.in ());
58 PortableServer::POAManager_var poa_manager =
59 root_poa->the_POAManager ();
61 // Policies for the childPOA to be created.
62 CORBA::PolicyList policies (1);
63 policies.length (1);
65 CORBA::Any pol;
66 pol <<= BiDirPolicy::BOTH;
67 policies[0] =
68 orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
69 pol);
71 // Create POA as child of RootPOA with the above policies. This POA
72 // will receive request in the same connection in which it sent
73 // the request
74 PortableServer::POA_var child_poa =
75 root_poa->create_POA ("childPOA",
76 poa_manager.in (),
77 policies);
79 // Creation of childPOA is over. Destroy the Policy objects.
80 for (CORBA::ULong i = 0;
81 i < policies.length ();
82 ++i)
84 policies[i]->destroy ();
87 poa_manager->activate ();
89 if (parse_args (argc, argv) != 0)
90 return 1;
92 CORBA::Object_var object =
93 orb->string_to_object (ior);
95 Simple_Server_var server =
96 Simple_Server::_narrow (object.in ());
98 if (CORBA::is_nil (server.in ()))
100 ACE_ERROR_RETURN ((LM_ERROR,
101 "Object reference <%s> is nil.\n",
102 ior),
106 Callback_i *callback_impl = 0;
107 ACE_NEW_THROW_EX (callback_impl,
108 Callback_i (orb.in ()),
109 CORBA::NO_MEMORY ());
111 PortableServer::ServantBase_var owner_transfer(callback_impl);
113 PortableServer::ObjectId_var id =
114 root_poa->activate_object (callback_impl);
116 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
118 Callback_var callback =
119 Callback::_narrow (object_act.in ());
121 // Send the callback object to the server
122 server->callback_object (callback.in ());
124 // Call the client that will make remote calls
126 CORBA::Long r =
127 server->test_method (1);
129 if (r != 0)
131 ACE_DEBUG ((LM_DEBUG,
132 "(%P|%t) unexpected result = %d ",
133 r));
136 // Shutdown the server
137 server->shutdown ();
139 root_poa->destroy (true, true);
141 catch (const CORBA::Exception& ex)
143 ex._tao_print_exception ("Caught exception:");
144 return 1;
147 return 0;