1 #include "tao/Compression/zlib/ZlibCompressor_Factory.h"
2 #include "tao/Compression/zlib/ZlibCompressor.h"
3 #include "ace/Min_Max.h"
6 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
10 Zlib_CompressorFactory::Zlib_CompressorFactory () :
11 ::TAO::CompressorFactory (::Compression::COMPRESSORID_ZLIB
)
15 ::Compression::Compressor_ptr
16 Zlib_CompressorFactory::get_compressor (
17 ::Compression::CompressionLevel compression_level
)
19 // Ensure Compression range 0-9 and will also convert -1(default) to 9(max).
20 compression_level
= ace_range( ::Compression::CompressionLevel(Z_NO_COMPRESSION
), // Min value
21 ::Compression::CompressionLevel(Z_BEST_COMPRESSION
), // Max value
22 compression_level
); // Argument value
24 ::Compression::Compressor_ptr compressor
= 0;
26 { // Ensure scoped lock for compressor Map container
28 ACE_GUARD_RETURN( TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
, 0 );
31 // Try and locate the compressor (we may already have it)
32 ZlibCompressorMap::iterator it
= this->compressors_
.find(compression_level
);
34 if (it
== this->compressors_
.end())
35 { // Does not yet exist so create it
36 ACE_NEW_RETURN(compressor
, ::TAO::ZlibCompressor(this, compression_level
), 0);
37 it
= this->compressors_
.insert(ZlibCompressorMap::value_type(compression_level
, compressor
)).first
;
40 compressor
= (*it
).second
.in();
42 TAOLIB_ERROR_RETURN((LM_ERROR
,
43 ACE_TEXT("(%P | %t) ERROR: ZlibCompressor - Unable to create Zlib Compressor at level [%d].\n"),
44 int(compression_level
)),0);
47 } // End of scoped container locking
49 return ::Compression::Compressor::_duplicate(compressor
);
54 TAO_END_VERSIONED_NAMESPACE_DECL