Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / DiffServ / client.cpp
blob4815a0b538e1b5f9d1d19e84eca081e6f5207da6
1 #include "testC.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/Policy_Manager.h"
4 #include "tao/DiffServPolicy/DiffServPolicy.h"
5 #include "tao/DiffServPolicy/Client_Network_Priority_Policy.h"
6 #include "tao/DiffServPolicy/Server_Network_Priority_Policy.h"
8 static const ACE_TCHAR *ior = ACE_TEXT("file://simple_servant.ior");
9 static int iterations = 1;
11 #define IPDSFIELD_DSCP_DEFAULT 0x00
12 #define IPDSFIELD_DSCP_CS1 0x08
13 #define IPDSFIELD_DSCP_CS2 0x10
14 #define IPDSFIELD_DSCP_CS3 0x18
15 #define IPDSFIELD_DSCP_CS4 0x20
16 #define IPDSFIELD_DSCP_CS5 0x28
17 #define IPDSFIELD_DSCP_CS6 0x30
18 #define IPDSFIELD_DSCP_CS7 0x38
19 #define IPDSFIELD_DSCP_AF11 0x0A
20 #define IPDSFIELD_DSCP_AF12 0x0C
21 #define IPDSFIELD_DSCP_AF13 0x0E
22 #define IPDSFIELD_DSCP_AF21 0x12
23 #define IPDSFIELD_DSCP_AF22 0x14
24 #define IPDSFIELD_DSCP_AF23 0x16
25 #define IPDSFIELD_DSCP_AF31 0x1A
26 #define IPDSFIELD_DSCP_AF32 0x1C
27 #define IPDSFIELD_DSCP_AF33 0x1E
28 #define IPDSFIELD_DSCP_AF41 0x22
29 #define IPDSFIELD_DSCP_AF42 0x24
30 #define IPDSFIELD_DSCP_AF43 0x26
31 #define IPDSFIELD_ECT_MASK 0x02
32 #define IPDSFIELD_CE_MASK 0x01
33 #define IPDSFIELD_DSCP_EF 0x2E
35 static int const dscp[] =
37 IPDSFIELD_DSCP_DEFAULT ,
38 IPDSFIELD_DSCP_CS1 ,
39 IPDSFIELD_DSCP_CS2 ,
40 IPDSFIELD_DSCP_CS3 ,
41 IPDSFIELD_DSCP_CS4 ,
42 IPDSFIELD_DSCP_CS5 ,
43 IPDSFIELD_DSCP_CS6 ,
44 IPDSFIELD_DSCP_CS7 ,
45 IPDSFIELD_DSCP_AF11 ,
46 IPDSFIELD_DSCP_AF12 ,
47 IPDSFIELD_DSCP_AF13 ,
48 IPDSFIELD_DSCP_AF21 ,
49 IPDSFIELD_DSCP_AF22 ,
50 IPDSFIELD_DSCP_AF23 ,
51 IPDSFIELD_DSCP_AF31 ,
52 IPDSFIELD_DSCP_AF32 ,
53 IPDSFIELD_DSCP_AF33 ,
54 IPDSFIELD_DSCP_AF41 ,
55 IPDSFIELD_DSCP_AF42 ,
56 IPDSFIELD_DSCP_AF43 ,
57 IPDSFIELD_DSCP_EF
60 int
61 parse_args (int argc, ACE_TCHAR *argv[])
63 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:n:x:"));
64 int c;
66 while ((c = get_opts ()) != -1)
67 switch (c)
69 case 'k':
70 ior = get_opts.opt_arg ();
71 break;
73 // number of itarations
74 case 'n':
75 iterations = ACE_OS::atoi (get_opts.opt_arg ());
76 break;
78 default:
79 ACE_ERROR_RETURN ((LM_ERROR,
80 "usage: %s\n"
81 "\t-k <ior> [default is %s]\n"
82 "\t-n <number of invocations> [defaults to %d]\n"
83 "\n",
84 argv [0],
85 ior,
86 iterations),
87 -1);
90 return 0;
93 int
94 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
96 try
98 CORBA::ORB_var orb =
99 CORBA::ORB_init (argc, argv);
101 if (parse_args (argc, argv) != 0)
102 return -1;
104 // Initialize and obtain reference to the Test object.
105 CORBA::Object_var client_object =
106 orb->string_to_object (ior);
108 Test_var server =
109 Test::_narrow (client_object.in ());
111 TAO::DiffservCodepoint request_dscp;
112 TAO::DiffservCodepoint reply_dscp;
113 int request_array_slot = 12;
114 int reply_array_slot = 13;
115 long request_dscp_codepoint = dscp[request_array_slot];
116 long reply_dscp_codepoint = dscp[reply_array_slot];
117 request_dscp = request_dscp_codepoint;
118 reply_dscp = reply_dscp_codepoint;
120 CORBA::PolicyList policy_list;
121 policy_list.length (1);
123 CORBA::Policy_var client_network_policy =
124 orb->_create_policy (TAO::CLIENT_NETWORK_PRIORITY_TYPE);
126 TAO::NetworkPriorityPolicy_var nw_priority =
127 TAO::NetworkPriorityPolicy::_narrow (client_network_policy.in ());
129 nw_priority->request_diffserv_codepoint (
130 request_dscp);
132 nw_priority->reply_diffserv_codepoint (
133 reply_dscp);
135 nw_priority->network_priority_model (
136 TAO::CLIENT_PROPAGATED_NETWORK_PRIORITY);
138 policy_list[0] = TAO::NetworkPriorityPolicy::_duplicate (nw_priority.in ());
140 CORBA::Object_var over_ridden_object = server->_set_policy_overrides (
141 policy_list, CORBA::SET_OVERRIDE);
143 policy_list[0]->destroy ();
145 server = Test::_narrow (over_ridden_object.in ());
147 // Make several invocation,
148 for (int i = 0; i < iterations; ++i)
150 server->test_method ();
153 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Calling shutdown on server\n"));
155 server->shutdown ();
157 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Destroying ORB\n"));
159 orb->destroy ();
161 catch (const CORBA::Exception& ex)
163 ex._tao_print_exception ("Caught exception:");
164 return -1;
167 return 0;