More tests update
[ACE_TAO.git] / TAO / tests / NestedUpcall / Simple / simple-client.cpp
blob027c9993cb2be6666c3d29ecefeaa5f00553e0fd
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 = 5;
12 // # of nested calls to be made.
14 static int quiet = 0;
15 // The test is quiet...
17 static int number_of_threads = 1;
18 // Number of client threads.
20 class Client_Task
22 public:
23 Client_Task (client_ptr c,
24 server_ptr s);
25 int svc (void);
27 private:
28 client_var client_;
29 server_var server_;
32 Client_Task::Client_Task (client_ptr c,
33 server_ptr s)
34 : client_ (client::_duplicate (c)),
35 server_ (server::_duplicate (s))
39 int
40 Client_Task::svc (void)
42 try
44 if (!quiet)
45 ACE_DEBUG ((LM_DEBUG,
46 "(%t) Client_Task::svc calling start -> time to live = %d\n",
47 call_count));
49 // Now, we can invoke an operation on the remote side.
50 this->server_->start (this->client_.in (),
51 call_count);
53 return 0;
55 catch (const CORBA::Exception& ex)
57 ex._tao_print_exception ("Client_Task::svc");
58 return -1;
60 return 0;
63 static int
64 parse_args (int argc, ACE_TCHAR **argv)
66 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("qxn:k:t:"));
67 int c;
69 while ((c = get_opts ()) != -1)
70 switch (c)
72 case 'q':
73 quiet = 1;
74 break;
76 case 'x':
77 shutdown_server = 1;
78 break;
80 case 'n':
81 call_count = ACE_OS::atoi (get_opts.opt_arg ());
82 break;
84 case 't':
85 number_of_threads = ACE_OS::atoi (get_opts.opt_arg ());
86 break;
88 case 'k':
89 ior = get_opts.opt_arg ();
90 break;
92 case '?':
93 default:
94 ACE_ERROR_RETURN ((LM_ERROR,
95 "usage: %s"
96 " [-n number of nested calls]"
97 " [-k ior]"
98 " [-q (quite)]"
99 " [-x (shutdown server)]"
100 "\n",
101 argv[0]),
102 -1);
105 if (ior == 0)
106 ACE_ERROR_RETURN ((LM_ERROR,
107 "%s: no nested up calls server ior specified\n",
108 argv[0]),
109 -1);
111 // Indicates successful parsing of command line.
112 return 0;
116 ACT_TMAIN (int argc, ACE_TCHAR **argv)
120 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
122 int result = parse_args (argc, argv);
123 if (result != 0)
124 return result;
126 CORBA::Object_var object = orb->resolve_initial_references ("RootPOA");
128 PortableServer::POA_var root_poa =
129 PortableServer::POA::_narrow (object.in ());
131 PortableServer::POAManager_var poa_manager =
132 root_poa->the_POAManager ();
134 poa_manager->activate ();
136 object = orb->string_to_object (ior);
138 server_var server = server::_narrow (object.in ());
140 // Create an client object to hand to the other side...
141 client_i client_servant (quiet,
142 server.in ());
144 PortableServer::ObjectId_var id =
145 root_poa->activate_object (&client_servant);
147 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
149 client_var client_object = client::_narrow (object_act.in ());
151 Client_Task client_tasks (client_object.in (),
152 server.in ());
154 client_tasks.svc ();
157 if (shutdown_server)
159 server->shutdown ();
162 root_poa->destroy (1,
165 catch (const CORBA::Exception& ex)
167 ex._tao_print_exception ("client::main");
168 return -1;
170 return 0;