Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Bug_3582 / client.cpp
blob66dec2b739219cc7b01650468848556c53894b3c
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "testC.h"
5 #include "Client_ORBInitializer.h"
6 #include "tao/ORBInitializer_Registry.h"
8 const ACE_TCHAR *ior1 = 0;
9 bool interceptor_invoked = false;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 if (argc != 3) // foo -p IOR_1
15 ACE_ERROR_RETURN ((LM_ERROR,
16 "Wrong number of arguments.\n"),
17 -1);
19 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("p:"));
20 int c;
22 while ((c = get_opts ()) != -1)
23 switch (c)
25 case 'p':
26 ior1 = get_opts.opt_arg ();
27 break;
28 default:
29 ACE_ERROR_RETURN ((LM_ERROR,
30 "Usage: %s "
31 "-p IOR_1\n",
32 argv[0]),
33 -1);
36 return 0;
39 int
40 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
42 int status = 0;
44 try
46 #if TAO_HAS_INTERCEPTORS == 1
47 PortableInterceptor::ORBInitializer_ptr temp_initializer =
48 PortableInterceptor::ORBInitializer::_nil ();
50 ACE_NEW_RETURN (temp_initializer,
51 Client_ORBInitializer,
52 -1); // No exceptions yet!
53 PortableInterceptor::ORBInitializer_var orb_initializer =
54 temp_initializer;
56 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
57 #endif /* TAO_HAS_INTERCEPTORS == 1 */
59 CORBA::ORB_var orb = CORBA::ORB_init (argc,
60 argv,
61 "Client ORB");
63 if (::parse_args (argc, argv) != 0)
64 return -1;
66 CORBA::Object_var object =
67 orb->string_to_object (ior1);
69 RTTest::test_var server =
70 RTTest::test::_narrow (object.in ());
72 if (CORBA::is_nil (server.in ()))
74 ACE_ERROR_RETURN ((LM_ERROR,
75 "Object reference <%s> is nil.\n",
76 ior1),
77 1);
80 CORBA::Short number = 0;
81 for (int i = 1; i <= 2; ++i)
83 ACE_DEBUG ((LM_INFO,
84 "CLIENT: Issuing request %d.\n",
85 i));
87 number = server->number ();
89 ACE_DEBUG ((LM_INFO,
90 "CLIENT: Request %d handled by object %d.\n",
92 number));
93 ACE_OS::sleep (1);
96 server->shutdown ();
98 catch (const CORBA::Exception& ex)
100 if (!interceptor_invoked)
102 ex._tao_print_exception ("Caught exception:");
103 status = -1;
107 if (status != -1)
108 ACE_DEBUG ((LM_INFO,
109 "PortableInterceptor::Redirection test passed.\n"));
111 return status;