Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / DiffServ / server.cpp
bloba42c51ca2d68961f2110715bd5267f5e16720a20
1 #include "testS.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "tao/debug.h"
5 #include "tao/DiffServPolicy/DiffServPolicy.h"
6 #include "tao/DiffServPolicy/Server_Network_Priority_Policy.h"
7 #include "tao/DiffServPolicy/Client_Network_Priority_Policy.h"
9 #define IPDSFIELD_DSCP_DEFAULT 0x00
10 #define IPDSFIELD_DSCP_CS1 0x08
11 #define IPDSFIELD_DSCP_CS2 0x10
12 #define IPDSFIELD_DSCP_CS3 0x18
13 #define IPDSFIELD_DSCP_CS4 0x20
14 #define IPDSFIELD_DSCP_CS5 0x28
15 #define IPDSFIELD_DSCP_CS6 0x30
16 #define IPDSFIELD_DSCP_CS7 0x38
17 #define IPDSFIELD_DSCP_AF11 0x0A
18 #define IPDSFIELD_DSCP_AF12 0x0C
19 #define IPDSFIELD_DSCP_AF13 0x0E
20 #define IPDSFIELD_DSCP_AF21 0x12
21 #define IPDSFIELD_DSCP_AF22 0x14
22 #define IPDSFIELD_DSCP_AF23 0x16
23 #define IPDSFIELD_DSCP_AF31 0x1A
24 #define IPDSFIELD_DSCP_AF32 0x1C
25 #define IPDSFIELD_DSCP_AF33 0x1E
26 #define IPDSFIELD_DSCP_AF41 0x22
27 #define IPDSFIELD_DSCP_AF42 0x24
28 #define IPDSFIELD_DSCP_AF43 0x26
29 #define IPDSFIELD_ECT_MASK 0x02
30 #define IPDSFIELD_CE_MASK 0x01
31 #define IPDSFIELD_DSCP_EF 0x2E
33 static int const dscp[] =
35 IPDSFIELD_DSCP_DEFAULT ,
36 IPDSFIELD_DSCP_CS1 ,
37 IPDSFIELD_DSCP_CS2 ,
38 IPDSFIELD_DSCP_CS3 ,
39 IPDSFIELD_DSCP_CS4 ,
40 IPDSFIELD_DSCP_CS5 ,
41 IPDSFIELD_DSCP_CS6 ,
42 IPDSFIELD_DSCP_CS7 ,
43 IPDSFIELD_DSCP_AF11 ,
44 IPDSFIELD_DSCP_AF12 ,
45 IPDSFIELD_DSCP_AF13 ,
46 IPDSFIELD_DSCP_AF21 ,
47 IPDSFIELD_DSCP_AF22 ,
48 IPDSFIELD_DSCP_AF23 ,
49 IPDSFIELD_DSCP_AF31 ,
50 IPDSFIELD_DSCP_AF32 ,
51 IPDSFIELD_DSCP_AF33 ,
52 IPDSFIELD_DSCP_AF41 ,
53 IPDSFIELD_DSCP_AF42 ,
54 IPDSFIELD_DSCP_AF43 ,
55 IPDSFIELD_DSCP_EF
59 class Test_i : public POA_Test
61 public:
62 Test_i (CORBA::ORB_ptr orb);
64 void test_method ();
66 //FUZZ: disable check_for_lack_ACE_OS
67 void shutdown ();
68 //FUZZ: enable check_for_lack_ACE_OS
70 private:
71 CORBA::ORB_var orb_;
74 Test_i::Test_i (CORBA::ORB_ptr orb)
75 : orb_ (CORBA::ORB::_duplicate (orb))
79 void
80 Test_i::test_method ()
82 ACE_DEBUG ((LM_DEBUG,
83 "Test_i::test_method\n"));
86 void
87 Test_i::shutdown ()
89 this->orb_->shutdown (false);
92 static const ACE_TCHAR *simple_servant_ior_file = ACE_TEXT("simple_servant.ior");
94 int
95 parse_args (int argc, ACE_TCHAR *argv[])
97 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
98 int c;
100 while ((c = get_opts ()) != -1)
101 switch (c)
103 case 'o':
104 simple_servant_ior_file = get_opts.opt_arg ();
105 break;
107 // Indicates successful parsing of the command line
108 return 0;
111 void
112 create_object (PortableServer::POA_ptr poa,
113 CORBA::ORB_ptr orb,
114 Test_i *servant,
115 const ACE_TCHAR *filename)
117 // Register with poa.
118 PortableServer::ObjectId_var id =
119 poa->activate_object (servant);
121 CORBA::Object_var object =
122 poa->id_to_reference (id.in ());
124 CORBA::String_var ior =
125 orb->object_to_string (object.in ());
127 ACE_DEBUG ((LM_DEBUG, "<%C>\n\n", ior.in ()));
129 FILE *output_file= ACE_OS::fopen (filename, "w");
130 ACE_OS::fprintf (output_file, "%s", ior.in ());
131 ACE_OS::fclose (output_file);
135 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
139 CORBA::ORB_var orb =
140 CORBA::ORB_init (argc, argv);
142 if (parse_args (argc, argv) != 0)
143 return 1;
145 // RootPOA.
146 CORBA::Object_var object =
147 orb->resolve_initial_references ("RootPOA");
149 PortableServer::POA_var root_poa =
150 PortableServer::POA::_narrow (object.in ());
152 PortableServer::POAManager_var poa_manager =
153 root_poa->the_POAManager ();
155 TAO::DiffservCodepoint request_dscp;
156 TAO::DiffservCodepoint reply_dscp;
157 int request_array_slot = 3;
158 int reply_array_slot = 2;
159 long request_dscp_codepoint = dscp[request_array_slot];
160 long reply_dscp_codepoint = dscp[reply_array_slot];
161 request_dscp = request_dscp_codepoint;
162 reply_dscp = reply_dscp_codepoint;
164 TAO::NetworkPriorityModel npm = TAO::CLIENT_PROPAGATED_NETWORK_PRIORITY;
166 CORBA::PolicyList policy_list;
167 policy_list.length (1);
169 CORBA::Policy_var npp =
170 orb->_create_policy (TAO::NETWORK_PRIORITY_TYPE);
172 TAO::NetworkPriorityPolicy_var nw_priority =
173 TAO::NetworkPriorityPolicy::_narrow (npp.in ());
175 nw_priority->network_priority_model (npm);
177 nw_priority->request_diffserv_codepoint (request_dscp);
179 nw_priority->reply_diffserv_codepoint (reply_dscp);
181 policy_list[0] = TAO::NetworkPriorityPolicy::_duplicate (nw_priority.in ());
183 PortableServer::POA_var child_poa =
184 root_poa->create_POA ("Child_POA",
185 poa_manager.in (),
186 policy_list);
188 policy_list[0]->destroy ();
190 // Servant.
191 Test_i servant (orb.in ());
193 // Create the first object in Root POA
194 create_object (child_poa.in (),
195 orb.in (),
196 &servant,
197 simple_servant_ior_file);
199 // Activate POA manager.
200 poa_manager->activate ();
202 // Start ORB event loop.
203 orb->run ();
205 ACE_DEBUG ((LM_DEBUG, "Server ORB event loop finished\n\n"));
207 root_poa->destroy (true, true);
209 orb->destroy ();
211 catch (const CORBA::Exception& ex)
213 ex._tao_print_exception ("Unexpected exception caught:");
214 return -1;
217 return 0;