Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Bug_1551_Regression / client.cpp
blob83ae4e3750f0445496402dad0f23311087e9144a
2 #include "TestS.h"
3 #include "Client_Task.h"
4 #include "ace/Get_Opt.h"
5 #include "tao/AnyTypeCode/Any.h"
7 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
9 int nthreads = 1;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("n:k:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 ior = get_opts.opt_arg ();
22 break;
24 case 'n':
25 nthreads = ACE_OS::atoi(get_opts.opt_arg());
26 break;
28 case '?':
29 default:
30 ACE_ERROR_RETURN ((LM_ERROR,
31 "usage: %s "
32 "-k <ior> "
33 "\n",
34 argv [0]),
35 -1);
37 // Indicates successful parsing of the command line
38 return 0;
41 int
42 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
44 int retval = 0;
46 try
48 CORBA::ORB_var orb =
49 CORBA::ORB_init (argc, argv);
51 if (parse_args (argc, argv) != 0)
52 return 1;
54 CORBA::Object_var tmp =
55 orb->string_to_object(ior);
57 Test::Hello_var hello =
58 Test::Hello::_narrow(tmp.in ());
60 if (CORBA::is_nil (hello.in ()))
62 ACE_ERROR_RETURN ((LM_DEBUG,
63 "Nil Test::Hello reference <%s>\n",
64 ior),
65 1);
68 CORBA::Object_var poa_object =
69 orb->resolve_initial_references("RootPOA");
71 PortableServer::POA_var root_poa =
72 PortableServer::POA::_narrow (poa_object.in ());
74 PortableServer::POAManager_var poa_manager =
75 root_poa->the_POAManager ();
77 poa_manager->activate ();
80 // Let the client perform the test in a separate thread
83 Client_Task client (hello.in (),
84 orb.in (),
85 ACE_Thread_Manager::instance ());
87 if (client.activate (THR_NEW_LWP | THR_JOINABLE, nthreads) != 0)
89 ACE_ERROR_RETURN ((LM_ERROR,
90 "ERROR - Cannot activate client threads\n"),
91 1);
95 ACE_Time_Value thread_deadline = ACE_OS::gettimeofday();
96 thread_deadline += 30;
98 if(client.thr_mgr ()->wait (&thread_deadline) == -1)
100 ACE_ERROR((LM_ERROR,
101 "ERROR - Timeout waiting for client threads\n"));
103 retval = 1;
106 root_poa->destroy (true, // ethernalize objects
107 false); // wait for completion
109 orb->destroy ();
111 catch (const CORBA::Exception& ex)
113 ex._tao_print_exception ("Exception caught:");
114 return 1;
117 return retval;