Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2925_Regression / client.cpp
blob8b7c976dce5fb8c64db7c1c2e82182b2dfe50b0e
2 #include "ace/Task.h"
3 #include "ace/Mutex.h"
4 #include "ace/Get_Opt.h"
5 #include "orbsvcs/PortableGroup/GOA.h"
6 #include "tao/Policy_Manager.h"
7 #include "tao/DiffServPolicy/DiffServPolicy.h"
8 #include "tao/DiffServPolicy/Client_Network_Priority_Policy.h"
9 #include "HelloC.h"
11 #define CLIENT_SLEEP_TIME 1000 /* in microseconds */
12 #define CLIENT_THREAD_NUMBER 32
13 #define HELLO_CALL_NUMBER 100
15 #define IPDSFIELD_DSCP_DEFAULT 0x00
16 #define IPDSFIELD_DSCP_CS1 0x08
17 #define IPDSFIELD_DSCP_CS2 0x10
18 #define IPDSFIELD_DSCP_CS3 0x18
19 #define IPDSFIELD_DSCP_CS4 0x20
20 #define IPDSFIELD_DSCP_CS5 0x28
21 #define IPDSFIELD_DSCP_CS6 0x30
22 #define IPDSFIELD_DSCP_CS7 0x38
23 #define IPDSFIELD_DSCP_AF11 0x0A
24 #define IPDSFIELD_DSCP_AF12 0x0C
25 #define IPDSFIELD_DSCP_AF13 0x0E
26 #define IPDSFIELD_DSCP_AF21 0x12
27 #define IPDSFIELD_DSCP_AF22 0x14
28 #define IPDSFIELD_DSCP_AF23 0x16
29 #define IPDSFIELD_DSCP_AF31 0x1A
30 #define IPDSFIELD_DSCP_AF32 0x1C
31 #define IPDSFIELD_DSCP_AF33 0x1E
32 #define IPDSFIELD_DSCP_AF41 0x22
33 #define IPDSFIELD_DSCP_AF42 0x24
34 #define IPDSFIELD_DSCP_AF43 0x26
35 #define IPDSFIELD_ECT_MASK 0x02
36 #define IPDSFIELD_CE_MASK 0x01
37 #define IPDSFIELD_DSCP_EF 0x2E
39 static int const dscp[] =
41 IPDSFIELD_DSCP_DEFAULT ,
42 IPDSFIELD_DSCP_CS1 ,
43 IPDSFIELD_DSCP_CS2 ,
44 IPDSFIELD_DSCP_CS3 ,
45 IPDSFIELD_DSCP_CS4 ,
46 IPDSFIELD_DSCP_CS5 ,
47 IPDSFIELD_DSCP_CS6 ,
48 IPDSFIELD_DSCP_CS7 ,
49 IPDSFIELD_DSCP_AF11 ,
50 IPDSFIELD_DSCP_AF12 ,
51 IPDSFIELD_DSCP_AF13 ,
52 IPDSFIELD_DSCP_AF21 ,
53 IPDSFIELD_DSCP_AF22 ,
54 IPDSFIELD_DSCP_AF23 ,
55 IPDSFIELD_DSCP_AF31 ,
56 IPDSFIELD_DSCP_AF32 ,
57 IPDSFIELD_DSCP_AF33 ,
58 IPDSFIELD_DSCP_AF41 ,
59 IPDSFIELD_DSCP_AF42 ,
60 IPDSFIELD_DSCP_AF43 ,
61 IPDSFIELD_DSCP_EF
64 const ACE_TCHAR *ior_file = 0;
66 void
67 test_sleep (int microsec)
69 ACE_Time_Value tv (microsec / 1000000, microsec % 1000000);
71 ACE_OS::sleep ((const ACE_Time_Value &) tv);
74 int
75 parse_args (int argc, ACE_TCHAR *argv[])
77 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
78 const unsigned char full_success = 0x01;
79 unsigned char success = 0;
83 int c = get_opts ();
84 if (success == full_success && c == -1)
85 break;
87 if (c == -1)
88 ACE_ERROR_RETURN ((LM_ERROR,
89 "usage: %s"
90 " -k <iorfile>"
91 "\n",
92 argv [0]),
93 -1);
95 switch (c)
97 case 'k':
98 ior_file = get_opts.opt_arg ();
99 success |= 0x01;
100 break;
103 while (true);
105 // Indicates successful parsing of the command line
106 return 0;
110 class ClientThread
111 : public ACE_Task_Base
113 public:
114 ClientThread (Test::Hello_ptr hello, CORBA::Short calls)
115 : hello_ (Test::Hello::_duplicate (hello))
116 , call_count_ (calls)
117 , count_ (0)
121 virtual int
122 svc ()
126 while (true)
128 CORBA::Short c = 0;
130 ACE_GUARD_RETURN (ACE_Mutex, ace_mon, this->mutex_, 0);
131 c = this->count_++;
134 if (c >= this->call_count_)
135 break;
137 this->hello_->say_hello (c);
139 ACE_DEBUG ((LM_DEBUG,
140 "%02d>>; ",
141 c));
143 test_sleep (CLIENT_SLEEP_TIME);
146 catch (const CORBA::Exception& ex)
148 ex._tao_print_exception ("Exception caught in ClientThread:");
149 return -1;
152 return 0;
155 private:
156 ACE_Mutex mutex_;
157 Test::Hello_var hello_;
158 CORBA::Short call_count_;
159 CORBA::Short count_;
164 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
168 CORBA::ORB_var orb =
169 CORBA::ORB_init (argc, argv);
171 if (parse_args (argc, argv) != 0)
172 return 2;
174 // create UIPMC reference
175 CORBA::Object_var miop_ref =
176 orb->string_to_object (ior_file);
178 // create Hello reference
179 Test::Hello_var hello =
180 Test::Hello::_unchecked_narrow (miop_ref.in ());
182 if (CORBA::is_nil (hello.in ()))
183 return 5;
185 TAO::DiffservCodepoint request_dscp = dscp[12];
186 TAO::DiffservCodepoint reply_dscp = dscp[13];
188 CORBA::PolicyList policy_list;
189 policy_list.length (1);
191 CORBA::Policy_var client_network_policy =
192 orb->_create_policy (TAO::CLIENT_NETWORK_PRIORITY_TYPE);
194 TAO::NetworkPriorityPolicy_var nw_priority =
195 TAO::NetworkPriorityPolicy::_narrow (client_network_policy.in ());
197 nw_priority->request_diffserv_codepoint (
198 request_dscp);
200 nw_priority->reply_diffserv_codepoint (
201 reply_dscp);
203 nw_priority->network_priority_model (
204 TAO::CLIENT_PROPAGATED_NETWORK_PRIORITY);
206 policy_list[0] = TAO::NetworkPriorityPolicy::_duplicate (nw_priority.in ());
208 CORBA::Object_var over_ridden_object = hello->_set_policy_overrides (
209 policy_list, CORBA::SET_OVERRIDE);
211 policy_list[0]->destroy ();
213 hello = Test::Hello::_unchecked_narrow (over_ridden_object.in ());
216 // start clients
217 ClientThread cln_thr (hello.in (), HELLO_CALL_NUMBER);
218 cln_thr.activate (THR_NEW_LWP | THR_JOINABLE, CLIENT_THREAD_NUMBER);
219 cln_thr.wait ();
222 // shutdown the server, after 10 invocations of shutdown() we can be
223 // more or less sure that server actually received that call
224 for (int i = 0; i < 10; i++)
225 hello->shutdown ();
227 orb->destroy ();
229 catch (const CORBA::Exception& ex)
231 ex._tao_print_exception ("Exception caught in client main ():");
232 return 4;
235 ACE_DEBUG ((LM_DEBUG,
236 "\n (%P|%t) client finished successfully..\n"));
237 return 0;