Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / MProfile / client.cpp
blobbd620441e42a9983ae34b8664d3460d088f9f29f
1 #include "tao/IORManipulation/IORManip_Loader.h"
2 #include "ace/SString.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_unistd.h"
5 #include "testC.h"
7 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
8 int do_shutdown = 0;
10 const ACE_TCHAR *name = ACE_TEXT("file://amba.ior");
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("xk:m:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'x':
22 do_shutdown = 1;
23 break;
25 case 'k':
26 ior = get_opts.opt_arg ();
27 break;
29 case 'm':
30 name = get_opts.opt_arg ();
31 break;
33 case '?':
34 default:
35 ACE_ERROR_RETURN ((LM_ERROR,
36 "usage: %s "
37 "-k <ior> "
38 "-i <niterations> "
39 "\n",
40 argv [0]),
41 -1);
43 // Indicates successful parsing of the command line
44 return 0;
47 void
48 run_test (Simple_Server_ptr server);
50 int
51 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
54 try
56 CORBA::ORB_var orb =
57 CORBA::ORB_init (argc, argv);
59 if (parse_args (argc, argv) != 0)
60 return 1;
62 // Primary server
63 CORBA::Object_var object_primary =
64 orb->string_to_object (ior);
66 //Secondary server
67 CORBA::Object_var object_secondary =
68 orb->string_to_object (name);
70 // Get an object reference for the ORBs IORManipultion object!
71 CORBA::Object_ptr IORM =
72 orb->resolve_initial_references (TAO_OBJID_IORMANIPULATION,
73 0);
75 TAO_IOP::TAO_IOR_Manipulation_ptr iorm =
76 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM);
78 TAO_IOP::TAO_IOR_Manipulation::IORList iors (2);
79 iors.length(2);
80 iors [0] = object_primary;
81 iors [1] = object_secondary;
83 CORBA::Object_var merged = iorm->merge_iors (iors);
85 // Combined IOR stuff
86 Simple_Server_var server =
87 Simple_Server::_narrow (merged.in ());
89 if (CORBA::is_nil (server.in ()))
91 ACE_ERROR_RETURN ((LM_ERROR,
92 "Object reference <%s> is nil.\n",
93 ior),
94 1);
97 run_test (server.in ());
99 catch (const CORBA::Exception& ex)
101 ex._tao_print_exception ("Caught an exception\n");
102 return -1;
104 return 0;
107 void run_test (Simple_Server_ptr server)
109 for (int loop = 0; loop < 10; loop++)
113 // Make a remote call
114 CORBA::Long ret =
115 server->remote_call ();
117 ACE_UNUSED_ARG (ret);
119 ACE_OS::sleep (25);
121 catch (const CORBA::TRANSIENT& t)
123 if (t.completed () != CORBA::COMPLETED_NO)
125 t._tao_print_exception ("Unexpected kind of TRANSIENT");
127 else
129 ACE_DEBUG ((LM_DEBUG,
130 "The completed status %d\n", t.completed ()));
131 ACE_DEBUG ((LM_DEBUG,
132 "Automagically re-issuing request on TRANSIENT\n"));
133 ACE_OS::sleep (1);
136 catch (const CORBA::COMM_FAILURE& f)
138 f._tao_print_exception ("A (sort of) expected COMM_FAILURE");
139 ACE_DEBUG ((LM_DEBUG,
140 "Automagically re-issuing request on COMM_FAILURE\n"));
142 catch (const CORBA::Exception& ex)
144 ex._tao_print_exception ("Unexpected exception");
145 throw;