Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Engine/OrthancPlugins.cpp @ 4495:fa2311f94d9f
IStorageArea::ReadRange()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Feb 2021 18:01:07 +0100 |
parents | 64f06e7d5fc7 |
children | 7b99e8bb8246 |
comparison
equal
deleted
inserted
replaced
4494:39192eb9b43d | 4495:fa2311f94d9f |
---|---|
61 #include "../../../OrthancFramework/Sources/Lua/LuaFunctionCall.h" | 61 #include "../../../OrthancFramework/Sources/Lua/LuaFunctionCall.h" |
62 #include "../../../OrthancFramework/Sources/MallocMemoryBuffer.h" | 62 #include "../../../OrthancFramework/Sources/MallocMemoryBuffer.h" |
63 #include "../../../OrthancFramework/Sources/MetricsRegistry.h" | 63 #include "../../../OrthancFramework/Sources/MetricsRegistry.h" |
64 #include "../../../OrthancFramework/Sources/OrthancException.h" | 64 #include "../../../OrthancFramework/Sources/OrthancException.h" |
65 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" | 65 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" |
66 #include "../../../OrthancFramework/Sources/StringMemoryBuffer.h" | |
66 #include "../../../OrthancFramework/Sources/Toolbox.h" | 67 #include "../../../OrthancFramework/Sources/Toolbox.h" |
67 #include "../../Sources/OrthancConfiguration.h" | 68 #include "../../Sources/OrthancConfiguration.h" |
68 #include "../../Sources/OrthancFindRequestHandler.h" | 69 #include "../../Sources/OrthancFindRequestHandler.h" |
69 #include "../../Sources/Search/HierarchicalMatcher.h" | 70 #include "../../Sources/Search/HierarchicalMatcher.h" |
70 #include "../../Sources/ServerContext.h" | 71 #include "../../Sources/ServerContext.h" |
209 protected: | 210 protected: |
210 PluginsErrorDictionary& GetErrorDictionary() const | 211 PluginsErrorDictionary& GetErrorDictionary() const |
211 { | 212 { |
212 return errorDictionary_; | 213 return errorDictionary_; |
213 } | 214 } |
215 | |
216 IMemoryBuffer* RangeFromWhole(const std::string& uuid, | |
217 FileContentType type, | |
218 uint64_t start /* inclusive */, | |
219 uint64_t end /* exclusive */) | |
220 { | |
221 if (start > end) | |
222 { | |
223 throw OrthancException(ErrorCode_BadRange); | |
224 } | |
225 else if (start == end) | |
226 { | |
227 return new StringMemoryBuffer; // Empty | |
228 } | |
229 else | |
230 { | |
231 std::unique_ptr<IMemoryBuffer> whole(Read(uuid, type)); | |
232 | |
233 if (start == 0 && | |
234 end == whole->GetSize()) | |
235 { | |
236 return whole.release(); | |
237 } | |
238 else if (end > whole->GetSize()) | |
239 { | |
240 throw OrthancException(ErrorCode_BadRange); | |
241 } | |
242 else | |
243 { | |
244 std::string range; | |
245 range.resize(end - start); | |
246 assert(!range.empty()); | |
247 | |
248 memcpy(&range[0], reinterpret_cast<const char*>(whole->GetData()) + start, range.size()); | |
249 | |
250 whole.reset(NULL); | |
251 return StringMemoryBuffer::CreateFromSwap(range); | |
252 } | |
253 } | |
254 } | |
214 | 255 |
215 public: | 256 public: |
216 StorageAreaBase(OrthancPluginStorageCreate create, | 257 StorageAreaBase(OrthancPluginStorageCreate create, |
217 OrthancPluginStorageRemove remove, | 258 OrthancPluginStorageRemove remove, |
218 PluginsErrorDictionary& errorDictionary) : | 259 PluginsErrorDictionary& errorDictionary) : |
304 { | 345 { |
305 GetErrorDictionary().LogError(error, true); | 346 GetErrorDictionary().LogError(error, true); |
306 throw OrthancException(static_cast<ErrorCode>(error)); | 347 throw OrthancException(static_cast<ErrorCode>(error)); |
307 } | 348 } |
308 } | 349 } |
350 | |
351 virtual IMemoryBuffer* ReadRange(const std::string& uuid, | |
352 FileContentType type, | |
353 uint64_t start /* inclusive */, | |
354 uint64_t end /* exclusive */) ORTHANC_OVERRIDE | |
355 { | |
356 return RangeFromWhole(uuid, type, start, end); | |
357 } | |
309 }; | 358 }; |
310 | 359 |
311 | 360 |
312 // New in Orthanc 1.9.0 | 361 // New in Orthanc 1.9.0 |
313 class PluginStorageArea2 : public StorageAreaBase | 362 class PluginStorageArea2 : public StorageAreaBase |
345 } | 394 } |
346 else | 395 else |
347 { | 396 { |
348 GetErrorDictionary().LogError(error, true); | 397 GetErrorDictionary().LogError(error, true); |
349 throw OrthancException(static_cast<ErrorCode>(error)); | 398 throw OrthancException(static_cast<ErrorCode>(error)); |
399 } | |
400 } | |
401 | |
402 virtual IMemoryBuffer* ReadRange(const std::string& uuid, | |
403 FileContentType type, | |
404 uint64_t start /* inclusive */, | |
405 uint64_t end /* exclusive */) ORTHANC_OVERRIDE | |
406 { | |
407 if (readRange_ == NULL) | |
408 { | |
409 return RangeFromWhole(uuid, type, start, end); | |
410 } | |
411 else | |
412 { | |
413 if (start > end) | |
414 { | |
415 throw OrthancException(ErrorCode_BadRange); | |
416 } | |
417 else if (start == end) | |
418 { | |
419 return new StringMemoryBuffer; | |
420 } | |
421 else | |
422 { | |
423 std::string range; | |
424 range.resize(end - start); | |
425 assert(!range.empty()); | |
426 | |
427 OrthancPluginMemoryBuffer64 buffer; | |
428 buffer.data = &range[0]; | |
429 buffer.size = static_cast<uint64_t>(range.size()); | |
430 | |
431 OrthancPluginErrorCode error = | |
432 readRange_(&buffer, uuid.c_str(), Plugins::Convert(type), start); | |
433 | |
434 if (error == OrthancPluginErrorCode_Success) | |
435 { | |
436 return StringMemoryBuffer::CreateFromSwap(range); | |
437 } | |
438 else | |
439 { | |
440 GetErrorDictionary().LogError(error, true); | |
441 throw OrthancException(static_cast<ErrorCode>(error)); | |
442 } | |
443 } | |
350 } | 444 } |
351 } | 445 } |
352 }; | 446 }; |
353 | 447 |
354 | 448 |