Use nullptr
[ACE_TAO.git] / TAO / tests / MProfile / client.cpp
blob3293557c49ba2edfa1b37a2c5c228001579650e4
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[])
53 try
55 CORBA::ORB_var orb =
56 CORBA::ORB_init (argc, argv);
58 if (parse_args (argc, argv) != 0)
59 return 1;
61 // Primary server
62 CORBA::Object_var object_primary =
63 orb->string_to_object (ior);
65 //Secondary server
66 CORBA::Object_var object_secondary =
67 orb->string_to_object (name);
69 // Get an object reference for the ORBs IORManipultion object!
70 CORBA::Object_ptr IORM =
71 orb->resolve_initial_references (TAO_OBJID_IORMANIPULATION,
72 0);
74 TAO_IOP::TAO_IOR_Manipulation_ptr iorm =
75 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM);
77 TAO_IOP::TAO_IOR_Manipulation::IORList iors (2);
78 iors.length(2);
79 iors [0] = object_primary;
80 iors [1] = object_secondary;
82 CORBA::Object_var merged = iorm->merge_iors (iors);
84 // Combined IOR stuff
85 Simple_Server_var server =
86 Simple_Server::_narrow (merged.in ());
88 if (CORBA::is_nil (server.in ()))
90 ACE_ERROR_RETURN ((LM_ERROR,
91 "Object reference <%s> is nil.\n",
92 ior),
93 1);
96 run_test (server.in ());
98 catch (const CORBA::Exception& ex)
100 ex._tao_print_exception ("Caught an exception\n");
101 return -1;
103 return 0;
106 void run_test (Simple_Server_ptr server)
108 for (int loop = 0; loop < 10; loop++)
112 // Make a remote call
113 CORBA::Long ret =
114 server->remote_call ();
116 ACE_UNUSED_ARG (ret);
118 ACE_OS::sleep (25);
120 catch (const CORBA::TRANSIENT& t)
122 if (t.completed () != CORBA::COMPLETED_NO)
124 t._tao_print_exception ("Unexpected kind of TRANSIENT");
126 else
128 ACE_DEBUG ((LM_DEBUG,
129 "The completed status %d\n", t.completed ()));
130 ACE_DEBUG ((LM_DEBUG,
131 "Automagically re-issuing request on TRANSIENT\n"));
132 ACE_OS::sleep (1);
135 catch (const CORBA::COMM_FAILURE& f)
137 f._tao_print_exception ("A (sort of) expected COMM_FAILURE");
138 ACE_DEBUG ((LM_DEBUG,
139 "Automagically re-issuing request on COMM_FAILURE\n"));
141 catch (const CORBA::Exception& ex)
143 ex._tao_print_exception ("Unexpected exception");
144 throw;