Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Bug_2510_Regression / client.cpp
blob684b13eb11b418453bb7cd66d32d08ca0b2b2b47
1 #include "ace/Get_Opt.h"
2 #include "ace/Synch.h"
3 #include "ace/Thread.h"
4 #include "testC.h"
5 #include "Client_ORBInitializer.h"
6 #include "tao/ORBInitializer_Registry.h"
8 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("ef:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'e':
20 break;
21 case 'f':
22 ior = get_opts.opt_arg ();
23 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-v "
29 "\n",
30 argv [0]),
31 -1);
33 return 0;
36 static ACE_THR_FUNC_RETURN run_test(void* pData)
38 Test_Interceptors::Visual_ptr server = static_cast<Test_Interceptors::Visual_ptr>(pData);
40 try
42 server->normal (10);
44 catch (const CORBA::Exception& ex)
46 ex._tao_print_exception ("Exception thrown in run_test()\n");
49 return (ACE_THR_FUNC_RETURN)0;
52 int
53 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
55 try
57 PortableInterceptor::ORBInitializer_ptr temp_initializer;
59 ACE_NEW_RETURN (temp_initializer,
60 Client_ORBInitializer,
61 -1); // No exceptions yet!
62 PortableInterceptor::ORBInitializer_var initializer =
63 temp_initializer;
65 PortableInterceptor::register_orb_initializer (initializer.in ());
67 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
69 if (parse_args (argc, argv) != 0)
70 return 1;
72 CORBA::Object_var object =
73 orb->string_to_object (ior);
75 Test_Interceptors::Visual_var server =
76 Test_Interceptors::Visual::_narrow (object.in ());
78 if (CORBA::is_nil (server.in ()))
80 ACE_ERROR_RETURN ((LM_ERROR,
81 "Object reference <%s> is nil.\n",
82 ior),
83 1);
86 ACE_hthread_t threadHandle;
87 if ( ACE_Thread::spawn(run_test,
88 static_cast<void*>(server.in()),
89 THR_NEW_LWP | THR_JOINABLE ,
91 & threadHandle) == -1 )
93 ACE_ERROR_RETURN ((LM_ERROR,"Cannot start thread"), 1);
96 ACE_Thread::join (threadHandle);
98 server->shutdown ();
100 orb->destroy ();
103 catch (const CORBA::Exception& ex)
105 ex._tao_print_exception ("Caught exception in client:");
106 return 1;
110 return 0;