Go to the documentation of this file.00001 #include "tao/DiffServPolicy/DiffServ_Protocols_Hooks.h"
00002 #include "tao/Stub.h"
00003 #include "tao/Profile.h"
00004 #include "tao/ORB_Core.h"
00005 #include "tao/Service_Context.h"
00006 #include "tao/CDR.h"
00007 #include "tao/SystemException.h"
00008 #include "tao/DiffServPolicy/Client_Network_Priority_Policy.h"
00009 #include "ace/OS_NS_string.h"
00010
00011 ACE_RCSID (DiffServPolicy,
00012 DiffServ_Protocols_Hooks,
00013 "$Id: DiffServ_Protocols_Hooks.cpp 84860 2009-03-17 10:17:38Z johnnyw $")
00014
00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00016
00017 TAO_DS_Network_Priority_Protocols_Hooks::
00018 TAO_DS_Network_Priority_Protocols_Hooks (void)
00019 : orb_core_ (0)
00020 {
00021 }
00022
00023
00024 TAO_DS_Network_Priority_Protocols_Hooks::
00025 ~TAO_DS_Network_Priority_Protocols_Hooks (void)
00026 {
00027 }
00028
00029 void
00030 TAO_DS_Network_Priority_Protocols_Hooks::init_hooks (TAO_ORB_Core *orb_core)
00031 {
00032 this->orb_core_ = orb_core;
00033 }
00034
00035 CORBA::Long
00036 TAO_DS_Network_Priority_Protocols_Hooks::get_dscp_codepoint (
00037 TAO_Service_Context &sc)
00038 {
00039 CORBA::Long dscp_codepoint = 0;
00040 const IOP::ServiceContext *context = 0;
00041
00042 if (sc.get_context (IOP::REP_NWPRIORITY, &context) == 1)
00043 {
00044 TAO_InputCDR cdr (reinterpret_cast
00045 <const char*>
00046 (context->context_data.get_buffer ()),
00047 context->context_data.length ());
00048
00049 CORBA::Boolean byte_order;
00050 if ((cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
00051 {
00052 throw CORBA::MARSHAL ();
00053 }
00054 cdr.reset_byte_order (static_cast<int> (byte_order));
00055
00056 if ((cdr >> dscp_codepoint) == 0)
00057 {
00058 throw CORBA::MARSHAL ();
00059 }
00060 }
00061
00062 return dscp_codepoint;
00063 }
00064
00065 CORBA::Long
00066 TAO_DS_Network_Priority_Protocols_Hooks::get_dscp_codepoint (
00067 TAO_Stub *stub, CORBA::Object *object)
00068 {
00069 CORBA::Long dscp = 0;
00070 TAO::DiffservCodepoint diffserv_codepoint;
00071 CORBA::Policy_var server_nw_priority_policy;
00072
00073 CORBA::Policy_var client_nw_priority_policy =
00074 stub->get_cached_policy (
00075 TAO_CACHED_POLICY_CLIENT_NETWORK_PRIORITY);
00076
00077 if (CORBA::is_nil (client_nw_priority_policy.in ()))
00078 {
00079 TAO_Stub *server_stub = object->_stubobj ();
00080 TAO_MProfile server_profiles = server_stub->base_profiles ();
00081 CORBA::PolicyList_var policy_list =
00082 server_profiles.policy_list ();
00083
00084 CORBA::ULong length = policy_list->length ();
00085
00086 for (CORBA::ULong i = 0; i < length; ++i)
00087 {
00088 if (policy_list[i]->policy_type () == TAO::NETWORK_PRIORITY_TYPE)
00089 {
00090 server_nw_priority_policy =
00091 CORBA::Policy::_duplicate (policy_list[i]);
00092 }
00093 }
00094
00095 if (CORBA::is_nil (server_nw_priority_policy.in ()))
00096 {
00097 return dscp;
00098 }
00099 else
00100 {
00101 TAO::NetworkPriorityPolicy_var npp =
00102 TAO::NetworkPriorityPolicy::_narrow (
00103 server_nw_priority_policy.in ());
00104
00105 if (!CORBA::is_nil (npp.in ()))
00106 {
00107 TAO::NetworkPriorityModel network_priority_model =
00108 npp->network_priority_model ();
00109
00110 if (network_priority_model ==
00111 TAO::SERVER_DECLARED_NETWORK_PRIORITY)
00112 {
00113 diffserv_codepoint =
00114 npp->request_diffserv_codepoint ();
00115 dscp = diffserv_codepoint;
00116 return dscp;
00117 }
00118 }
00119 }
00120 }
00121 else
00122 {
00123 TAO::NetworkPriorityPolicy_var client_nw_priority =
00124 TAO::NetworkPriorityPolicy::_narrow (client_nw_priority_policy.in ());
00125
00126 if (!CORBA::is_nil (client_nw_priority.in ()))
00127 {
00128 diffserv_codepoint =
00129 client_nw_priority->request_diffserv_codepoint ();
00130 dscp = diffserv_codepoint;
00131 return dscp;
00132 }
00133 }
00134
00135 return dscp;
00136 }
00137
00138
00139 ACE_STATIC_SVC_DEFINE (TAO_DS_Network_Priority_Protocols_Hooks,
00140 ACE_TEXT ("DS_Network_Priority_Protocols_Hooks"),
00141 ACE_SVC_OBJ_T,
00142 &ACE_SVC_NAME (TAO_DS_Network_Priority_Protocols_Hooks),
00143 ACE_Service_Type::DELETE_THIS
00144 | ACE_Service_Type::DELETE_OBJ,
00145 0)
00146 ACE_FACTORY_DEFINE (TAO_DiffServPolicy,
00147 TAO_DS_Network_Priority_Protocols_Hooks)
00148 TAO_END_VERSIONED_NAMESPACE_DECL