Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 1554:89ab71a68fcf
New function OrthancPluginBufferCompression() to (un)compress memory buffers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 Aug 2015 11:56:42 +0200 |
parents | 7c4b487b3b4a |
children | 3232f1c995a5 |
comparison
equal
deleted
inserted
replaced
1553:7c4b487b3b4a | 1554:89ab71a68fcf |
---|---|
39 #include "../../Core/OrthancException.h" | 39 #include "../../Core/OrthancException.h" |
40 #include "../../Core/Toolbox.h" | 40 #include "../../Core/Toolbox.h" |
41 #include "../../OrthancServer/OrthancInitialization.h" | 41 #include "../../OrthancServer/OrthancInitialization.h" |
42 #include "../../OrthancServer/ServerContext.h" | 42 #include "../../OrthancServer/ServerContext.h" |
43 #include "../../OrthancServer/ServerToolbox.h" | 43 #include "../../OrthancServer/ServerToolbox.h" |
44 #include "../../Core/Compression/ZlibCompressor.h" | |
45 #include "../../Core/Compression/GzipCompressor.h" | |
44 | 46 |
45 #include <boost/regex.hpp> | 47 #include <boost/regex.hpp> |
46 | 48 |
47 namespace Orthanc | 49 namespace Orthanc |
48 { | 50 { |
852 throw OrthancException(ErrorCode_InternalError); | 854 throw OrthancException(ErrorCode_InternalError); |
853 } | 855 } |
854 } | 856 } |
855 | 857 |
856 | 858 |
859 void OrthancPlugins::BufferCompression(const void* parameters) | |
860 { | |
861 const _OrthancPluginBufferCompression& p = | |
862 *reinterpret_cast<const _OrthancPluginBufferCompression*>(parameters); | |
863 | |
864 std::string result; | |
865 | |
866 { | |
867 std::auto_ptr<DeflateBaseCompressor> compressor; | |
868 | |
869 switch (p.compression) | |
870 { | |
871 case OrthancPluginCompressionType_Zlib: | |
872 { | |
873 compressor.reset(new ZlibCompressor); | |
874 compressor->SetPrefixWithUncompressedSize(false); | |
875 break; | |
876 } | |
877 | |
878 case OrthancPluginCompressionType_ZlibWithSize: | |
879 { | |
880 compressor.reset(new ZlibCompressor); | |
881 compressor->SetPrefixWithUncompressedSize(true); | |
882 break; | |
883 } | |
884 | |
885 case OrthancPluginCompressionType_Gzip: | |
886 { | |
887 compressor.reset(new GzipCompressor); | |
888 compressor->SetPrefixWithUncompressedSize(false); | |
889 break; | |
890 } | |
891 | |
892 case OrthancPluginCompressionType_GzipWithSize: | |
893 { | |
894 compressor.reset(new GzipCompressor); | |
895 compressor->SetPrefixWithUncompressedSize(true); | |
896 break; | |
897 } | |
898 | |
899 default: | |
900 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
901 } | |
902 | |
903 if (p.uncompress) | |
904 { | |
905 compressor->Uncompress(result, p.source, p.size); | |
906 } | |
907 else | |
908 { | |
909 compressor->Compress(result, p.source, p.size); | |
910 } | |
911 } | |
912 | |
913 CopyToMemoryBuffer(*p.target, result); | |
914 } | |
915 | |
916 | |
857 bool OrthancPlugins::InvokeService(_OrthancPluginService service, | 917 bool OrthancPlugins::InvokeService(_OrthancPluginService service, |
858 const void* parameters) | 918 const void* parameters) |
859 { | 919 { |
860 boost::recursive_mutex::scoped_lock lock(pimpl_->invokeServiceMutex_); | 920 boost::recursive_mutex::scoped_lock lock(pimpl_->invokeServiceMutex_); |
861 | 921 |
888 Configuration::FormatConfiguration(s); | 948 Configuration::FormatConfiguration(s); |
889 | 949 |
890 *reinterpret_cast<const _OrthancPluginRetrieveDynamicString*>(parameters)->result = CopyString(s); | 950 *reinterpret_cast<const _OrthancPluginRetrieveDynamicString*>(parameters)->result = CopyString(s); |
891 return true; | 951 return true; |
892 } | 952 } |
953 | |
954 case _OrthancPluginService_BufferCompression: | |
955 BufferCompression(parameters); | |
956 return true; | |
893 | 957 |
894 case _OrthancPluginService_RegisterRestCallback: | 958 case _OrthancPluginService_RegisterRestCallback: |
895 RegisterRestCallback(parameters); | 959 RegisterRestCallback(parameters); |
896 return true; | 960 return true; |
897 | 961 |