comparison Framework/Plugins/StorageBackend.h @ 242:b97a537f4613

MySQL: Support of range reads for the storage area
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 13 Apr 2021 17:00:02 +0200
parents 0a9b48d19643
children 483af3f35a4b
comparison
equal deleted inserted replaced
241:a063bbf10a3e 242:b97a537f4613
30 30
31 namespace OrthancDatabases 31 namespace OrthancDatabases
32 { 32 {
33 class StorageBackend : public boost::noncopyable 33 class StorageBackend : public boost::noncopyable
34 { 34 {
35 private:
36 boost::mutex mutex_;
37 std::unique_ptr<DatabaseManager> manager_;
38
39 DatabaseManager& GetManager();
40
41 protected:
42 void SetDatabase(IDatabase* database); // Takes ownership
43
44 public: 35 public:
45 class IFileContentVisitor : public boost::noncopyable 36 class IFileContentVisitor : public boost::noncopyable
46 { 37 {
47 public: 38 public:
48 virtual ~IFileContentVisitor() 39 virtual ~IFileContentVisitor()
52 virtual void Assign(const std::string& content) = 0; 43 virtual void Assign(const std::string& content) = 0;
53 44
54 virtual bool IsSuccess() const = 0; 45 virtual bool IsSuccess() const = 0;
55 }; 46 };
56 47
57 class Accessor : public boost::noncopyable 48 class IAccessor : public boost::noncopyable
49 {
50 public:
51 virtual ~IAccessor()
52 {
53 }
54
55 virtual void Create(const std::string& uuid,
56 const void* content,
57 size_t size,
58 OrthancPluginContentType type) = 0;
59
60 virtual void ReadWhole(IFileContentVisitor& visitor,
61 const std::string& uuid,
62 OrthancPluginContentType type) = 0;
63
64 virtual void ReadRange(IFileContentVisitor& visitor,
65 const std::string& uuid,
66 OrthancPluginContentType type,
67 uint64_t start,
68 uint64_t length) = 0;
69
70 virtual void Remove(const std::string& uuid,
71 OrthancPluginContentType type) = 0;
72 };
73
74 private:
75 class StringVisitor;
76
77 boost::mutex mutex_;
78 std::unique_ptr<DatabaseManager> manager_;
79
80 DatabaseManager& GetManager();
81
82 protected:
83 class AccessorBase : public IAccessor
58 { 84 {
59 private: 85 private:
60 boost::mutex::scoped_lock lock_; 86 boost::mutex::scoped_lock lock_;
61 DatabaseManager& manager_; 87 DatabaseManager& manager_;
62 88
63 public: 89 public:
64 Accessor(StorageBackend& backend) : 90 AccessorBase(StorageBackend& backend) :
65 lock_(backend.mutex_), 91 lock_(backend.mutex_),
66 manager_(backend.GetManager()) 92 manager_(backend.GetManager())
67 { 93 {
68 } 94 }
69
70 void Create(const std::string& uuid,
71 const void* content,
72 size_t size,
73 OrthancPluginContentType type);
74 95
75 void Read(IFileContentVisitor& visitor, 96 DatabaseManager& GetManager() const
76 const std::string& uuid, 97 {
77 OrthancPluginContentType type); 98 return manager_;
99 }
78 100
79 void Remove(const std::string& uuid, 101 virtual void Create(const std::string& uuid,
80 OrthancPluginContentType type); 102 const void* content,
103 size_t size,
104 OrthancPluginContentType type);
81 105
82 // For unit tests 106 virtual void ReadWhole(IFileContentVisitor& visitor,
83 void ReadToString(std::string& target, 107 const std::string& uuid,
84 const std::string& uuid, 108 OrthancPluginContentType type);
85 OrthancPluginContentType type); 109
110 virtual void ReadRange(IFileContentVisitor& visitor,
111 const std::string& uuid,
112 OrthancPluginContentType type,
113 uint64_t start,
114 uint64_t length);
115
116 virtual void Remove(const std::string& uuid,
117 OrthancPluginContentType type);
86 }; 118 };
87 119
120 void SetDatabase(IDatabase* database); // Takes ownership
121
122 virtual bool HasReadRange() const = 0;
123
124 public:
88 virtual ~StorageBackend() 125 virtual ~StorageBackend()
89 { 126 {
127 }
128
129 virtual IAccessor* CreateAccessor()
130 {
131 return new AccessorBase(*this);
90 } 132 }
91 133
92 static void Register(OrthancPluginContext* context, 134 static void Register(OrthancPluginContext* context,
93 StorageBackend* backend); // Takes ownership 135 StorageBackend* backend); // Takes ownership
94 136
95 static void Finalize(); 137 static void Finalize();
138
139 // For unit tests
140 static void ReadWholeToString(std::string& target,
141 IAccessor& accessor,
142 const std::string& uuid,
143 OrthancPluginContentType type);
144
145 // For unit tests
146 static void ReadRangeToString(std::string& target,
147 IAccessor& accessor,
148 const std::string& uuid,
149 OrthancPluginContentType type,
150 uint64_t start,
151 uint64_t length);
96 }; 152 };
97 } 153 }