1 #include "tao/ZIOP/ZIOP_ORBInitializer.h"
2 #include "tao/ZIOP/ZIOP_Policy_Validator.h"
3 #include "tao/ZIOP/ZIOP.h"
4 #include "tao/ORB_Core.h"
6 #include "tao/ORBInitializer_Registry.h"
7 #include "tao/operation_details.h"
9 #include "tao/Transport.h"
11 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
13 TAO_ZIOP_Loader::TAO_ZIOP_Loader ()
14 : initialized_ (false)
18 TAO_ZIOP_Loader::~TAO_ZIOP_Loader ()
23 TAO_ZIOP_Loader::init (int, ACE_TCHAR
* [])
25 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
26 if (!this->initialized_
&& TAO_DEF_GIOP_MINOR
>= 2)
28 PortableInterceptor::ORBInitializer_ptr tmp_orb_initializer
=
29 PortableInterceptor::ORBInitializer::_nil ();
30 PortableInterceptor::ORBInitializer_var ziop_orb_initializer
;
34 /// Register the BiDir ORBInitializer.
35 ACE_NEW_THROW_EX (tmp_orb_initializer
,
36 TAO_ZIOP_ORBInitializer (this),
38 CORBA::SystemException::_tao_minor_code (
41 CORBA::COMPLETED_NO
));
43 ziop_orb_initializer
= tmp_orb_initializer
;
45 PortableInterceptor::register_orb_initializer (
46 ziop_orb_initializer
.in ());
48 this->initialized_
= true;
50 catch (const ::CORBA::Exception
& ex
)
52 if (TAO_debug_level
> 0)
54 ex
._tao_print_exception ("ZIOP (%P|%t) Caught exception:");
59 #endif /* TAO_HAS_CORBA_MESSAGING */
65 TAO_ZIOP_Loader::load_policy_validators (TAO_Policy_Validator
&val
)
67 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
68 // Is this true? Does the GIOP protocol version matter here?
69 if (TAO_DEF_GIOP_MINOR
< 2)
72 TAO_ZIOPPolicy_Validator
*validator
= 0;
73 ACE_NEW_THROW_EX (validator
,
74 TAO_ZIOPPolicy_Validator (val
.orb_core ()),
76 CORBA::SystemException::_tao_minor_code (
79 CORBA::COMPLETED_NO
));
81 // We may be adding another TAO_BiDirPolicy_Validator instance for
82 // the same ORB (different POA). In cases where huge numbers of
83 // bi-directional POA instances are created, having a validator
84 // instance per POA may introduce additional delays in policy
85 // validation and hence, the overal policy creation time. Since this
86 // is out of the critical invocation processing path, I plan to keep
87 // the design simple and not try to avoid an ineficiency of such
89 val
.add_validator (validator
);
90 #else /* TAO_HAS_CORBA_MESSAGING */
92 #endif /* TAO_HAS_CORBA_MESSAGING */
96 TAO_ZIOP_Loader::Initializer ()
98 return ACE_Service_Config::process_directive (ace_svc_desc_TAO_ZIOP_Loader
);
102 TAO_ZIOP_Loader::ziop_compressorid_name (::Compression::CompressorId st
)
106 case ::Compression::COMPRESSORID_NONE
: return "NONE";
107 case ::Compression::COMPRESSORID_GZIP
: return "GZIP";
108 case ::Compression::COMPRESSORID_PKZIP
: return "PKZIP";
109 case ::Compression::COMPRESSORID_BZIP2
: return "BZIP2";
110 case ::Compression::COMPRESSORID_ZLIB
: return "ZLIB";
111 case ::Compression::COMPRESSORID_LZMA
: return "LZMA";
112 case ::Compression::COMPRESSORID_LZO
: return "LZO";
113 case ::Compression::COMPRESSORID_RZIP
: return "RZIP";
114 case ::Compression::COMPRESSORID_7X
: return "7X";
115 case ::Compression::COMPRESSORID_XAR
: return "XAR";
116 case ::Compression::COMPRESSORID_RLE
: return "RLE";
123 TAO_ZIOP_Loader::dump_msg (const char *type
, const u_char
*ptr
,
124 size_t len
, size_t original_data_length
,
125 ::Compression::CompressorId compressor_id
,
126 ::Compression::CompressionLevel compression_level
)
128 if (TAO_debug_level
< 10)
133 static const char digits
[] = "0123456789ABCD";
134 int const byte_order
= ptr
[TAO_GIOP_MESSAGE_FLAGS_OFFSET
] & 0x01;
136 TAOLIB_DEBUG ((LM_DEBUG
,
137 ACE_TEXT ("ZIOP (%P|%t) ZIOP_Loader::dump_msg, ")
138 ACE_TEXT ("ZIOP message v%c.%c %C, %B data bytes, %s endian, ")
139 ACE_TEXT ("original_data_length = %B, ")
140 ACE_TEXT ("compressor = %C@%d\n"),
141 digits
[ptr
[TAO_GIOP_VERSION_MAJOR_OFFSET
]],
142 digits
[ptr
[TAO_GIOP_VERSION_MINOR_OFFSET
]],
144 len
- TAO_GIOP_MESSAGE_HEADER_LEN
,
145 (byte_order
== TAO_ENCAP_BYTE_ORDER
) ? ACE_TEXT ("my") : ACE_TEXT ("other"),
146 original_data_length
,
147 TAO_ZIOP_Loader::ziop_compressorid_name (compressor_id
),
148 static_cast <int> (compression_level
)));
150 TAOLIB_HEX_DUMP ((LM_DEBUG
,
153 ACE_TEXT ("ZIOP message")));
157 TAO_ZIOP_Loader::decompress (Compression::Compressor_ptr compressor
,
158 const ::Compression::Buffer
&source
,
159 ::Compression::Buffer
&target
)
163 compressor
->decompress (source
, target
);
165 catch (::Compression::CompressionException
&e
)
167 TAOLIB_ERROR_RETURN((LM_ERROR
,
168 ACE_TEXT ("ZIOP (%P|%t) TAO_ZIOP_Loader::decompress, ")
169 ACE_TEXT ("decompression failed, %C\n"),
170 e
._info ().c_str ()),
178 TAO_ZIOP_Loader::decompress (ACE_Data_Block
**db
, TAO_Queued_Data
& qd
,
179 TAO_ORB_Core
& orb_core
)
181 #if defined (TAO_HAS_ZIOP) && TAO_HAS_ZIOP != 0
182 CORBA::Object_var compression_manager
=
183 orb_core
.resolve_compression_manager();
185 Compression::CompressionManager_var manager
=
186 Compression::CompressionManager::_narrow (compression_manager
.in ());
188 if (!CORBA::is_nil(manager
.in ()))
190 ZIOP::CompressionData data
;
191 // first set the read pointer after the header
192 size_t begin
= qd
.msg_block ()-> rd_ptr() - qd
.msg_block ()->base ();
193 char * initial_rd_ptr
= qd
.msg_block ()-> rd_ptr();
194 size_t const wr
= qd
.msg_block ()->wr_ptr () - qd
.msg_block ()->base ();
196 TAO_InputCDR
cdr ((*db
),
197 qd
.msg_block ()->self_flags (),
198 begin
+ TAO_GIOP_MESSAGE_HEADER_LEN
,
201 qd
.giop_version ().major_version (),
202 qd
.giop_version ().minor_version (),
207 TAOLIB_DEBUG ((LM_DEBUG
, "ZIOP (%P|%t) decompress failed to demarshal data.\n"));
213 // Get hold of the required compressor to perform the decompression.
214 // NOTE: every compressor can decompress any of its own compression levels,
215 // and at this stage we do not know what level of compression was
216 // used to compress the data. (Policies are stored inside the compressed
217 // datablock so we can't look it up anyway.)
218 Compression::Compressor_var
compressor (
219 manager
->get_compressor (data
.compressor
, 0));
220 CORBA::OctetSeq myout
;
221 myout
.length (data
.original_length
);
223 if (decompress (compressor
.in (), data
.data
, myout
))
225 size_t new_data_length
= (size_t)(data
.original_length
+
226 TAO_GIOP_MESSAGE_HEADER_LEN
);
228 ACE_Message_Block
mb (new_data_length
);
229 qd
.msg_block ()->rd_ptr (initial_rd_ptr
);
230 mb
.copy (qd
.msg_block ()->base () + begin
,
231 TAO_GIOP_MESSAGE_HEADER_LEN
);
233 if (mb
.copy ((char*)myout
.get_buffer (false),
234 static_cast<size_t> (data
.original_length
)) != 0)
235 TAOLIB_ERROR_RETURN((LM_ERROR
,
236 ACE_TEXT ("ZIOP (%P|%t) ")
237 ACE_TEXT ("TAO_ZIOP_Loader::decompress, ")
238 ACE_TEXT ("failed to copy decompressed data, ")
239 ACE_TEXT ("Buffer too small\n")),
241 // change it into a GIOP message..
242 mb
.base ()[0] = 0x47;
243 ACE_CDR::mb_align (&mb
);
245 if (TAO_debug_level
> 9)
246 { // we're only logging ZIOP messages. Log datablock before it's
247 // replaced by it's decompressed datablock
248 this->dump_msg ("before decompression",
249 reinterpret_cast <u_char
*>(qd
.msg_block ()->rd_ptr ()),
250 qd
.msg_block ()->length (), data
.original_length
,
251 data
.compressor
, compressor
->compression_level ());
254 *db
= mb
.data_block ()->duplicate ();
255 (*db
)->size (new_data_length
);
259 catch (const ::Compression::UnknownCompressorId
&)
261 TAOLIB_DEBUG ((LM_DEBUG
, "ZIOP (%P|%t) client used ZIOP with an unregistered (at the server) compressor (ID %d: %C)\n",
262 static_cast <int> (data
.compressor
), TAO_ZIOP_Loader::ziop_compressorid_name (data
.compressor
)));
268 TAOLIB_DEBUG ((LM_DEBUG
, "ZIOP (%P|%t) failed to obtain compression manager\n"));
271 #else /* TAO_HAS_ZIOP */
274 ACE_UNUSED_ARG (orb_core
);
275 #endif /* TAO_HAS_ZIOP */
281 TAO_ZIOP_Loader::compression_low_value (CORBA::Policy_ptr policy
) const
283 // Default if no policy specified (No minimum, i.e. policy ignored).
284 CORBA::ULong result
= 0u;
286 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
287 if (!CORBA::is_nil (policy
))
289 ZIOP::CompressionLowValuePolicy_var
290 srp (ZIOP::CompressionLowValuePolicy::_narrow (policy
));
291 if (!CORBA::is_nil (srp
.in ()))
293 result
= srp
->low_value ();
296 #else /* TAO_HAS_CORBA_MESSAGING */
297 ACE_UNUSED_ARG (policy
);
298 #endif /* TAO_HAS_CORBA_MESSAGING */
303 Compression::CompressionRatio
304 TAO_ZIOP_Loader::compression_minratio_value (CORBA::Policy_ptr policy
) const
306 // All ratios are computed via (ratio = Compressed_size / Uncompressed_size)
307 // and so are valid between ("Smaller Size" 0.0 < ratio < 1.0 "Full size").
309 // Default if no policy specified (ratio of 1.0 = 100% message size, i.e.
310 // this policy is ignored.)
311 Compression::CompressionRatio result
= 1.00;
313 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
314 if (!CORBA::is_nil (policy
))
316 ZIOP::CompressionMinRatioPolicy_var
317 srp (ZIOP::CompressionMinRatioPolicy::_narrow (policy
));
318 if (!CORBA::is_nil (srp
.in ()))
320 result
= srp
->ratio ();
323 #else /* TAO_HAS_CORBA_MESSAGING */
324 ACE_UNUSED_ARG (policy
);
325 #endif /* TAO_HAS_CORBA_MESSAGING */
331 TAO_ZIOP_Loader::compress (Compression::Compressor_ptr compressor
,
332 const ::Compression::Buffer
&source
,
333 ::Compression::Buffer
&target
)
337 compressor
->compress (source
, target
);
339 catch (::Compression::CompressionException
&e
)
341 TAOLIB_ERROR_RETURN((LM_ERROR
,
342 ACE_TEXT ("ZIOP (%P|%t) TAO_ZIOP_Loader::compress, ")
343 ACE_TEXT ("compression failed, %C\n"),
344 e
._info ().c_str ()),
351 ::Compression::CompressionRatio
352 TAO_ZIOP_Loader::get_ratio (CORBA::OctetSeq
& uncompressed
, CORBA::OctetSeq
& compressed
)
354 // All ratios are computed via (ratio = Compressed_size / Uncompressed_size)
355 // and so are valid between ("Smaller Size" 0.0 < ratio < 1.0 "Full size").
357 return static_cast< ::Compression::CompressionRatio
> (compressed
.length ()) /
358 static_cast< ::Compression::CompressionRatio
> (uncompressed
.length ());
362 TAO_ZIOP_Loader::check_min_ratio (const ::Compression::CompressionRatio
&this_ratio
,
363 ::Compression::CompressionRatio overall_ratio
,
364 ::Compression::CompressionRatio min_ratio
) const
366 // All ratios are computed via (ratio = Compressed_size / Uncompressed_size)
367 // and so are valid between ("Smaller Size" 0.0 < ratio < 1.0 "Full size").
369 // Note we don't want to overload the receiver with messages that have not
370 // compressed enough, i.e. the achieved ratio must be at least as small as
371 // the min_ratio, (i.e. smaller ratios are better).
372 bool allow_compression
= this_ratio
<= min_ratio
;
373 if (allow_compression
)
375 if (TAO_debug_level
> 8)
377 TAOLIB_DEBUG ((LM_DEBUG
,
378 ACE_TEXT ("ZIOP (%P|%t) TAO_ZIOP_Loader::check_min_ratio, ")
379 ACE_TEXT ("this ratio (%4.2f <= %4.2f) min ratio, ")
380 ACE_TEXT ("average so far %4.2f (allowed compression).\n"),
381 this_ratio
, min_ratio
, overall_ratio
));
384 else if (TAO_debug_level
> 8)
386 TAOLIB_DEBUG ((LM_DEBUG
,
387 ACE_TEXT ("ZIOP (%P|%t) TAO_ZIOP_Loader::check_min_ratio, ")
388 ACE_TEXT ("COMPRESSION_MIN_RATIO_POLICY applied, ")
389 ACE_TEXT ("this ratio (%4.2f > %4.2f) min ratio, ")
390 ACE_TEXT ("average so far %4.2f (did not compress).\n"),
391 this_ratio
, min_ratio
, overall_ratio
));
393 return allow_compression
;
398 TAO_ZIOP_Loader::get_compressor_details (
399 ::Compression::CompressorIdLevelList
*list
,
400 Compression::CompressorId
&compressor_id
,
401 Compression::CompressionLevel
&compression_level
)
406 compressor_id
= (*list
)[0].compressor_id
;
407 compression_level
= (*list
)[0].compression_level
;
409 if (TAO_debug_level
> 6)
411 TAOLIB_DEBUG ((LM_DEBUG
,
412 ACE_TEXT ("ZIOP (%P|%t) ")
413 ACE_TEXT ("TAO_ZIOP_Loader::get_compressor_details, ")
414 ACE_TEXT ("compressor policy found, compressor = %C@%d\n"),
415 TAO_ZIOP_Loader::ziop_compressorid_name (compressor_id
),
416 static_cast<int> (compression_level
)));
422 if (TAO_debug_level
> 6)
424 TAOLIB_DEBUG ((LM_DEBUG
,
425 ACE_TEXT ("ZIOP (%P|%t) ")
426 ACE_TEXT ("TAO_ZIOP_Loader::get_compressor_details, ")
427 ACE_TEXT ("no appropriate compressor found\n")));
435 TAO_ZIOP_Loader::get_compression_details(
436 CORBA::Policy_ptr compression_enabling_policy
,
437 CORBA::Policy_ptr compression_level_list_policy
,
438 Compression::CompressorId
&compressor_id
,
439 Compression::CompressionLevel
&compression_level
)
441 bool use_ziop
= false;
442 if (!CORBA::is_nil (compression_enabling_policy
))
444 ZIOP::CompressionEnablingPolicy_var srp
=
445 ZIOP::CompressionEnablingPolicy::_narrow (compression_enabling_policy
);
447 if (!CORBA::is_nil (srp
.in ()))
449 use_ziop
= srp
->compression_enabled ();
450 if (!use_ziop
&& TAO_debug_level
> 8)
452 TAOLIB_DEBUG ((LM_DEBUG
,
453 ACE_TEXT ("ZIOP (%P|%t) ")
454 ACE_TEXT ("TAO_ZIOP_Loader::get_compression_details, ")
455 ACE_TEXT ("ZIOP enabled policy not set\n")));
461 if (TAO_debug_level
> 6)
463 TAOLIB_DEBUG ((LM_DEBUG
,
464 ACE_TEXT ("ZIOP (%P|%t) ")
465 ACE_TEXT ("TAO_ZIOP_Loader::get_compression_details, ")
466 ACE_TEXT ("compression_enabling_policy is NIL, no ZIOP\n")));
472 if (!CORBA::is_nil (compression_level_list_policy
))
474 ZIOP::CompressorIdLevelListPolicy_var srp
=
475 ZIOP::CompressorIdLevelListPolicy::_narrow (compression_level_list_policy
);
477 if (!CORBA::is_nil (srp
.in ()))
479 use_ziop
= get_compressor_details (srp
->compressor_ids (),
480 compressor_id
, compression_level
);
485 if (TAO_debug_level
> 6)
487 TAOLIB_DEBUG ((LM_DEBUG
,
488 ACE_TEXT("ZIOP (%P|%t) ")
489 ACE_TEXT("TAO_ZIOP_Loader::get_compression_details, ")
490 ACE_TEXT("compressor ID/Level list policy not found\n")));
499 TAO_ZIOP_Loader::complete_compression (Compression::Compressor_ptr compressor
,
501 ACE_Message_Block
& mb
,
502 char *initial_rd_ptr
,
503 CORBA::ULong low_value
,
504 Compression::CompressionRatio min_ratio
,
505 CORBA::ULong original_data_length
,
506 Compression::CompressorId compressor_id
)
508 static const CORBA::ULong
509 Compression_Overhead
= sizeof (compressor_id
)
510 + sizeof (original_data_length
)
511 + sizeof (CORBA::ULong
); // Compressed data Sequence length
513 // NOTE we don't want any compressed block if it is larger or equal to the
514 // original uncompressed length, we may as well use the uncompressed message
515 // in that case (we are trying to send LESS information not MORE).
517 if (low_value
<= original_data_length
)
519 CORBA::OctetSeq output
;
520 CORBA::OctetSeq
input (original_data_length
, &mb
);
521 output
.length (original_data_length
);
523 if (!this->compress (compressor
, input
, output
))
525 if (TAO_debug_level
> 0)
527 TAOLIB_DEBUG ((LM_ERROR
,
528 ACE_TEXT ("ZIOP (%P|%t) ")
529 ACE_TEXT ("TAO_ZIOP_Loader::complete_compression, ")
530 ACE_TEXT ("Compressor failed to compress message!\n")));
534 else if (original_data_length
<= output
.length () + Compression_Overhead
)
536 if (TAO_debug_level
> 8)
538 TAOLIB_DEBUG ((LM_DEBUG
,
539 ACE_TEXT ("ZIOP (%P|%t) ")
540 ACE_TEXT ("TAO_ZIOP_Loader::complete_compression, ")
541 ACE_TEXT ("compressed length (%u >= %u) ")
542 ACE_TEXT ("uncompressed length, (did not compress).\n"),
543 static_cast <unsigned int> (output
.length () + Compression_Overhead
),
544 static_cast <unsigned int> (original_data_length
)));
548 else if (this->check_min_ratio (
549 this->get_ratio (input
, output
),
550 compressor
->compression_ratio(),
553 mb
.wr_ptr (mb
.rd_ptr ());
554 cdr
.current_alignment (mb
.wr_ptr() - mb
.base ());
555 ZIOP::CompressionData data
;
556 data
.compressor
= compressor_id
;
557 data
.original_length
= input
.length();
560 mb
.rd_ptr(initial_rd_ptr
);
561 size_t begin
= (mb
.rd_ptr() - mb
.base ());
562 mb
.data_block ()->base ()[0 + begin
] = 0x5A;
563 mb
.data_block ()->base ()[TAO_GIOP_MESSAGE_SIZE_OFFSET
+ begin
] =
564 static_cast<char> (cdr
.length() - TAO_GIOP_MESSAGE_HEADER_LEN
);
566 if (TAO_debug_level
> 9)
568 this->dump_msg ("after compression", reinterpret_cast <u_char
*>(mb
.rd_ptr ()),
569 mb
.length (), data
.original_length
,
570 data
.compressor
, compressor
->compression_level ());
576 else if (TAO_debug_level
> 8)
578 TAOLIB_DEBUG ((LM_DEBUG
,
579 ACE_TEXT ("ZIOP (%P|%t) ")
580 ACE_TEXT ("TAO_ZIOP_Loader::complete_compression, ")
581 ACE_TEXT ("COMPRESSION_LOW_VALUE_POLICY applied, ")
582 ACE_TEXT ("message length %u < %u (did not compress).\n"),
583 static_cast <unsigned int> (original_data_length
),
584 static_cast <unsigned int> (low_value
)));
592 TAO_ZIOP_Loader::compress_data (TAO_OutputCDR
&cdr
,
593 CORBA::Object_ptr compression_manager
,
594 CORBA::ULong low_value
,
595 ::Compression::CompressionRatio min_ratio
,
596 ::Compression::CompressorId compressor_id
,
597 ::Compression::CompressionLevel compression_level
)
599 bool compressed
= true;
603 ACE_Message_Block
* current
= const_cast <ACE_Message_Block
*> (cdr
.current ());
605 char* initial_rd_ptr
= current
->rd_ptr();
607 // Set the read pointer to the point where the data starts
608 current
->rd_ptr (TAO_GIOP_MESSAGE_HEADER_LEN
);
610 current
= const_cast <ACE_Message_Block
*> (cdr
.current());
611 CORBA::ULong
const original_data_length
=
612 (CORBA::ULong
)(current
->wr_ptr() - current
->rd_ptr());
614 if (original_data_length
> 0)
616 Compression::CompressionManager_var manager
=
617 Compression::CompressionManager::_narrow (compression_manager
);
619 if (!CORBA::is_nil(manager
.in ()))
621 Compression::Compressor_var compressor
=
622 manager
->get_compressor (compressor_id
, compression_level
);
624 compressed
= complete_compression (compressor
.in (), cdr
, *current
,
625 initial_rd_ptr
, low_value
, min_ratio
,
626 original_data_length
, compressor_id
);
629 // set back read pointer in case no compression was done...
630 current
->rd_ptr(initial_rd_ptr
);
635 TAO_ZIOP_Loader::marshal_data (TAO_OutputCDR
&cdr
, TAO_Stub
&stub
)
637 #if defined (TAO_HAS_ZIOP) && TAO_HAS_ZIOP != 0
638 Compression::CompressorId compressor_id
= Compression::COMPRESSORID_NONE
;
639 Compression::CompressionLevel compression_level
= 0;
641 CORBA::Policy_var compression_enabling_policy
=
642 stub
.get_cached_policy (TAO_CACHED_COMPRESSION_ENABLING_POLICY
);
643 CORBA::Policy_var compression_level_list_policy
=
644 stub
.get_cached_policy (TAO_CACHED_COMPRESSION_ID_LEVEL_LIST_POLICY
);
646 if (get_compression_details (
647 compression_enabling_policy
.in (),
648 compression_level_list_policy
.in (),
652 CORBA::Object_var compression_manager
=
653 stub
.orb_core ()->resolve_compression_manager();
655 CORBA::Policy_var policy_low_value
=
656 stub
.get_cached_policy (TAO_CACHED_COMPRESSION_LOW_VALUE_POLICY
);
657 CORBA::Policy_var policy_min_ratio
=
658 stub
.get_cached_policy (TAO_CACHED_MIN_COMPRESSION_RATIO_POLICY
);
660 CORBA::ULong low_value
=
661 this->compression_low_value (policy_low_value
.in ());
662 Compression::CompressionRatio min_ratio
=
663 this->compression_minratio_value (policy_min_ratio
.in ());
665 return this->compress_data (cdr
, compression_manager
.in (),
666 low_value
, min_ratio
,
667 compressor_id
, compression_level
);
669 #else /* TAO_HAS_ZIOP */
670 ACE_UNUSED_ARG (cdr
);
671 ACE_UNUSED_ARG (stub
);
672 #endif /* TAO_HAS_ZIOP */
674 return false; // Did not compress
678 TAO_ZIOP_Loader::marshal_data (TAO_OutputCDR
&cdr
, TAO_ORB_Core
&orb_core
, TAO_ServerRequest
*request
)
680 // If there is no TAO_ServerRequest supplied, then there are no client side ZIOP policies to check.
683 if (6 < TAO_debug_level
)
685 TAOLIB_DEBUG ((LM_DEBUG
,
686 ACE_TEXT("ZIOP (%P|%t) ")
687 ACE_TEXT("TAO_ZIOP_Loader::marshal_data (server_reply), ")
688 ACE_TEXT("client policies not available (did not compress).\n")));
690 return false; // Did not compress
693 #if defined (TAO_HAS_ZIOP) && TAO_HAS_ZIOP != 0
694 // Check the client supplied the compression enabling policy for this request.
695 ::ZIOP::CompressionEnablingPolicy_var
696 check (::ZIOP::CompressionEnablingPolicy::_narrow (
697 request
->clientCompressionEnablingPolicy ()));
698 if (CORBA::is_nil (check
.in ()) || !check
->compression_enabled ())
700 if (6 < TAO_debug_level
)
702 TAOLIB_DEBUG ((LM_DEBUG
,
703 ACE_TEXT("ZIOP (%P|%t) ")
704 ACE_TEXT("TAO_ZIOP_Loader::marshal_data (server_reply), ")
705 ACE_TEXT("clientCompressionEnablingPolicy (did not compress).\n")));
707 return false; // Did not compress
710 // Check the server supplied the compression enabling policy.
711 CORBA::Policy_var
serverPolicy (
712 orb_core
.get_cached_policy_including_current (
713 TAO_CACHED_COMPRESSION_ENABLING_POLICY
));
714 check
= ::ZIOP::CompressionEnablingPolicy::_narrow (serverPolicy
.in ());
715 if (CORBA::is_nil (check
.in ()) || !check
->compression_enabled ())
717 if (6 < TAO_debug_level
)
719 TAOLIB_DEBUG ((LM_DEBUG
,
720 ACE_TEXT("ZIOP (%P|%t) ")
721 ACE_TEXT("TAO_ZIOP_Loader::marshal_data (server_reply), ")
722 ACE_TEXT("serverCompressionEnablingPolicy (did not compress).\n")));
724 return false; // Did not compress
727 // Check the client has supplied the available compressor ID list for this request.
728 ZIOP::CompressorIdLevelListPolicy_var
clientCompressors (
729 ZIOP::CompressorIdLevelListPolicy::_narrow (
730 request
->clientCompressorIdLevelListPolicy ()));
731 if (is_nil (clientCompressors
.in ()))
733 if (6 < TAO_debug_level
)
735 TAOLIB_DEBUG ((LM_DEBUG
,
736 ACE_TEXT("ZIOP (%P|%t) ")
737 ACE_TEXT("TAO_ZIOP_Loader::marshal_data (server_reply), ")
738 ACE_TEXT("no clientCompressorIdLevelListPolicy (did not compress).\n")));
740 return false; // Did not compress
742 ::Compression::CompressorIdLevelList
&clientList
=
743 *clientCompressors
->compressor_ids ();
745 // Check the server has supplied a compressor ID list.
746 serverPolicy
= orb_core
.get_cached_policy_including_current (
747 TAO_CACHED_COMPRESSION_ID_LEVEL_LIST_POLICY
);
748 ZIOP::CompressorIdLevelListPolicy_var
serverCompressors (
749 ZIOP::CompressorIdLevelListPolicy::_narrow (serverPolicy
.in ()));
750 if (is_nil (serverCompressors
.in ()))
752 if (6 < TAO_debug_level
)
754 TAOLIB_DEBUG ((LM_DEBUG
,
755 ACE_TEXT("ZIOP (%P|%t) ")
756 ACE_TEXT("TAO_ZIOP_Loader::marshal_data (server_reply), ")
757 ACE_TEXT("no serverCompressorIdLevelListPolicy (did not compress).\n")));
759 return false; // Did not compress
761 ::Compression::CompressorIdLevelList
&serverList
=
762 *serverCompressors
->compressor_ids ();
764 // Check the whole server list (in priority order)
765 for (CORBA::ULong server
= 0u; server
< serverList
.length (); ++server
)
767 ::Compression::CompressorIdLevel_var
serverEntry (serverList
[server
]);
769 // ...for the first matching client compressor that is available
770 for (CORBA::ULong client
= 0u; client
< clientList
.length (); ++client
)
772 ::Compression::CompressorIdLevel_var
clientEntry (clientList
[client
]);
773 if (serverEntry
->compressor_id
== clientEntry
->compressor_id
)
775 // Found the first matching server in the client's available list.
776 // The correct compression level to use is the smaller of the two
777 // listed compression levels.
778 Compression::CompressionLevel
779 compression_level
= ACE_MIN (serverEntry
->compression_level
,
780 clientEntry
->compression_level
);
781 if (6 < TAO_debug_level
)
783 TAOLIB_DEBUG ((LM_DEBUG
,
784 ACE_TEXT("ZIOP (%P|%t) ")
785 ACE_TEXT("TAO_ZIOP_Loader::marshal_data (server_reply), ")
786 ACE_TEXT("Found (Server %d: %C@%d == Client %d: %C@%d) using @%d.\n"),
788 this->ziop_compressorid_name (serverEntry
->compressor_id
),
789 static_cast<int> (serverEntry
->compression_level
),
791 this->ziop_compressorid_name (clientEntry
->compressor_id
),
792 static_cast<int> (clientEntry
->compression_level
),
793 static_cast<int> (compression_level
)));
796 // Obtain the other server supplied policy settings
797 serverPolicy
= orb_core
.get_cached_policy_including_current (
798 TAO_CACHED_COMPRESSION_LOW_VALUE_POLICY
);
799 CORBA::ULong low_value
=
800 this->compression_low_value (serverPolicy
.in ());
802 serverPolicy
= orb_core
.get_cached_policy_including_current (
803 TAO_CACHED_MIN_COMPRESSION_RATIO_POLICY
);
804 Compression::CompressionRatio min_ratio
=
805 this->compression_minratio_value (serverPolicy
.in ());
807 // Attempt to compress the data.
808 CORBA::Object_var
compression_manager (
809 orb_core
.resolve_compression_manager ());
810 return this->compress_data (cdr
, compression_manager
.in (),
811 low_value
, min_ratio
,
812 serverEntry
->compressor_id
,
816 if (7 < TAO_debug_level
)
818 TAOLIB_DEBUG ((LM_DEBUG
,
819 ACE_TEXT("ZIOP (%P|%t) ")
820 ACE_TEXT("TAO_ZIOP_Loader::marshal_data (server_reply), ")
821 ACE_TEXT("checking (Server %d: %C@%d != Client %d: %C@%d).\n"),
823 this->ziop_compressorid_name (serverEntry
->compressor_id
),
824 static_cast<int> (serverEntry
->compression_level
),
826 this->ziop_compressorid_name (clientEntry
->compressor_id
),
827 static_cast<int> (clientEntry
->compression_level
)));
829 } // next clientEntry
830 } // next serverEntry
832 if (6 < TAO_debug_level
)
834 TAOLIB_DEBUG ((LM_DEBUG
,
835 ACE_TEXT("ZIOP (%P|%t) ")
836 ACE_TEXT("TAO_ZIOP_Loader::marshal_data (server_reply), ")
837 ACE_TEXT("no matching CompressorIdLevelListPolicy (did not compress).\n")));
839 #else /* TAO_HAS_ZIOP */
840 ACE_UNUSED_ARG (cdr
);
841 ACE_UNUSED_ARG (orb_core
);
842 #endif /* TAO_HAS_ZIOP */
844 return false; // Did not compress
847 ACE_STATIC_SVC_DEFINE (TAO_ZIOP_Loader
,
848 ACE_TEXT ("ZIOP_Loader"),
850 &ACE_SVC_NAME (TAO_ZIOP_Loader
),
851 ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ
,
854 ACE_FACTORY_DEFINE (TAO_ZIOP
, TAO_ZIOP_Loader
)
856 TAO_END_VERSIONED_NAMESPACE_DECL