Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / No_Server_MT_Connect_Test / client.cpp
blob0bd61bb3908b3f541960bda562bb24bbe0426226
1 #include "testC.h"
2 #include "tao/debug.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Task.h"
6 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
7 int nthreads = 5;
8 int niterations = 5;
9 int server_shutdown = 0;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:n:i:x"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 ior = get_opts.opt_arg ();
22 break;
23 case 'n':
24 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
25 break;
26 case 'i':
27 niterations = ACE_OS::atoi (get_opts.opt_arg ());
28 break;
29 case 'x':
30 server_shutdown = 1;
31 break;
32 case '?':
33 default:
34 ACE_ERROR_RETURN ((LM_ERROR,
35 "usage: %s "
36 "-k <ior> "
37 "-n <nthreads> "
38 "-i <niterations> "
39 "\n",
40 argv [0]),
41 -1);
43 // Indicates successful parsing of the command line
44 return 0;
47 class Client : public ACE_Task_Base
49 // = TITLE
50 // Run the client thread
52 // = DESCRIPTION
53 // Use the ACE_Task_Base class to run the client threads.
55 public:
56 Client (Simple_Server_ptr server, int niterations);
59 /// The thread entry point.
60 virtual int svc ();
62 private:
63 Simple_Server_var server_;
64 // The server.
66 int niterations_;
67 // The number of iterations on each client thread.
70 int
71 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
73 try
75 CORBA::ORB_var orb =
76 CORBA::ORB_init (argc, argv);
78 if (parse_args (argc, argv) != 0)
79 return 1;
81 CORBA::Object_var object =
82 orb->string_to_object (ior);
84 Simple_Server_var server =
85 Simple_Server::_narrow (object.in ());
87 if (CORBA::is_nil (server.in ()))
89 ACE_ERROR_RETURN ((LM_ERROR,
90 "Object reference <%s> is nil.\n",
91 ior),
92 1);
95 if (server_shutdown)
97 server->shutdown ();
100 Client client (server.in (), niterations);
101 if (client.activate (THR_NEW_LWP | THR_JOINABLE,
102 nthreads) != 0)
103 ACE_ERROR_RETURN ((LM_ERROR,
104 "Cannot activate client threads\n"),
107 client.thr_mgr ()->wait ();
109 ACE_DEBUG ((LM_DEBUG, "threads finished\n"));
111 orb->destroy ();
113 catch (const CORBA::Exception& ex)
115 ex._tao_print_exception ("Caught exception:");
116 return 1;
119 return 0;
122 // ****************************************************************
124 Client::Client (Simple_Server_ptr server,
125 int niterations)
126 : server_ (Simple_Server::_duplicate (server)),
127 niterations_ (niterations)
132 Client::svc ()
136 for (int i = 0; i < this->niterations_; ++i)
138 this->server_->test_method ();
140 if (TAO_debug_level > 0 && i % 100 == 0)
141 ACE_DEBUG ((LM_DEBUG, "(%P|%t) iteration = %d\n",
142 i));
145 catch (const CORBA::Exception&)
147 ACE_DEBUG ((LM_DEBUG,
148 "(%P|%t) Expected exceptions\n"));
150 return 0;