Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_3953_Regression / client.cpp
blob096b1866420c1375cb4ba0ac87968e3533bfb870
1 #include "client_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Task.h"
5 static const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
6 // Server IOR.
8 static int shutdown_server = 0;
9 // Flag to tell server to shutdown.
11 static CORBA::UShort call_count = 2;
12 // # of nested calls to be made.
14 static int quiet = 0;
15 // The test is quiet...
17 class Client_Task
19 public:
20 Client_Task (client_ptr c,
21 server_ptr s);
22 int svc ();
24 bool exception () const;
26 private:
27 client_var client_;
28 server_var server_;
31 Client_Task::Client_Task (client_ptr c,
32 server_ptr s)
33 : client_ (client::_duplicate (c)),
34 server_ (server::_duplicate (s))
38 int
39 Client_Task::svc ()
41 try
43 if (!quiet)
44 ACE_DEBUG ((LM_DEBUG,
45 "(%t) Client_Task::svc calling start -> time to live = %d\n",
46 call_count));
48 // Now, we can invoke an operation on the remote side.
49 this->server_->start (this->client_.in (),
50 call_count);
52 catch (const CORBA::Exception& ex)
54 ex._tao_print_exception ("Client_Task::svc");
55 return -1;
57 return 0;
60 static int
61 parse_args (int argc,
62 ACE_TCHAR **argv)
64 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("qxn:k:"));
65 int c;
67 while ((c = get_opts ()) != -1)
68 switch (c)
70 case 'q':
71 quiet = 1;
72 break;
74 case 'x':
75 shutdown_server = 1;
76 break;
78 case 'n':
79 call_count = ACE_OS::atoi (get_opts.opt_arg ());
80 break;
82 case 'k':
83 ior = get_opts.opt_arg ();
84 break;
86 case '?':
87 default:
88 ACE_ERROR_RETURN ((LM_ERROR,
89 "usage: %s"
90 " [-n number of nested calls]"
91 " [-k ior]"
92 " [-q (quite)]"
93 " [-x (shutdown server)]"
94 "\n",
95 argv[0]),
96 -1);
99 if (ior == 0)
100 ACE_ERROR_RETURN ((LM_ERROR,
101 "%s: no nested up calls server ior specified\n",
102 argv[0]),
103 -1);
105 // Indicates successful parsing of command line.
106 return 0;
110 ACE_TMAIN (int argc,
111 ACE_TCHAR **argv)
113 int result = 0;
116 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
118 result = parse_args (argc, argv);
119 if (result != 0)
120 return result;
122 CORBA::Object_var object = orb->resolve_initial_references ("RootPOA");
124 PortableServer::POA_var root_poa =
125 PortableServer::POA::_narrow (object.in ());
127 PortableServer::POAManager_var poa_manager =
128 root_poa->the_POAManager ();
130 poa_manager->activate ();
132 object = orb->string_to_object (ior);
134 server_var server = server::_narrow (object.in ());
136 // Create an client object to hand to the other side...
137 client_i client_servant (quiet,
138 server.in ());
140 PortableServer::ObjectId_var id =
141 root_poa->activate_object (&client_servant);
143 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
145 client_var client_object = client::_narrow (object_act.in ());
147 Client_Task client_tasks (client_object.in (),
148 server.in ());
150 client_tasks.svc ();
152 if (shutdown_server)
154 server->shutdown ();
157 root_poa->destroy (true, true);
159 orb->destroy ();
161 catch (const CORBA::Exception& ex)
163 ex._tao_print_exception ("client::main");
164 return -1;
166 return result;