comparison Framework/PushMode/BucketPushQuery.cpp @ 0:95226b754d9e

initial release
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Sep 2018 11:34:55 +0200
parents
children 7e207ade2f1a
comparison
equal deleted inserted replaced
-1:000000000000 0:95226b754d9e
1 /**
2 * Transfers accelerator plugin for Orthanc
3 * Copyright (C) 2018 Osimis, Belgium
4 *
5 * This program is free software: you can redistribute it and/or
6 * modify it under the terms of the GNU Affero General Public License
7 * as published by the Free Software Foundation, either version 3 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 **/
18
19
20 #include "BucketPushQuery.h"
21
22 #include <Core/ChunkedBuffer.h>
23 #include <Core/Compression/GzipCompressor.h>
24
25 #include <boost/lexical_cast.hpp>
26
27
28 namespace OrthancPlugins
29 {
30 BucketPushQuery::BucketPushQuery(OrthancInstancesCache& cache,
31 const TransferBucket& bucket,
32 const std::string& peer,
33 const std::string& transactionUri,
34 size_t bucketIndex,
35 BucketCompression compression) :
36 cache_(cache),
37 bucket_(bucket),
38 peer_(peer),
39 compression_(compression)
40 {
41 uri_ = transactionUri + "/" + boost::lexical_cast<std::string>(bucketIndex);
42 }
43
44
45 void BucketPushQuery::ReadBody(std::string& body) const
46 {
47 Orthanc::ChunkedBuffer buffer;
48
49 for (size_t j = 0; j < bucket_.GetChunksCount(); j++)
50 {
51 std::string chunk;
52 std::string md5; // unused
53 cache_.GetChunk(chunk, md5, bucket_, j);
54 buffer.AddChunk(chunk);
55 }
56
57 switch (compression_)
58 {
59 case BucketCompression_None:
60 buffer.Flatten(body);
61 break;
62
63 case BucketCompression_Gzip:
64 {
65 std::string raw;
66 buffer.Flatten(raw);
67
68 Orthanc::GzipCompressor compressor;
69 Orthanc::IBufferCompressor::Compress(body, compressor, raw);
70 break;
71 }
72
73 default:
74 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
75 }
76 }
77
78
79 void BucketPushQuery::HandleAnswer(const void* answer,
80 size_t size)
81 {
82 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
83 }
84 }