Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_3276_Regression / client.cpp
blob59412b4da37b87211b63200011b266a10527da71
1 #include "ace/SString.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "testC.h"
5 #include "tao/ORB_Constants.h"
7 const ACE_TCHAR *proxy_ior = 0;
8 const ACE_TCHAR *control_ior = 0;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("p:c:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'p':
20 proxy_ior = get_opts.opt_arg ();
21 break;
22 case 'c':
23 control_ior = get_opts.opt_arg ();
24 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-c <control>"
30 "-p <proxy>"
31 "\n",
32 argv [0]),
33 -1);
35 // Indicates successful parsing of the command line
36 return 0;
39 int
40 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
42 try
44 CORBA::ORB_var orb =
45 CORBA::ORB_init (argc, argv);
47 if (parse_args (argc, argv) == -1)
48 return -1;
50 CORBA::Object_var obj =
51 orb->string_to_object (proxy_ior);
53 if (obj.in () == 0)
55 ACE_ERROR_RETURN ((LM_ERROR,
56 "The received object is nil\n"),
57 -1);
60 Simple_Server_var server =
61 Simple_Server::_narrow (obj.in ());
63 if (CORBA::is_nil (server.in ()))
65 ACE_ERROR_RETURN ((LM_ERROR,
66 "Object reference is nil\n"),
67 -1);
70 try
72 while (true)
74 // Make a remote call
75 server->remote_call ();
76 ACE_OS::sleep (2);
79 catch (const CORBA::TRANSIENT& ex)
81 CORBA::ULong m = ex.minor () & 0x00000F80u;
82 if (m == TAO_INVOCATION_LOCATION_FORWARD_MINOR_CODE &&
83 ex.completed () == CORBA::COMPLETED_NO)
85 ACE_DEBUG ((LM_DEBUG,
86 "TRANSIENT caught in client as it was expected.\n"));
88 else
90 ex._tao_print_exception ("Unexpected TRANSIENT caught in client:");
91 return 2;
95 obj =
96 orb->string_to_object (control_ior);
98 if (obj.in () == 0)
100 ACE_ERROR_RETURN ((LM_ERROR,
101 "The received objref is NULL\n"),
102 -1);
105 server =
106 Simple_Server::_narrow (obj.in ());
108 server->shutdown ();
110 orb->destroy ();
112 catch (const CORBA::Exception & ex)
114 ex._tao_print_exception ("Exception caught in client:");
115 return 1;
118 return 0;