From d5c3e91779887950d9f5db14f1cd5794ccbfe8f1 Mon Sep 17 00:00:00 2001 From: wolff1 Date: Thu, 16 Apr 2009 00:49:06 +0000 Subject: merged in revisions 84573 - 85094 from DOC/Middleware/trunk/TAO --- TAO/tao/ZIOP/ZIOP.cpp | 226 ++++++++++++++++++++------ TAO/tao/ZIOP/ZIOP.h | 19 ++- TAO/tao/ZIOP/ZIOP_ORBInitializer.cpp | 9 + TAO/tao/ZIOP/ZIOP_Policy_i.cpp | 8 +- TAO/tao/ZIOP/ZIOP_Service_Context_Handler.cpp | 127 +++++++++++++++ TAO/tao/ZIOP/ZIOP_Service_Context_Handler.h | 47 ++++++ TAO/tao/ZIOP/ZIOP_Stub.cpp | 75 ++++++++- 7 files changed, 439 insertions(+), 72 deletions(-) create mode 100644 TAO/tao/ZIOP/ZIOP_Service_Context_Handler.cpp create mode 100644 TAO/tao/ZIOP/ZIOP_Service_Context_Handler.h (limited to 'TAO/tao/ZIOP') diff --git a/TAO/tao/ZIOP/ZIOP.cpp b/TAO/tao/ZIOP/ZIOP.cpp index 910811b7fc9..ef689281ae5 100644 --- a/TAO/tao/ZIOP/ZIOP.cpp +++ b/TAO/tao/ZIOP/ZIOP.cpp @@ -103,6 +103,60 @@ TAO_ZIOP_Loader::Initializer (void) return ACE_Service_Config::process_directive (ace_svc_desc_TAO_ZIOP_Loader); } +const char * +TAO_ZIOP_Loader::ziop_compressorid_name (::Compression::CompressorId st) +{ + switch (st) + { + case ::Compression::COMPRESSORID_NONE: return "NONE"; + case ::Compression::COMPRESSORID_GZIP: return "GZIP"; + case ::Compression::COMPRESSORID_PKZIP: return "PKZIP"; + case ::Compression::COMPRESSORID_BZIP2: return "BZIP2"; + case ::Compression::COMPRESSORID_ZLIB: return "ZLIB"; + case ::Compression::COMPRESSORID_LZMA: return "LZMA"; + case ::Compression::COMPRESSORID_LZO: return "LZO"; + case ::Compression::COMPRESSORID_RZIP: return "RZIP"; + case ::Compression::COMPRESSORID_7X: return "7X"; + case ::Compression::COMPRESSORID_XAR: return "XAR"; + } + return "Unknown"; +} + +void +TAO_ZIOP_Loader::dump_msg (const char *type, const u_char *ptr, + size_t len, size_t original_data_length, + ::Compression::CompressorId compressor_id, + ::Compression::CompressionLevel compression_level) +{ + if (TAO_debug_level < 10) + { + return; + } + + static const char digits[] = "0123456789ABCD"; + int const byte_order = ptr[TAO_GIOP_MESSAGE_FLAGS_OFFSET] & 0x01; + CORBA::Double const ratio = 100 - (((CORBA::Double)len/original_data_length) * + (CORBA::Double) 100); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) - ZIOP_Loader::dump_msg, ") + ACE_TEXT ("ZIOP message v%c.%c %C, %d data bytes, %s endian, ") + ACE_TEXT ("original_data_length = %d, ratio = %4.2f, ") + ACE_TEXT ("compressor = %C, compression_level = %d\n"), + digits[ptr[TAO_GIOP_VERSION_MAJOR_OFFSET]], + digits[ptr[TAO_GIOP_VERSION_MINOR_OFFSET]], + type, + len - TAO_GIOP_MESSAGE_HEADER_LEN , + (byte_order == TAO_ENCAP_BYTE_ORDER) ? ACE_TEXT("my") : ACE_TEXT("other"), + original_data_length, + ratio, + TAO_ZIOP_Loader::ziop_compressorid_name(compressor_id), + compression_level)); + ACE_HEX_DUMP ((LM_DEBUG, + (const char *) ptr, + len, + ACE_TEXT ("ZIOP message"))); +} bool TAO_ZIOP_Loader::decompress (Compression::Compressor_ptr compressor, @@ -116,7 +170,8 @@ TAO_ZIOP_Loader::decompress (Compression::Compressor_ptr compressor, catch (::Compression::CompressionException &e) { ACE_ERROR_RETURN((LM_ERROR, - ACE_TEXT ("Decompression failed: %C\n"), + ACE_TEXT ("TAO (%P|%t) - TAO_ZIOP_Loader::decompress, ") + ACE_TEXT ("decompression failed, %C\n"), e._info ().c_str ()), false); } @@ -128,6 +183,12 @@ bool TAO_ZIOP_Loader::decompress (ACE_Data_Block **db, TAO_Queued_Data& qd, TAO_ORB_Core& orb_core) { +#if defined (TAO_HAS_ZIOP) && TAO_HAS_ZIOP == 0 + ACE_UNUSED_ARG (db); + ACE_UNUSED_ARG (qd); + ACE_UNUSED_ARG (orb_core); + return true; +#else CORBA::Object_var compression_manager = orb_core.resolve_compression_manager(); @@ -137,12 +198,12 @@ TAO_ZIOP_Loader::decompress (ACE_Data_Block **db, TAO_Queued_Data& qd, if (!CORBA::is_nil(manager.in ())) { ZIOP::CompressedData data; - //first set the read pointer after the header + // first set the read pointer after the header size_t begin = qd.msg_block ()-> rd_ptr() - qd.msg_block ()->base (); char * initial_rd_ptr = qd.msg_block ()-> rd_ptr(); size_t const wr = qd.msg_block ()->wr_ptr () - qd.msg_block ()->base (); - TAO_InputCDR cdr (*db, + TAO_InputCDR cdr ((*db), qd.msg_block ()->self_flags (), begin + TAO_GIOP_MESSAGE_HEADER_LEN, wr, @@ -161,27 +222,37 @@ TAO_ZIOP_Loader::decompress (ACE_Data_Block **db, TAO_Queued_Data& qd, if (decompress(compressor.in(), data.data, myout)) { - ACE_Message_Block *mb = new ACE_Message_Block(); - - mb->size ((size_t)(data.original_length + - TAO_GIOP_MESSAGE_HEADER_LEN)); + size_t new_data_length = (size_t)(data.original_length + + TAO_GIOP_MESSAGE_HEADER_LEN); + ACE_Message_Block mb (new_data_length); qd.msg_block ()->rd_ptr (initial_rd_ptr); - - mb->copy(qd.msg_block ()->base () + begin, + mb.copy(qd.msg_block ()->base () + begin, TAO_GIOP_MESSAGE_HEADER_LEN); - if (mb->copy((char*)myout.get_buffer(true), + if (mb.copy((char*)myout.get_buffer(false), (size_t)data.original_length) != 0) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("TAO - (%P|%t) - ") - ACE_TEXT ("Failed to copy decompressed data : ") + ACE_TEXT ("TAO_ZIOP_Loader::decompress, ") + ACE_TEXT ("failed to copy decompressed data, ") ACE_TEXT ("Buffer too small\n")), false); - //change it into a GIOP message.. - mb->base ()[0] = 0x47; - ACE_CDR::mb_align (mb); - *db = mb->data_block (); + // change it into a GIOP message.. + mb.base ()[0] = 0x47; + ACE_CDR::mb_align (&mb); + + if (TAO_debug_level > 9) + { // we're only logging ZIOP messages. Log datablock before it's + // replaced by it's decompressed datablock + this->dump_msg ("before decompression", + reinterpret_cast (qd.msg_block ()->rd_ptr ()), + qd.msg_block ()->length (), data.original_length, + data.compressorid, compressor->compression_level ()); + } + //replace data block + *db = mb.data_block ()->duplicate (); + (*db)->size (new_data_length); return true; } } @@ -191,6 +262,7 @@ TAO_ZIOP_Loader::decompress (ACE_Data_Block **db, TAO_Queued_Data& qd, } return true; +#endif } CORBA::ULong @@ -227,7 +299,8 @@ TAO_ZIOP_Loader::compress (Compression::Compressor_ptr compressor, catch (::Compression::CompressionException &e) { ACE_ERROR_RETURN((LM_ERROR, - ACE_TEXT ("Compression failed: %C\n"), + ACE_TEXT ("TAO (%P|%t) - TAO_ZIOP_Loader::compress, ") + ACE_TEXT ("compression failed, %C\n"), e._info ().c_str ()), false); } @@ -235,17 +308,26 @@ TAO_ZIOP_Loader::compress (Compression::Compressor_ptr compressor, return true; } +CORBA::ULong +TAO_ZIOP_Loader::get_ratio (CORBA::OctetSeq& uncompressed, CORBA::OctetSeq& compressed) +{ + return CORBA::ULong (100 - ((CORBA::Double)compressed.length () / uncompressed.length () * + (CORBA::Double)100)); +} + bool -TAO_ZIOP_Loader::check_min_ratio (::Compression::CompressionRatio ratio, +TAO_ZIOP_Loader::check_min_ratio (const CORBA::ULong& this_ratio, + ::Compression::CompressionRatio overall_ratio, CORBA::Long min_ratio) const { - bool accepted = min_ratio == 0 || ratio > min_ratio; + bool accepted = min_ratio == 0 || + static_cast < ::Compression::CompressionRatio>(this_ratio) > min_ratio; if (TAO_debug_level > 8) { ACE_ERROR ((LM_ERROR, - ACE_TEXT ("TAO (%P|%t) - TAO_ZIOP_Loader::check_min_ratio: ") - ACE_TEXT ("Ratio:%d Accepted:%d\n"), - ratio, accepted)); + ACE_TEXT ("TAO (%P|%t) - TAO_ZIOP_Loader::check_min_ratio, ") + ACE_TEXT ("overall_ratio = %d, this_ratio = %d, accepted = %d\n"), + overall_ratio, this_ratio, accepted)); } return accepted; } @@ -262,13 +344,28 @@ TAO_ZIOP_Loader::get_compressor_details ( { compressor_id = (*list)[0].compressor_id; compression_level = (*list)[0].compression_level; + + if (TAO_debug_level > 6) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) - ") + ACE_TEXT ("TAO_ZIOP_Loader::get_compressor_details,") + ACE_TEXT ("compressor policy found, compressor = %C, ") + ACE_TEXT ("compression_level = %d\n"), + TAO_ZIOP_Loader::ziop_compressorid_name (compressor_id), + compression_level)); + } + } else { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("TAO_ZIOP_Loader::get_compressor_details: ") - ACE_TEXT ("No appropriate compressor found\n"))); + if (TAO_debug_level > 6) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) - ") + ACE_TEXT ("TAO_ZIOP_Loader::get_compressor_details, ") + ACE_TEXT ("no appropriate compressor found\n"))); + } return false; } return true; @@ -294,17 +391,20 @@ TAO_ZIOP_Loader::get_compression_details( { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("TAO_ZIOP_Loader::get_compression_details: ") - ACE_TEXT ("No ZIOP policy set\n"))); + ACE_TEXT ("TAO_ZIOP_Loader::get_compression_details, ") + ACE_TEXT ("ZIOP enabled policy not set\n"))); } } } else { - ACE_ERROR((LM_ERROR, - ACE_TEXT("TAO (%P|%t) - ") - ACE_TEXT("TAO_ZIOP_Loader::get_compression_details : ") - ACE_TEXT("compression_enabling_policy is NIL. No ZIOP\n"))); + if (TAO_debug_level > 6) + { + ACE_ERROR((LM_ERROR, + ACE_TEXT ("TAO (%P|%t) - ") + ACE_TEXT ("TAO_ZIOP_Loader::get_compression_details, ") + ACE_TEXT ("compression_enabling_policy is NIL, no ZIOP\n"))); + } } if (use_ziop) @@ -320,18 +420,22 @@ TAO_ZIOP_Loader::get_compression_details( compressor_id, compression_level); } } - else + else { - ACE_ERROR((LM_ERROR, - ACE_TEXT("TAO (%P|%t) - ") - ACE_TEXT("TAO_ZIOP_Loader::get_compression_details : ") - ACE_TEXT("Compression level policy not found\n"))); + if (TAO_debug_level > 6) + { + ACE_ERROR((LM_ERROR, + ACE_TEXT("TAO (%P|%t) - ") + ACE_TEXT("TAO_ZIOP_Loader::get_compression_details, ") + ACE_TEXT("compressor ID/Level list policy not found\n"))); + } + use_ziop = false; } } return use_ziop; } -void +bool TAO_ZIOP_Loader::complete_compression (Compression::Compressor_ptr compressor, TAO_OutputCDR &cdr, ACE_Message_Block& mb, @@ -343,39 +447,50 @@ TAO_ZIOP_Loader::complete_compression (Compression::Compressor_ptr compressor, { if (low_value > 0 && original_data_length > low_value) { - CORBA::OctetSeq myout; + CORBA::OctetSeq output; CORBA::OctetSeq input (original_data_length, &mb); - myout.length (original_data_length); - - bool compressed = this->compress (compressor, input, myout); + output.length (original_data_length); - if (compressed && - (myout.length () < original_data_length) && - (this->check_min_ratio (compressor->compression_ratio(), - min_ratio))) + if (!this->compress (compressor, input, output)) + return false; + else if ((output.length () < original_data_length) && + (this->check_min_ratio (this->get_ratio (input, output), + compressor->compression_ratio(), + min_ratio))) { mb.wr_ptr (mb.rd_ptr ()); cdr.current_alignment (mb.wr_ptr() - mb.base ()); ZIOP::CompressedData data; data.compressorid = compressor_id; data.original_length = input.length(); - data.data = myout; + data.data = output; cdr << data; mb.rd_ptr(initial_rd_ptr); int begin = (mb.rd_ptr() - mb.base ()); mb.data_block ()->base ()[0 + begin] = 0x5A; mb.data_block ()->base ()[TAO_GIOP_MESSAGE_SIZE_OFFSET + begin] = cdr.length() - TAO_GIOP_MESSAGE_HEADER_LEN; + + if (TAO_debug_level > 9) + { + this->dump_msg ("after compression", reinterpret_cast (mb.rd_ptr ()), + mb.length (), data.original_length, + data.compressorid, compressor->compression_level ()); + } + } + else + return false; } else if (TAO_debug_level > 8) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("TAO_ZIOP_Loader::compress_data: ") - ACE_TEXT ("No compression used") - ACE_TEXT ("->Low Value Policy applied\n"))); + ACE_TEXT ("TAO_ZIOP_Loader::compress_data, ") + ACE_TEXT ("no compression used, ") + ACE_TEXT ("low value policy applied\n"))); } + return true; } bool @@ -386,6 +501,8 @@ TAO_ZIOP_Loader::compress_data (TAO_OutputCDR &cdr, Compression::CompressorId compressor_id, Compression::CompressionLevel compression_level) { + bool compressed = true; + cdr.consolidate (); ACE_Message_Block* current = const_cast (cdr.current ()); @@ -409,14 +526,14 @@ TAO_ZIOP_Loader::compress_data (TAO_OutputCDR &cdr, Compression::Compressor_var compressor = manager->get_compressor (compressor_id, compression_level); - complete_compression(compressor.in (), cdr, *current, + compressed = complete_compression(compressor.in (), cdr, *current, initial_rd_ptr, low_value, min_ratio, original_data_length, compressor_id); } } - //set back read pointer in case no compression was done... + // set back read pointer in case no compression was done... current->rd_ptr(initial_rd_ptr); - return true; + return compressed; } bool @@ -428,7 +545,8 @@ TAO_ZIOP_Loader::marshal_data (TAO_OutputCDR &cdr, TAO_Stub& stub) return true; #else CORBA::Boolean use_ziop = false; - Compression::CompressorId compressor_id = Compression::COMPRESSORID_ZLIB; + + Compression::CompressorId compressor_id = Compression::COMPRESSORID_NONE; Compression::CompressionLevel compression_level = 0; CORBA::Policy_var compression_enabling_policy = @@ -472,7 +590,7 @@ TAO_ZIOP_Loader::marshal_data (TAO_OutputCDR& cdr, TAO_ORB_Core& orb_core) return true; #else CORBA::Boolean use_ziop = false; - Compression::CompressorId compressor_id = Compression::COMPRESSORID_ZLIB; + Compression::CompressorId compressor_id = Compression::COMPRESSORID_NONE; Compression::CompressionLevel compression_level = 0; CORBA::Policy_var compression_enabling_policy = diff --git a/TAO/tao/ZIOP/ZIOP.h b/TAO/tao/ZIOP/ZIOP.h index f8639f3789e..1ce3ac690f7 100644 --- a/TAO/tao/ZIOP/ZIOP.h +++ b/TAO/tao/ZIOP/ZIOP.h @@ -60,6 +60,9 @@ public: /// Used to force the initialization of the ORB code. static int Initializer (void); + + /// Converts compressor ID to a compressor name. + static const char * ziop_compressorid_name (::Compression::CompressorId st); private: @@ -67,7 +70,13 @@ private: /// activated. static bool is_activated_; - /// Get the compression low value, returns 0 when it is not set + /// dump a ZIOP datablock after (de)compression + void dump_msg (const char *type, const u_char *ptr, + size_t len, size_t original_data_length, + ::Compression::CompressorId compressor_id, + ::Compression::CompressionLevel compression_level); + +/// Get the compression low value, returns 0 when it is not set CORBA::ULong compression_policy_value (CORBA::Policy_ptr policy) const; bool get_compressor_details ( @@ -80,7 +89,7 @@ private: Compression::CompressorId &compressor_id, Compression::CompressionLevel &compression_level); - void complete_compression (Compression::Compressor_ptr compressor, + bool complete_compression (Compression::Compressor_ptr compressor, TAO_OutputCDR &cdr, ACE_Message_Block& mb, char *initial_rd_ptr, @@ -103,8 +112,12 @@ private: bool decompress (Compression::Compressor_ptr compressor, const ::Compression::Buffer &source, ::Compression::Buffer &target); + + CORBA::ULong get_ratio (CORBA::OctetSeq& uncompressed, + CORBA::OctetSeq& compressed); - bool check_min_ratio (::Compression::CompressionRatio ratio, + bool check_min_ratio (const CORBA::ULong& this_ratio, + ::Compression::CompressionRatio overall_ratio, CORBA::Long min_ratio) const; }; diff --git a/TAO/tao/ZIOP/ZIOP_ORBInitializer.cpp b/TAO/tao/ZIOP/ZIOP_ORBInitializer.cpp index 0865acd51e3..9d9309925f3 100644 --- a/TAO/tao/ZIOP/ZIOP_ORBInitializer.cpp +++ b/TAO/tao/ZIOP/ZIOP_ORBInitializer.cpp @@ -7,6 +7,7 @@ #include "tao/ZIOP/ZIOP.h" #include "tao/ZIOP/ZIOP_Stub_Factory.h" #include "tao/ZIOP/ZIOP_PolicyFactory.h" +#include "tao/ZIOP/ZIOP_Service_Context_Handler.h" #include "tao/ORB_Core.h" #include "tao/PI/ORBInitInfo.h" @@ -43,6 +44,14 @@ TAO_ZIOP_ORBInitializer::pre_init (PortableInterceptor::ORBInitInfo_ptr info) // Set the name of the stub factory to be ZIOP_Stub_Factory. tao_info->orb_core ()->orb_params ()->stub_factory_name ("ZIOP_Stub_Factory"); ACE_Service_Config::process_directive (ace_svc_desc_TAO_ZIOP_Stub_Factory); + +#if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0 + // Bind the service context handler for ZIOP + TAO_ZIOP_Service_Context_Handler* h = 0; + ACE_NEW (h, + TAO_ZIOP_Service_Context_Handler()); + tao_info->orb_core ()->service_context_registry ().bind (IOP::INVOCATION_POLICIES, h); +#endif } void diff --git a/TAO/tao/ZIOP/ZIOP_Policy_i.cpp b/TAO/tao/ZIOP/ZIOP_Policy_i.cpp index c6306341d7a..8a25e5b902c 100644 --- a/TAO/tao/ZIOP/ZIOP_Policy_i.cpp +++ b/TAO/tao/ZIOP/ZIOP_Policy_i.cpp @@ -81,13 +81,7 @@ CompressorIdLevelListPolicy::destroy (void) ::Compression::CompressorIdLevelList * CompressorIdLevelListPolicy::compressor_ids (void) { - ::Compression::CompressorIdLevelList *tmp = 0; - ACE_NEW_THROW_EX (tmp, - ::Compression::CompressorIdLevelList (this->value_), - CORBA::NO_MEMORY (TAO::VMCID, - CORBA::COMPLETED_NO)); - - return tmp; + return &this->value_; } TAO_Cached_Policy_Type diff --git a/TAO/tao/ZIOP/ZIOP_Service_Context_Handler.cpp b/TAO/tao/ZIOP/ZIOP_Service_Context_Handler.cpp new file mode 100644 index 00000000000..7e0ad04cfec --- /dev/null +++ b/TAO/tao/ZIOP/ZIOP_Service_Context_Handler.cpp @@ -0,0 +1,127 @@ +// $Id$ + +#include "tao/ZIOP/ZIOP_Service_Context_Handler.h" + +#if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0 + +ACE_RCSID (ZIOP, + ZIOP_Service_Context_Handler, + "$Id$") + +#include "tao/CDR.h" +#include "tao/Transport.h" +#include "tao/ORB_Core.h" +#include "tao/GIOP_Message_Base.h" +#include "tao/operation_details.h" +#include "tao/Stub.h" +#include "tao/ZIOP/ZIOP_Policy_i.h" +#include "tao/Messaging_PolicyValueC.h" + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +int +TAO_ZIOP_Service_Context_Handler::process_service_context ( + TAO_Transport&, + const IOP::ServiceContext &) +{ + return 0; +} + +int +TAO_ZIOP_Service_Context_Handler::generate_service_context ( + TAO_Stub *stub, + TAO_Transport&, + TAO_Operation_Details &opdetails, + TAO_Target_Specification &, + TAO_OutputCDR &) +{ + if (stub) + { + CORBA::Policy_var idpolicy = + stub->get_cached_policy (TAO_CACHED_COMPRESSION_ID_LEVEL_LIST_POLICY); + + CORBA::Policy_var enabledpolicy = + stub->get_cached_policy (TAO_CACHED_COMPRESSION_ENABLING_POLICY); + + ::ZIOP::CompressorIdLevelListPolicy_var idpolicyp = + ::ZIOP::CompressorIdLevelListPolicy::_narrow (idpolicy.in ()); + + ::ZIOP::CompressionEnablingPolicy_var enabledpolicyp = + ::ZIOP::CompressionEnablingPolicy::_narrow (enabledpolicy.in ()); + + Messaging::PolicyValueSeq policy_value_seq; + policy_value_seq.length (0); + TAO_OutputCDR out_CDR; + CORBA::ULong i = 0; + size_t length = 0; + + if (!CORBA::is_nil (idpolicyp.in ())) + { + policy_value_seq.length (i + 1); + policy_value_seq[i].ptype = idpolicyp->policy_type (); + + if (!(out_CDR << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER))) + return 0; + + if (!(idpolicyp->_tao_encode (out_CDR))) + return 0; + + length = out_CDR.total_length (); + policy_value_seq[i].pvalue.length (static_cast (length)); + CORBA::Octet *buf = policy_value_seq[i].pvalue.get_buffer (); + + // Copy the CDR buffer data into the octet sequence buffer. + for (const ACE_Message_Block *iterator = out_CDR.begin (); + iterator != 0; + iterator = iterator->cont ()) + { + ACE_OS::memcpy (buf, iterator->rd_ptr (), iterator->length ()); + buf += iterator->length (); + } + ++i; + } + if (!CORBA::is_nil (enabledpolicyp.in ())) + { + policy_value_seq.length (i + 1); + policy_value_seq[i].ptype = enabledpolicyp->policy_type (); + + if (!(out_CDR << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER))) + return 0; + + if (!(enabledpolicyp->_tao_encode (out_CDR))) + return 0; + + length = out_CDR.total_length (); + policy_value_seq[i].pvalue.length (static_cast (length)); + CORBA::Octet *buf = policy_value_seq[i].pvalue.get_buffer (); + + // Copy the CDR buffer data into the octet sequence buffer. + for (const ACE_Message_Block *iterator = out_CDR.begin (); + iterator != 0; + iterator = iterator->cont ()) + { + ACE_OS::memcpy (buf, iterator->rd_ptr (), iterator->length ()); + buf += iterator->length (); + } + ++i; + } + + if (policy_value_seq.length () > 0) + { + TAO_OutputCDR out_cdr; + if (!(out_cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER))) + return 0; + + if (!(out_cdr << policy_value_seq)) + return 0; + + opdetails.request_service_context ().set_context (IOP::INVOCATION_POLICIES, out_cdr); + } + } + + return 0; +} + +TAO_END_VERSIONED_NAMESPACE_DECL + +#endif diff --git a/TAO/tao/ZIOP/ZIOP_Service_Context_Handler.h b/TAO/tao/ZIOP/ZIOP_Service_Context_Handler.h new file mode 100644 index 00000000000..24b9c6a766f --- /dev/null +++ b/TAO/tao/ZIOP/ZIOP_Service_Context_Handler.h @@ -0,0 +1,47 @@ +// -*- C++ -*- + +// =================================================================== +/** + * @file ZIOP_Service_Context_Handler.h + * + * $Id$ + * + * @author Johnny Willemsen + */ +// =================================================================== + +#ifndef TAO_ZIOP_SERVICE_CONTEXT_HANDLER_H +#define TAO_ZIOP_SERVICE_CONTEXT_HANDLER_H +#include /**/ "ace/pre.h" +#include "tao/ZIOP/ziop_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/Service_Context_Handler.h" + +#if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0 + +TAO_BEGIN_VERSIONED_NAMESPACE_DECL + +class TAO_ZIOP_Service_Context_Handler : + public TAO_Service_Context_Handler +{ +public: + virtual int process_service_context (TAO_Transport& transport, + const IOP::ServiceContext& context); + virtual int generate_service_context ( + TAO_Stub *stub, + TAO_Transport &transport, + TAO_Operation_Details &opdetails, + TAO_Target_Specification &spec, + TAO_OutputCDR &msg); +}; + +TAO_END_VERSIONED_NAMESPACE_DECL + +#endif + +#include /**/ "ace/post.h" +#endif /* TAO_ZIOP_SERVICE_CONTEXT_HANDLER_H */ diff --git a/TAO/tao/ZIOP/ZIOP_Stub.cpp b/TAO/tao/ZIOP/ZIOP_Stub.cpp index e52eb117e0f..fb245ff9cfe 100644 --- a/TAO/tao/ZIOP/ZIOP_Stub.cpp +++ b/TAO/tao/ZIOP/ZIOP_Stub.cpp @@ -5,6 +5,7 @@ #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0 #include "tao/ZIOP/ZIOP_Policy_i.h" +#include "tao/ZIOP/ZIOP.h" #include "tao/ORB_Core.h" #include "tao/Policy_Set.h" #include "tao/Policy_Manager.h" @@ -187,22 +188,80 @@ TAO_ZIOP_Stub::effective_compression_id_list_policy (void) CORBA::Policy_var exposed = this->exposed_compression_id_list_policy (); - // Reconcile client-exposed and locally set values. - if (CORBA::is_nil (exposed.in ())) - return override._retn (); - - if (CORBA::is_nil (override.in ())) - return exposed._retn (); - ZIOP::CompressorIdLevelListPolicy_var override_policy_var = ZIOP::CompressorIdLevelListPolicy::_narrow (override.in ()); ZIOP::CompressorIdLevelListPolicy_var exposed_policy_var = ZIOP::CompressorIdLevelListPolicy::_narrow (exposed.in ()); + // Reconcile client-exposed and locally set values. + if (CORBA::is_nil (exposed_policy_var.in ())) + return override._retn (); + + if (CORBA::is_nil (override_policy_var.in ())) + return exposed._retn (); + // Check which compressor id we should use and which level + for (CORBA::ULong nr_exposed = 0; + nr_exposed < exposed_policy_var->compressor_ids ()->length (); + ++nr_exposed) + { + ::Compression::CompressorIdLevel_var exposed_compressor = + exposed_policy_var->compressor_ids ()->operator [](nr_exposed); - return exposed._retn (); + if (TAO_debug_level > 9) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) - ") + ACE_TEXT ("TAO_ZIOP_Stub::effective_compression_id_list_policy, ") + ACE_TEXT ("exposed_policy = %d, compressor_id = %C, ") + ACE_TEXT ("compression_level = %d\n"), + nr_exposed, + TAO_ZIOP_Loader::ziop_compressorid_name ( + exposed_compressor.ptr ()->compressor_id), + exposed_compressor.ptr ()->compression_level)); + } + // check if a local policy matches this exposed policy + for (CORBA::ULong nr_override = 0; + nr_override < override_policy_var->compressor_ids ()->length (); + ++nr_override) + { + ::Compression::CompressorIdLevel_var override_compressor = + override_policy_var->compressor_ids ()->operator [] (nr_override); + if (TAO_debug_level > 9) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) - ") + ACE_TEXT ("TAO_ZIOP_Stub::effective_compression_id_list_policy, ") + ACE_TEXT ("checking override_policy = %d, compressor_id = %C, ") + ACE_TEXT ("compression_level = %d\n"), + nr_override, + TAO_ZIOP_Loader::ziop_compressorid_name ( + override_compressor->compressor_id), + override_compressor->compression_level)); + } + if (override_compressor->compressor_id == + exposed_compressor->compressor_id) + { + CORBA::Policy_var tmp_policy = override_policy_var->copy (); + ZIOP::CompressorIdLevelListPolicy_var idlevellist_policy_var = + ZIOP::CompressorIdLevelListPolicy::_narrow (tmp_policy.in ()); + if (CORBA::is_nil (idlevellist_policy_var.in ())) + return override._retn (); + + idlevellist_policy_var->compressor_ids ()->operator [] (0).compressor_id = + override_compressor->compressor_id; + //according to ZIOP spec, return the compressor with the lowest compression level. + idlevellist_policy_var.ptr ()->compressor_ids ()->operator [] (0).compression_level = + ACE_MIN (override_compressor->compression_level, + exposed_compressor->compression_level); + + return idlevellist_policy_var._retn (); + } + } + } + + return 0; } TAO_END_VERSIONED_NAMESPACE_DECL -- cgit v1.2.1