Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_3108_Regression / client.cpp
blob8e63098454f803b72a556809ec648edd8c3667d7
1 #include "testC.h"
2 #include "ace/Task.h"
3 #include "ace/Get_Opt.h"
5 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
7 test_var global_client;
8 int iterations = 100;
9 bool server_shutdown = true;
10 int n_tasks = 45;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:c:x"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'k':
22 ior = get_opts.opt_arg ();
23 break;
24 case 'c':
25 n_tasks = ACE_OS::atoi (get_opts.opt_arg ());
26 break;
27 case 'x':
28 server_shutdown = false;
29 break;
30 case '?':
31 default:
32 ACE_ERROR_RETURN ((LM_ERROR,
33 "usage: %s "
34 "-k <ior> "
35 "[-x] [-c concurrent_tasks]"
36 "\n",
37 argv [0]),
38 -1);
40 // Indicates successful parsing of the command line
41 return 0;
45 class Client : public ACE_Task_Base
47 public:
48 // ctor
49 Client (test_ptr server);
51 virtual int svc ();
53 // The server.
54 test_var server_;
57 Client::Client (test_ptr server)
58 : server_ (test::_duplicate (server))
62 int
63 Client::svc ()
65 try
67 this->server_->test_method();
69 catch (const CORBA::Exception& ex)
71 ex._tao_print_exception ("Client: exception raised");
73 return 0;
76 int
77 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
79 try
81 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
83 if (parse_args (argc, argv) != 0)
84 return 1;
86 CORBA::Object_var obj = orb->string_to_object(ior);
87 test_var server = test::_narrow(obj.in ());
88 if (CORBA::is_nil(server.in ()))
90 ACE_ERROR_RETURN ((LM_DEBUG,
91 "Nil reference <%s>\n",
92 ior),
93 1);
96 Client client (server.in ());
97 if (client.activate (THR_NEW_LWP | THR_JOINABLE,
98 n_tasks) != 0)
99 ACE_ERROR_RETURN ((LM_ERROR,
100 "Cannot activate client threads\n"),
103 client.thr_mgr ()->wait ();
105 if (server_shutdown)
107 server->shutdown ();
110 orb->destroy ();
112 catch (const CORBA::Exception& ex)
114 ex._tao_print_exception ("Exception caught");
115 return -1;
118 return 0;