annotate Plugin/Plugin.cpp @ 4:1ed03945c057

showing unavailable peers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Sep 2018 14:42:57 +0200
parents 95226b754d9e
children 5e6de82bb10f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Transfers accelerator plugin for Orthanc
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2018 Osimis, Belgium
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 *
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * modify it under the terms of the GNU Affero General Public License
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * as published by the Free Software Foundation, either version 3 of
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * the License, or (at your option) any later version.
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 *
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful, but
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * Affero General Public License for more details.
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 *
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU Affero General Public License
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 **/
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 #include "PluginContext.h"
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 #include "../Framework/HttpQueries/DetectTransferPlugin.h"
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 #include "../Framework/PullMode/PullJob.h"
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "../Framework/PushMode/PushJob.h"
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../Framework/TransferScheduler.h"
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <EmbeddedResources.h>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <Core/ChunkedBuffer.h>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <Core/Compression/GzipCompressor.h>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <Core/Logging.h>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 static bool DisplayPerformanceWarning()
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 (void) DisplayPerformanceWarning; // Disable warning about unused function
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 LOG(WARNING) << "Performance warning in transfers accelerator: "
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 << "Non-release build, runtime debug assertions are turned on";
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 return true;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 static size_t ReadSizeArgument(const OrthancPluginHttpRequest* request,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 uint32_t index)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 std::string value(request->getValues[index]);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 try
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 int tmp = boost::lexical_cast<int>(value);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 if (tmp >= 0)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 return static_cast<size_t>(tmp);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 catch (boost::bad_lexical_cast&)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 LOG(ERROR) << "The \"" << request->getKeys[index]
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 << "\" GET argument must be a positive integer: " << value;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 void ServeChunks(OrthancPluginRestOutput* output,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 const char* url,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 const OrthancPluginHttpRequest* request)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 if (request->method != OrthancPluginHttpMethod_Get)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "GET");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 return;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 assert(request->groupsCount == 1);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 std::vector<std::string> instances;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 Orthanc::Toolbox::TokenizeString(instances, std::string(request->groups[0]), '.');
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 size_t offset = 0;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 size_t requestedSize = 0;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 OrthancPlugins::BucketCompression compression = OrthancPlugins::BucketCompression_None;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 for (uint32_t i = 0; i < request->getCount; i++)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 std::string key(request->getKeys[i]);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 if (key == "offset")
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 offset = ReadSizeArgument(request, i);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 else if (key == "size")
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 requestedSize = ReadSizeArgument(request, i);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 else if (key == "compression")
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 compression = OrthancPlugins::StringToBucketCompression(request->getValues[i]);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 else
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 LOG(INFO) << "Ignored GET argument: " << key;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 // Limit the number of clients
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 Orthanc::Semaphore::Locker lock(context.GetSemaphore());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 Orthanc::ChunkedBuffer buffer;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 for (size_t i = 0; i < instances.size() && (requestedSize == 0 ||
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 buffer.GetNumBytes() < requestedSize); i++)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 size_t instanceSize;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 std::string md5; // Ignored
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 context.GetCache().GetInstanceInfo(instanceSize, md5, instances[i]);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 if (offset >= instanceSize)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 offset -= instanceSize;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 else
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 size_t toRead;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 if (requestedSize == 0)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 toRead = instanceSize - offset;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 else
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 toRead = requestedSize - buffer.GetNumBytes();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 if (toRead > instanceSize - offset)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 toRead = instanceSize - offset;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 std::string chunk;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 std::string md5; // Ignored
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 context.GetCache().GetChunk(chunk, md5, instances[i], offset, toRead);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 buffer.AddChunk(chunk);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 offset = 0;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 assert(requestedSize == 0 ||
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 buffer.GetNumBytes() <= requestedSize);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 std::string chunk;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 buffer.Flatten(chunk);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 switch (compression)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 case OrthancPlugins::BucketCompression_None:
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, chunk.c_str(),
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 chunk.size(), "application/octet-stream");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 break;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 case OrthancPlugins::BucketCompression_Gzip:
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 std::string compressed;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 Orthanc::GzipCompressor gzip;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 //gzip.SetCompressionLevel(9);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 Orthanc::IBufferCompressor::Compress(compressed, gzip, chunk);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, compressed.c_str(),
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 compressed.size(), "application/gzip");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 break;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 default:
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 static bool ParsePostBody(Json::Value& body,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 OrthancPluginRestOutput* output,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 const OrthancPluginHttpRequest* request)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 Json::Reader reader;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 if (request->method != OrthancPluginHttpMethod_Post)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "POST");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 return false;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 else if (reader.parse(request->body, request->body + request->bodySize, body))
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 return true;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 else
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 void LookupInstances(OrthancPluginRestOutput* output,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 const char* url,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 const OrthancPluginHttpRequest* request)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 Json::Value resources;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 if (!ParsePostBody(resources, output, request))
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 return;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 OrthancPlugins::TransferScheduler scheduler;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 scheduler.ParseListOfResources(context.GetCache(), resources);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 Json::Value answer = Json::objectValue;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 answer[KEY_INSTANCES] = Json::arrayValue;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 answer[KEY_ORIGINATOR_UUID] = context.GetPluginUuid();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 answer["CountInstances"] = static_cast<uint32_t>(scheduler.GetInstancesCount());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 answer["TotalSize"] = boost::lexical_cast<std::string>(scheduler.GetTotalSize());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 answer["TotalSizeMB"] = OrthancPlugins::ConvertToMegabytes(scheduler.GetTotalSize());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 std::vector<OrthancPlugins::DicomInstanceInfo> instances;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 scheduler.ListInstances(instances);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 for (size_t i = 0; i < instances.size(); i++)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 Json::Value instance;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 instances[i].Serialize(instance);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 answer[KEY_INSTANCES].append(instance);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 Json::FastWriter writer;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 std::string s = writer.write(answer);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 static void SubmitJob(OrthancPluginRestOutput* output,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 OrthancPlugins::OrthancJob* job,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 int priority)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 std::string id = OrthancPlugins::OrthancJob::Submit(context.GetOrthanc(), job, priority);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 Json::Value result = Json::objectValue;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 result[KEY_ID] = id;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 result[KEY_PATH] = std::string(URI_JOBS) + "/" + id;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 std::string s = result.toStyledString();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 void SchedulePull(OrthancPluginRestOutput* output,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 const char* url,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 const OrthancPluginHttpRequest* request)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 Json::Value body;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 if (!ParsePostBody(body, output, request))
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 return;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 OrthancPlugins::TransferQuery query(body);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 SubmitJob(output, new OrthancPlugins::PullJob(context.GetOrthanc(), query,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 context.GetThreadsCount(),
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 context.GetTargetBucketSize()),
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 query.GetPriority());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 void CreatePush(OrthancPluginRestOutput* output,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 const char* url,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 const OrthancPluginHttpRequest* request)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 Json::Value query;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 if (!ParsePostBody(query, output, request))
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 return;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 if (query.type() != Json::objectValue ||
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 !query.isMember(KEY_BUCKETS) ||
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 !query.isMember(KEY_COMPRESSION) ||
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 !query.isMember(KEY_INSTANCES) ||
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 query[KEY_BUCKETS].type() != Json::arrayValue ||
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 query[KEY_COMPRESSION].type() != Json::stringValue ||
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 query[KEY_INSTANCES].type() != Json::arrayValue)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 std::vector<OrthancPlugins::DicomInstanceInfo> instances;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 instances.reserve(query[KEY_INSTANCES].size());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 for (Json::Value::ArrayIndex i = 0; i < query[KEY_INSTANCES].size(); i++)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 OrthancPlugins::DicomInstanceInfo instance(query[KEY_INSTANCES][i]);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 instances.push_back(instance);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 std::vector<OrthancPlugins::TransferBucket> buckets;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 buckets.reserve(query[KEY_BUCKETS].size());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 for (Json::Value::ArrayIndex i = 0; i < query[KEY_BUCKETS].size(); i++)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 OrthancPlugins::TransferBucket bucket(query[KEY_BUCKETS][i]);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 buckets.push_back(bucket);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 OrthancPlugins::BucketCompression compression =
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 OrthancPlugins::StringToBucketCompression(query[KEY_COMPRESSION].asString());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 std::string id = context.GetActivePushTransactions().CreateTransaction
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 (instances, buckets, compression);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 Json::Value result = Json::objectValue;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 result[KEY_ID] = id;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 result[KEY_PATH] = std::string(URI_PUSH) + "/" + id;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 std::string s = result.toStyledString();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 void StorePush(OrthancPluginRestOutput* output,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 const char* url,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 const OrthancPluginHttpRequest* request)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 if (request->method != OrthancPluginHttpMethod_Put)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "PUT");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 return;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 assert(request->groupsCount == 2);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 std::string transaction(request->groups[0]);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 std::string chunk(request->groups[1]);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 size_t chunkIndex;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 try
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 chunkIndex = boost::lexical_cast<size_t>(chunk);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 catch (boost::bad_lexical_cast&)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 context.GetActivePushTransactions().Store
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 (context.GetOrthanc(), transaction, chunkIndex, request->body, request->bodySize);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 std::string s = "{}";
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 void CommitPush(OrthancPluginRestOutput* output,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 const char* url,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 const OrthancPluginHttpRequest* request)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 if (request->method != OrthancPluginHttpMethod_Post)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "POST");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 return;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 assert(request->groupsCount == 1);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 std::string transaction(request->groups[0]);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 context.
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 GetActivePushTransactions().Commit(context.GetOrthanc(), transaction);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 std::string s = "{}";
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 void DiscardPush(OrthancPluginRestOutput* output,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 const char* url,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 const OrthancPluginHttpRequest* request)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 if (request->method != OrthancPluginHttpMethod_Delete)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "DELETE");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 return;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 assert(request->groupsCount == 1);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 std::string transaction(request->groups[0]);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 context.
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 GetActivePushTransactions().Discard(transaction);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 std::string s = "{}";
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 void ScheduleSend(OrthancPluginRestOutput* output,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 const char* url,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 const OrthancPluginHttpRequest* request)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 Json::Value body;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 if (!ParsePostBody(body, output, request))
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 return;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 OrthancPlugins::TransferQuery query(body);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 std::string remoteSelf; // For pull mode
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 bool pullMode = context.LookupBidirectionalPeer(remoteSelf, query.GetPeer());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 LOG(INFO) << "Sending resources to peer \"" << query.GetPeer() << "\" using "
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 << (pullMode ? "pull" : "push") << " mode";
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 if (pullMode)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 OrthancPlugins::OrthancPeers peers(context.GetOrthanc());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 Json::Value lookup = Json::objectValue;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 lookup[KEY_RESOURCES] = query.GetResources();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 lookup[KEY_COMPRESSION] = OrthancPlugins::EnumerationToString(query.GetCompression());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 lookup[KEY_ORIGINATOR_UUID] = context.GetPluginUuid();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 lookup[KEY_PEER] = remoteSelf;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 Json::FastWriter writer;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 std::string s = writer.write(lookup);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 Json::Value answer;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 if (peers.DoPost(answer, query.GetPeer(), URI_PULL, s) &&
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 answer.type() == Json::objectValue &&
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 answer.isMember(KEY_ID) &&
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 answer.isMember(KEY_PATH) &&
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 answer[KEY_ID].type() == Json::stringValue &&
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 answer[KEY_PATH].type() == Json::stringValue)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 const std::string url = peers.GetPeerUrl(query.GetPeer());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 Json::Value result = Json::objectValue;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 result[KEY_PEER] = query.GetPeer();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 result[KEY_REMOTE_JOB] = answer[KEY_ID].asString();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 result[KEY_URL] = url + answer[KEY_PATH].asString();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 std::string s = result.toStyledString();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 else
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 LOG(ERROR) << "Cannot trigger send DICOM instances using pull mode to peer: " << query.GetPeer()
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 << " (check out remote logs, and that transfer plugin is installed)";
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 else
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 SubmitJob(output, new OrthancPlugins::PushJob(context.GetOrthanc(), query,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 context.GetCache(),
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 context.GetThreadsCount(),
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 context.GetTargetBucketSize()),
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 query.GetPriority());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 OrthancPluginJob* Unserializer(const char* jobType,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 const char* serialized)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 if (jobType == NULL ||
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 serialized == NULL)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 return NULL;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 std::string type(jobType);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 if (type != JOB_TYPE_PULL &&
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 type != JOB_TYPE_PUSH)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 return NULL;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 try
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 std::string tmp(serialized);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 Json::Value source;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 Json::Reader reader;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 if (reader.parse(tmp, source))
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 OrthancPlugins::TransferQuery query(source);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 std::auto_ptr<OrthancPlugins::OrthancJob> job;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 if (type == JOB_TYPE_PULL)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 job.reset(new OrthancPlugins::PullJob(context.GetOrthanc(), query,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 context.GetThreadsCount(),
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 context.GetTargetBucketSize()));
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 else if (type == JOB_TYPE_PUSH)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 job.reset(new OrthancPlugins::PushJob(context.GetOrthanc(), query,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 context.GetCache(),
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 context.GetThreadsCount(),
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 context.GetTargetBucketSize()));
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 if (job.get() == NULL)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 else
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 return OrthancPlugins::OrthancJob::Create(context.GetOrthanc(), job.release());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 else
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 catch (Orthanc::OrthancException& e)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 LOG(ERROR) << "Error while unserializing a job from the transfers accelerator plugin: "
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 << e.What();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 return NULL;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 catch (...)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 LOG(ERROR) << "Error while unserializing a job from the transfers accelerator plugin";
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 return NULL;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 void ServePeers(OrthancPluginRestOutput* output,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 const char* url,
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 const OrthancPluginHttpRequest* request)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 OrthancPlugins::PluginContext& context = OrthancPlugins::PluginContext::GetInstance();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 if (request->method != OrthancPluginHttpMethod_Get)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 OrthancPluginSendMethodNotAllowed(context.GetOrthanc(), output, "GET");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 return;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581
4
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
582 OrthancPlugins::DetectTransferPlugin::Peers peers;
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 OrthancPlugins::DetectTransferPlugin::Apply
4
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
584 (peers, context.GetOrthanc(), context.GetThreadsCount(), 2 /* timeout */);
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
585
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
586 Json::Value result = Json::objectValue;
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
587
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
588 for (OrthancPlugins::DetectTransferPlugin::Peers::const_iterator
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
589 it = peers.begin(); it != peers.end(); ++it)
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
590 {
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
591 switch (it->second)
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
592 {
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
593 case OrthancPlugins::PeerCapabilities_Disabled:
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
594 result[it->first] = "disabled";
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
595 break;
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596
4
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
597 case OrthancPlugins::PeerCapabilities_Installed:
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
598 {
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
599 std::string remoteSelf;
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600
4
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
601 if (context.LookupBidirectionalPeer(remoteSelf, it->first))
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
602 {
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
603 result[it->first] = "installed";
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
604 }
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
605 else
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
606 {
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
607 result[it->first] = "bidirectional";
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
608 }
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
609 break;
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
610 }
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
611
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
612 default:
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
613 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
1ed03945c057 showing unavailable peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
614 }
0
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 std::string s = result.toStyledString();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 OrthancPluginAnswerBuffer(context.GetOrthanc(), output, s.c_str(), s.size(), "application/json");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 extern "C"
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 Orthanc::Logging::Initialize(context);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 assert(DisplayPerformanceWarning());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 /* Check the version of the Orthanc core */
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 if (OrthancPluginCheckVersion(context) == 0)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 LOG(ERROR) << "Your version of Orthanc ("
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 << context->orthancVersion << ") must be above "
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 << ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER << "."
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 << ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER << "."
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 << ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 << " to run this plugin";
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 return -1;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 OrthancPluginSetDescription(context, "Accelerates transfers and provides "
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 "storage commitment between Orthanc peers");
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 try
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 size_t threadsCount = 4;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 size_t targetBucketSize = 4096; // In KB
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 size_t maxPushTransactions = 4;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 size_t memoryCacheSize = 512; // In MB
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 std::map<std::string, std::string> bidirectionalPeers;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 OrthancPlugins::OrthancConfiguration config(context);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 if (config.IsSection(KEY_PLUGIN_CONFIGURATION))
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 OrthancPlugins::OrthancConfiguration plugin;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 config.GetSection(plugin, KEY_PLUGIN_CONFIGURATION);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 plugin.GetDictionary(bidirectionalPeers, KEY_BIDIRECTIONAL_PEERS);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 threadsCount = plugin.GetUnsignedIntegerValue("Threads", threadsCount);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 targetBucketSize = plugin.GetUnsignedIntegerValue("BucketSize", targetBucketSize);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 memoryCacheSize = plugin.GetUnsignedIntegerValue("CacheSize", memoryCacheSize);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 maxPushTransactions = plugin.GetUnsignedIntegerValue
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 ("MaxPushTransactions", maxPushTransactions);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 OrthancPlugins::PluginContext::Initialize
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 (context, threadsCount, targetBucketSize * KB, maxPushTransactions, memoryCacheSize * MB);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 OrthancPlugins::PluginContext::GetInstance().LoadBidirectionalPeers(bidirectionalPeers);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 OrthancPlugins::RegisterRestCallback<ServeChunks>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 (context, std::string(URI_CHUNKS) + "/([.0-9a-f-]+)", true);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 OrthancPlugins::RegisterRestCallback<LookupInstances>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 (context, URI_LOOKUP, true);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 OrthancPlugins::RegisterRestCallback<SchedulePull>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 (context, URI_PULL, true);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 OrthancPlugins::RegisterRestCallback<ScheduleSend>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 (context, URI_SEND, true);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 OrthancPlugins::RegisterRestCallback<ServePeers>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 (context, URI_PEERS, true);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 if (maxPushTransactions != 0)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 // If no push transaction is allowed, their URIs are disabled
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 OrthancPlugins::RegisterRestCallback<CreatePush>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 (context, URI_PUSH, true);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 OrthancPlugins::RegisterRestCallback<StorePush>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 (context, std::string(URI_PUSH) + "/([.0-9a-f-]+)/([0-9]+)", true);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 OrthancPlugins::RegisterRestCallback<CommitPush>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 (context, std::string(URI_PUSH) + "/([.0-9a-f-]+)/commit", true);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 OrthancPlugins::RegisterRestCallback<DiscardPush>
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 (context, std::string(URI_PUSH) + "/([.0-9a-f-]+)", true);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 OrthancPluginRegisterJobsUnserializer(context, Unserializer);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 /* Extend the default Orthanc Explorer with custom JavaScript */
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 std::string explorer;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 Orthanc::EmbeddedResources::GetFileResource
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 (explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER);
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 OrthancPluginExtendOrthancExplorer(context, explorer.c_str());
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 catch (Orthanc::OrthancException& e)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 LOG(ERROR) << "Cannot initialize transfers accelerator plugin: " << e.What();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 return -1;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 return 0;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 LOG(WARNING) << "Transfers accelerator plugin is finalizing";
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 try
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 OrthancPlugins::PluginContext::Finalize();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 catch (Orthanc::OrthancException& e)
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 LOG(ERROR) << "Error while finalizing the transfers accelerator plugin: " << e.What();
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 return PLUGIN_NAME;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 {
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 return ORTHANC_PLUGIN_VERSION;
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 }
95226b754d9e initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 }