Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / RTCORBA / Private_Connection / client.cpp
blobe36c4ab63dfcf9f7f34cf8dd66d2e8ff29c985f8
1 #include "testC.h"
2 #include "tao/RTCORBA/RTCORBA.h"
3 #include "tao/Policy_ManagerC.h"
4 #include "tao/Policy_CurrentC.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior1 = ACE_TEXT("file://test1.ior");
8 const ACE_TCHAR *ior2 = ACE_TEXT("file://test2.ior");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:p:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'o':
20 ior1 = get_opts.opt_arg ();
21 break;
22 case 'p':
23 ior2 = get_opts.opt_arg ();
24 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-o <ior1> "
30 "-p <ior2> "
31 "\n",
32 argv [0]),
33 -1);
36 return 0;
39 int
40 check_for_nil (CORBA::Object_ptr obj, const char *msg)
42 if (CORBA::is_nil (obj))
43 ACE_ERROR_RETURN ((LM_ERROR,
44 "ERROR: Object reference <%C> is nil\n",
45 msg),
46 -1);
47 else
48 return 0;
51 int
52 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
54 try
56 // Initialize the ORB, resolve references and parse arguments.
58 // ORB.
59 CORBA::ORB_var orb =
60 CORBA::ORB_init (argc, argv);
62 // Parse arguments.
63 if (parse_args (argc, argv) != 0)
64 return -1;
66 // RTORB.
67 CORBA::Object_var object =
68 orb->resolve_initial_references ("RTORB");
69 RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (object.in ());
70 if (check_for_nil (rt_orb.in (), "RTORB") == -1)
71 return -1;
73 // PolicyCurrent.
74 object = orb->resolve_initial_references ("PolicyCurrent");
75 CORBA::PolicyCurrent_var policy_current =
76 CORBA::PolicyCurrent::_narrow (object.in ());
77 if (check_for_nil (policy_current.in (), "PolicyCurrent")
78 == -1)
79 return -1;
81 // Test object 1.
82 object = orb->string_to_object (ior1);
83 Test_var server1 = Test::_narrow (object.in ());
84 if (check_for_nil (server1.in (), "server1") == -1)
85 return -1;
87 // Test object 2.
88 object = orb->string_to_object (ior2);
89 Test_var server2 = Test::_narrow (object.in ());
90 if (check_for_nil (server2.in (), "server2") == -1)
91 return -1;
93 // Make four invocations on test objects. Expected: connection
94 // established on the first invocation, and reused in the
95 // following three.
96 ACE_DEBUG ((LM_DEBUG,
97 "\n Invocation 1 --> new connection\n"));
98 server1->test_method ();
100 ACE_DEBUG ((LM_DEBUG,
101 "\n Invocation 2 --> use connection from invocation 1\n"));
102 server2->test_method ();
104 ACE_DEBUG ((LM_DEBUG,
105 "\n Invocation 3 --> use connection from invocation 1\n"));
106 server1->test_method ();
108 ACE_DEBUG ((LM_DEBUG,
109 "\n Invocation 4 --> use connection from invocation 1\n"));
110 server2->test_method ();
112 // Set RTCORBA::PrivateConnectionPolicy on PolicyCurrent.
113 CORBA::PolicyList policy_list;
114 policy_list.length (1);
115 policy_list[0] =
116 rt_orb->create_private_connection_policy ();
118 policy_current->set_policy_overrides (policy_list,
119 CORBA::SET_OVERRIDE);
121 // Make four invocations on test objects again. This time,
122 // since RTCORBA::PrivateConnectionPolicy is set, we expect a
123 // connection to be established for <server1> during the first
124 // invocation, a connection to be established for <server2> during
125 // the second invocation, <server1>'s connection reused on
126 // third, and <server2>'s reused on fourth.
127 ACE_DEBUG ((LM_DEBUG,
128 "\n Invocation 5 --> new connection\n"));
129 server1->test_method ();
131 ACE_DEBUG ((LM_DEBUG,
132 "\n Invocation 6 --> new connection\n"));
133 server2->test_method ();
135 ACE_DEBUG ((LM_DEBUG,
136 "\n Invocation 7 --> use connection from invocation 5\n"));
137 server1->test_method ();
139 ACE_DEBUG ((LM_DEBUG,
140 "\n Invocation 8 --> use connection from invocation 6\n"));
141 server2->test_method ();
143 // Testing over. Shut down Server ORB.
144 ACE_DEBUG ((LM_DEBUG,
145 "\n Testing over - shutting down\n"));
146 server1->shutdown ();
148 catch (const CORBA::Exception& ex)
150 ex._tao_print_exception (
151 "Unexpected exception caught in Private_Connection test client:");
152 return -1;
155 return 0;