Go to the documentation of this file.00001
00002
00003 #include "tao/ZIOP/ZIOP_Service_Context_Handler.h"
00004
00005 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00006
00007 ACE_RCSID (ZIOP,
00008 ZIOP_Service_Context_Handler,
00009 "$Id: ZIOP_Service_Context_Handler.cpp 84919 2009-03-20 10:00:34Z johnnyw $")
00010
00011 #include "tao/CDR.h"
00012 #include "tao/Transport.h"
00013 #include "tao/ORB_Core.h"
00014 #include "tao/GIOP_Message_Base.h"
00015 #include "tao/operation_details.h"
00016 #include "tao/Stub.h"
00017 #include "tao/ZIOP/ZIOP_Policy_i.h"
00018 #include "tao/Messaging_PolicyValueC.h"
00019
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021
00022 int
00023 TAO_ZIOP_Service_Context_Handler::process_service_context (
00024 TAO_Transport&,
00025 const IOP::ServiceContext &)
00026 {
00027 return 0;
00028 }
00029
00030 int
00031 TAO_ZIOP_Service_Context_Handler::generate_service_context (
00032 TAO_Stub *stub,
00033 TAO_Transport&,
00034 TAO_Operation_Details &opdetails,
00035 TAO_Target_Specification &,
00036 TAO_OutputCDR &)
00037 {
00038 if (stub)
00039 {
00040 CORBA::Policy_var idpolicy =
00041 stub->get_cached_policy (TAO_CACHED_COMPRESSION_ID_LEVEL_LIST_POLICY);
00042
00043 CORBA::Policy_var enabledpolicy =
00044 stub->get_cached_policy (TAO_CACHED_COMPRESSION_ENABLING_POLICY);
00045
00046 ::ZIOP::CompressorIdLevelListPolicy_var idpolicyp =
00047 ::ZIOP::CompressorIdLevelListPolicy::_narrow (idpolicy.in ());
00048
00049 ::ZIOP::CompressionEnablingPolicy_var enabledpolicyp =
00050 ::ZIOP::CompressionEnablingPolicy::_narrow (enabledpolicy.in ());
00051
00052 Messaging::PolicyValueSeq policy_value_seq;
00053 policy_value_seq.length (0);
00054 TAO_OutputCDR out_CDR;
00055 CORBA::ULong i = 0;
00056 size_t length = 0;
00057
00058 if (!CORBA::is_nil (idpolicyp.in ()))
00059 {
00060 policy_value_seq.length (i + 1);
00061 policy_value_seq[i].ptype = idpolicyp->policy_type ();
00062
00063 if (!(out_CDR << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)))
00064 return 0;
00065
00066 if (!(idpolicyp->_tao_encode (out_CDR)))
00067 return 0;
00068
00069 length = out_CDR.total_length ();
00070 policy_value_seq[i].pvalue.length (static_cast <CORBA::ULong>(length));
00071 CORBA::Octet *buf = policy_value_seq[i].pvalue.get_buffer ();
00072
00073
00074 for (const ACE_Message_Block *iterator = out_CDR.begin ();
00075 iterator != 0;
00076 iterator = iterator->cont ())
00077 {
00078 ACE_OS::memcpy (buf, iterator->rd_ptr (), iterator->length ());
00079 buf += iterator->length ();
00080 }
00081 ++i;
00082 }
00083 if (!CORBA::is_nil (enabledpolicyp.in ()))
00084 {
00085 policy_value_seq.length (i + 1);
00086 policy_value_seq[i].ptype = enabledpolicyp->policy_type ();
00087
00088 if (!(out_CDR << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)))
00089 return 0;
00090
00091 if (!(enabledpolicyp->_tao_encode (out_CDR)))
00092 return 0;
00093
00094 length = out_CDR.total_length ();
00095 policy_value_seq[i].pvalue.length (static_cast <CORBA::ULong>(length));
00096 CORBA::Octet *buf = policy_value_seq[i].pvalue.get_buffer ();
00097
00098
00099 for (const ACE_Message_Block *iterator = out_CDR.begin ();
00100 iterator != 0;
00101 iterator = iterator->cont ())
00102 {
00103 ACE_OS::memcpy (buf, iterator->rd_ptr (), iterator->length ());
00104 buf += iterator->length ();
00105 }
00106 ++i;
00107 }
00108
00109 if (policy_value_seq.length () > 0)
00110 {
00111 TAO_OutputCDR out_cdr;
00112 if (!(out_cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)))
00113 return 0;
00114
00115 if (!(out_cdr << policy_value_seq))
00116 return 0;
00117
00118 opdetails.request_service_context ().set_context (IOP::INVOCATION_POLICIES, out_cdr);
00119 }
00120 }
00121
00122 return 0;
00123 }
00124
00125 TAO_END_VERSIONED_NAMESPACE_DECL
00126
00127 #endif