Mercurial > hg > orthanc
comparison Core/FileStorage/StorageAccessor.h @ 1549:e5e975e9b738
refactoring and simplification of StorageAccessor
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 17 Aug 2015 10:47:04 +0200 |
parents | 6e7e5ed91c2d |
children | 55d52567bebb |
comparison
equal
deleted
inserted
replaced
1548:e9325f3ac496 | 1549:e5e975e9b738 |
---|---|
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #pragma once | 33 #pragma once |
34 | 34 |
35 #include "IStorageArea.h" | |
35 #include "FileInfo.h" | 36 #include "FileInfo.h" |
36 #include "../HttpServer/HttpFileSender.h" | 37 #include "../HttpServer/BufferHttpSender.h" |
38 #include "../RestApi/RestApiOutput.h" | |
37 | 39 |
38 #include <vector> | 40 #include <vector> |
39 #include <string> | 41 #include <string> |
40 #include <boost/noncopyable.hpp> | 42 #include <boost/noncopyable.hpp> |
41 #include <stdint.h> | 43 #include <stdint.h> |
42 | 44 |
43 namespace Orthanc | 45 namespace Orthanc |
44 { | 46 { |
45 class StorageAccessor : boost::noncopyable | 47 class StorageAccessor : boost::noncopyable |
46 { | 48 { |
47 protected: | 49 private: |
48 bool storeMD5_; | 50 IStorageArea& area_; |
49 | 51 |
50 virtual FileInfo WriteInternal(const void* data, | 52 void SetupSender(BufferHttpSender& sender, |
51 size_t size, | 53 const FileInfo& info); |
52 FileContentType type) = 0; | |
53 | 54 |
54 public: | 55 public: |
55 StorageAccessor() | 56 StorageAccessor(IStorageArea& area) : area_(area) |
56 { | 57 { |
57 storeMD5_ = true; | |
58 } | |
59 | |
60 virtual ~StorageAccessor() | |
61 { | |
62 } | |
63 | |
64 void SetStoreMD5(bool storeMD5) | |
65 { | |
66 storeMD5_ = storeMD5; | |
67 } | |
68 | |
69 bool IsStoreMD5() const | |
70 { | |
71 return storeMD5_; | |
72 } | 58 } |
73 | 59 |
74 FileInfo Write(const void* data, | 60 FileInfo Write(const void* data, |
75 size_t size, | 61 size_t size, |
76 FileContentType type) | 62 FileContentType type, |
63 CompressionType compression, | |
64 bool storeMd5); | |
65 | |
66 FileInfo Write(const std::string& data, | |
67 FileContentType type, | |
68 CompressionType compression, | |
69 bool storeMd5) | |
77 { | 70 { |
78 return WriteInternal(data, size, type); | 71 return Write((data.size() == 0 ? NULL : data.c_str()), |
72 data.size(), type, compression, storeMd5); | |
79 } | 73 } |
80 | 74 |
81 FileInfo Write(const std::vector<uint8_t>& content, | 75 void Read(std::string& content, |
82 FileContentType type); | 76 const FileInfo& info); |
83 | 77 |
84 FileInfo Write(const std::string& content, | 78 void Remove(const FileInfo& info) |
85 FileContentType type); | 79 { |
80 area_.Remove(info.GetUuid(), info.GetContentType()); | |
81 } | |
86 | 82 |
87 virtual void Read(std::string& content, | 83 void AnswerFile(HttpOutput& output, |
88 const std::string& uuid, | 84 const FileInfo& info); |
89 FileContentType type) = 0; | |
90 | 85 |
91 virtual void Remove(const std::string& uuid, | 86 void AnswerFile(RestApiOutput& output, |
92 FileContentType type) = 0; | 87 const FileInfo& info); |
93 | |
94 virtual HttpFileSender* ConstructHttpFileSender(const std::string& uuid, | |
95 FileContentType type) = 0; | |
96 }; | 88 }; |
97 } | 89 } |