Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / DiffServPolicy / DiffServ_Protocols_Hooks.cpp
blobdd1c246263218c087d8d47a438d91433334fa910
1 // -*- C++ -*-
2 #include "tao/DiffServPolicy/DiffServ_Protocols_Hooks.h"
3 #include "tao/Stub.h"
4 #include "tao/Profile.h"
5 #include "tao/ORB_Core.h"
6 #include "tao/Service_Context.h"
7 #include "tao/CDR.h"
8 #include "tao/SystemException.h"
9 #include "tao/DiffServPolicy/Client_Network_Priority_Policy.h"
10 #include "ace/OS_NS_string.h"
12 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
14 TAO_DS_Network_Priority_Protocols_Hooks::
15 TAO_DS_Network_Priority_Protocols_Hooks ()
16 : orb_core_ (0)
21 TAO_DS_Network_Priority_Protocols_Hooks::
22 ~TAO_DS_Network_Priority_Protocols_Hooks ()
26 void
27 TAO_DS_Network_Priority_Protocols_Hooks::init_hooks (TAO_ORB_Core *orb_core)
29 this->orb_core_ = orb_core;
32 CORBA::Long
33 TAO_DS_Network_Priority_Protocols_Hooks::get_dscp_codepoint (
34 TAO_Service_Context &sc)
36 CORBA::Long dscp_codepoint = 0;
37 const IOP::ServiceContext *context = 0;
39 if (sc.get_context (IOP::REP_NWPRIORITY, &context) == 1)
41 TAO_InputCDR cdr (reinterpret_cast
42 <const char*>
43 (context->context_data.get_buffer ()),
44 context->context_data.length ());
46 CORBA::Boolean byte_order;
47 if ((cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
49 throw CORBA::MARSHAL ();
51 cdr.reset_byte_order (static_cast<int> (byte_order));
53 if ((cdr >> dscp_codepoint) == 0)
55 throw CORBA::MARSHAL ();
59 return dscp_codepoint;
62 CORBA::Long
63 TAO_DS_Network_Priority_Protocols_Hooks::get_dscp_codepoint (
64 TAO_Stub *stub, CORBA::Object *object)
66 CORBA::Long dscp = 0;
67 TAO::DiffservCodepoint diffserv_codepoint;
68 CORBA::Policy_var server_nw_priority_policy;
70 CORBA::Policy_var client_nw_priority_policy =
71 stub->get_cached_policy (
72 TAO_CACHED_POLICY_CLIENT_NETWORK_PRIORITY);
74 if (CORBA::is_nil (client_nw_priority_policy.in ()))
76 TAO_Stub *server_stub = object->_stubobj ();
77 TAO_MProfile server_profiles = server_stub->base_profiles ();
78 CORBA::PolicyList_var policy_list =
79 server_profiles.policy_list ();
81 CORBA::ULong length = policy_list->length ();
83 for (CORBA::ULong i = 0; i < length; ++i)
85 if (policy_list[i]->policy_type () == TAO::NETWORK_PRIORITY_TYPE)
87 server_nw_priority_policy =
88 CORBA::Policy::_duplicate (policy_list[i]);
92 if (CORBA::is_nil (server_nw_priority_policy.in ()))
94 return dscp;
96 else
98 TAO::NetworkPriorityPolicy_var npp =
99 TAO::NetworkPriorityPolicy::_narrow (
100 server_nw_priority_policy.in ());
102 if (!CORBA::is_nil (npp.in ()))
104 TAO::NetworkPriorityModel network_priority_model =
105 npp->network_priority_model ();
107 if (network_priority_model ==
108 TAO::SERVER_DECLARED_NETWORK_PRIORITY)
110 diffserv_codepoint =
111 npp->request_diffserv_codepoint ();
112 dscp = diffserv_codepoint;
113 return dscp;
118 else
120 TAO::NetworkPriorityPolicy_var client_nw_priority =
121 TAO::NetworkPriorityPolicy::_narrow (client_nw_priority_policy.in ());
123 if (!CORBA::is_nil (client_nw_priority.in ()))
125 diffserv_codepoint =
126 client_nw_priority->request_diffserv_codepoint ();
127 dscp = diffserv_codepoint;
128 return dscp;
132 return dscp;
136 ACE_STATIC_SVC_DEFINE (TAO_DS_Network_Priority_Protocols_Hooks,
137 ACE_TEXT ("DS_Network_Priority_Protocols_Hooks"),
138 ACE_SVC_OBJ_T,
139 &ACE_SVC_NAME (TAO_DS_Network_Priority_Protocols_Hooks),
140 ACE_Service_Type::DELETE_THIS
141 | ACE_Service_Type::DELETE_OBJ,
143 ACE_FACTORY_DEFINE (TAO_DiffServPolicy,
144 TAO_DS_Network_Priority_Protocols_Hooks)
145 TAO_END_VERSIONED_NAMESPACE_DECL