Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_3926_Regression / client.cpp
blob5c16c0ca9ffa758fbf67685c491a1dd39076950b
1 // -*- C++ -*-
2 #include "testC.h"
3 #include "Client_ORBInitializer.h"
5 #include "tao/ORBInitializer_Registry.h"
7 #include "ace/Get_Opt.h"
8 #include "ace/Argv_Type_Converter.h"
10 const ACE_TCHAR *ior = 0;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("k:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'k':
22 ior = get_opts.opt_arg ();
23 break;
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 ACE_TEXT ("Usage: %s ")
27 ACE_TEXT ("-k IOR\n"),
28 argv[0]),
29 -1);
32 return 0;
35 int
36 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
38 int status = 0;
40 try
42 #if TAO_HAS_INTERCEPTORS == 1
43 PortableInterceptor::ORBInitializer_ptr temp_initializer =
44 PortableInterceptor::ORBInitializer::_nil ();
46 ACE_NEW_RETURN (temp_initializer,
47 Client_ORBInitializer,
48 -1); // No exceptions yet!
49 PortableInterceptor::ORBInitializer_var orb_initializer =
50 temp_initializer;
52 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
53 #endif /* TAO_HAS_INTERCEPTORS == 1 */
55 ACE_Argv_Type_Converter narrow (argc, argv);
56 CORBA::ORB_var orb =
57 CORBA::ORB_init (narrow.get_argc (), narrow.get_ASCII_argv (), "ClientORB");
59 ACE_Argv_Type_Converter wide (narrow.get_argc (), narrow.get_ASCII_argv ());
60 if (::parse_args (wide.get_argc (), wide.get_TCHAR_argv ()) != 0)
61 return -1;
63 CORBA::Object_var object =
64 orb->string_to_object (ACE_TEXT_ALWAYS_CHAR (ior));
66 hello::GoodDay_var server =
67 hello::GoodDay::_narrow (object.in ());
69 if (CORBA::is_nil (server.in ()))
71 ACE_ERROR_RETURN ((LM_ERROR,
72 ACE_TEXT ("Object reference <%s> is nil\n"),
73 ior),
74 1);
77 for (int i = 1; i <= 3; ++i)
79 ACE_DEBUG ((LM_INFO,
80 ACE_TEXT ("CLIENT: Issuing request %d.\n"),
81 i));
83 CORBA::Short number = server->number ();
85 ACE_DEBUG ((LM_INFO,
86 ACE_TEXT ("CLIENT: Request %d returns %d.\n"),
88 number));
91 server->shutdown ();
93 orb->destroy ();
95 catch (const CORBA::Exception& ex)
97 ex._tao_print_exception ("Caught exception:");
98 return -1;
101 return status;