comparison Google/GoogleStoragePlugin.cpp @ 78:d7295e8678d7

renames
author Alain Mazy <am@osimis.io>
date Fri, 14 Oct 2022 11:00:18 +0200
parents 80792bb9600e
children 16514270d9ca
comparison
equal deleted inserted replaced
77:80792bb9600e 78:d7295e8678d7
24 // Create aliases to make the code easier to read. 24 // Create aliases to make the code easier to read.
25 namespace gcs = google::cloud::storage; 25 namespace gcs = google::cloud::storage;
26 static const char* const PLUGIN_SECTION = "GoogleCloudStorage"; 26 static const char* const PLUGIN_SECTION = "GoogleCloudStorage";
27 27
28 28
29 class GoogleStoragePlugin : public BaseStoragePlugin 29 class GoogleStoragePlugin : public BaseStorage
30 { 30 {
31 public: 31 public:
32 32
33 std::string bucketName_; 33 std::string bucketName_;
34 google::cloud::storage::Client mainClient_; // the client that is created at startup. Each thread should copy it when it needs it. (from the doc: Instances of this class created via copy-construction or copy-assignment share the underlying pool of connections. Access to these copies via multiple threads is guaranteed to work. Two threads operating on the same instance of this class is not guaranteed to work.) 34 google::cloud::storage::Client mainClient_; // the client that is created at startup. Each thread should copy it when it needs it. (from the doc: Instances of this class created via copy-construction or copy-assignment share the underlying pool of connections. Access to these copies via multiple threads is guaranteed to work. Two threads operating on the same instance of this class is not guaranteed to work.)
47 virtual bool DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); 47 virtual bool DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
48 virtual const char* GetConfigurationSectionName() {return PLUGIN_SECTION;} 48 virtual const char* GetConfigurationSectionName() {return PLUGIN_SECTION;}
49 }; 49 };
50 50
51 51
52 class Writer : public IStoragePlugin::IWriter 52 class Writer : public IStorage::IWriter
53 { 53 {
54 std::string path_; 54 std::string path_;
55 gcs::Client client_; 55 gcs::Client client_;
56 std::string bucketName_; 56 std::string bucketName_;
57 gcs::ObjectWriteStream stream_; 57 gcs::ObjectWriteStream stream_;
87 } 87 }
88 } 88 }
89 }; 89 };
90 90
91 91
92 class Reader : public IStoragePlugin::IReader 92 class Reader : public IStorage::IReader
93 { 93 {
94 std::list<std::string> paths_; 94 std::list<std::string> paths_;
95 gcs::Client client_; 95 gcs::Client client_;
96 std::string bucketName_; 96 std::string bucketName_;
97 97
232 const char* GoogleStoragePluginFactory::GetStoragePluginName() 232 const char* GoogleStoragePluginFactory::GetStoragePluginName()
233 { 233 {
234 return "Google Cloud Storage"; 234 return "Google Cloud Storage";
235 } 235 }
236 236
237 IStoragePlugin* GoogleStoragePluginFactory::CreateStoragePlugin(const OrthancPlugins::OrthancConfiguration& orthancConfig) 237 IStorage* GoogleStoragePluginFactory::CreateStorage(const OrthancPlugins::OrthancConfiguration& orthancConfig)
238 { 238 {
239 bool enableLegacyStorageStructure; 239 bool enableLegacyStorageStructure;
240 bool storageContainsUnknownFiles; 240 bool storageContainsUnknownFiles;
241 241
242 if (!orthancConfig.IsSection(PLUGIN_SECTION)) 242 if (!orthancConfig.IsSection(PLUGIN_SECTION))
246 } 246 }
247 247
248 OrthancPlugins::OrthancConfiguration pluginSection; 248 OrthancPlugins::OrthancConfiguration pluginSection;
249 orthancConfig.GetSection(pluginSection, PLUGIN_SECTION); 249 orthancConfig.GetSection(pluginSection, PLUGIN_SECTION);
250 250
251 if (!BaseStoragePlugin::ReadCommonConfiguration(enableLegacyStorageStructure, storageContainsUnknownFiles, pluginSection)) 251 if (!BaseStorage::ReadCommonConfiguration(enableLegacyStorageStructure, storageContainsUnknownFiles, pluginSection))
252 { 252 {
253 return nullptr; 253 return nullptr;
254 } 254 }
255 255
256 std::string pathToGoogleCredentials; 256 std::string pathToGoogleCredentials;
287 287
288 return new GoogleStoragePlugin(googleBucketName, mainClient.value(), enableLegacyStorageStructure, storageContainsUnknownFiles); 288 return new GoogleStoragePlugin(googleBucketName, mainClient.value(), enableLegacyStorageStructure, storageContainsUnknownFiles);
289 } 289 }
290 290
291 GoogleStoragePlugin::GoogleStoragePlugin(const std::string &bucketName, google::cloud::storage::Client& mainClient, bool enableLegacyStorageStructure, bool storageContainsUnknownFiles) 291 GoogleStoragePlugin::GoogleStoragePlugin(const std::string &bucketName, google::cloud::storage::Client& mainClient, bool enableLegacyStorageStructure, bool storageContainsUnknownFiles)
292 : BaseStoragePlugin(enableLegacyStorageStructure), 292 : BaseStorage(enableLegacyStorageStructure),
293 bucketName_(bucketName), 293 bucketName_(bucketName),
294 mainClient_(mainClient), 294 mainClient_(mainClient),
295 storageContainsUnknownFiles_(storageContainsUnknownFiles) 295 storageContainsUnknownFiles_(storageContainsUnknownFiles)
296 { 296 {
297 297
298 } 298 }
299 299
300 IStoragePlugin::IWriter* GoogleStoragePlugin::GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) 300 IStorage::IWriter* GoogleStoragePlugin::GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled)
301 { 301 {
302 return new Writer(bucketName_, GetPath(uuid, type, encryptionEnabled), mainClient_); 302 return new Writer(bucketName_, GetPath(uuid, type, encryptionEnabled), mainClient_);
303 } 303 }
304 304
305 IStoragePlugin::IReader* GoogleStoragePlugin::GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) 305 IStorage::IReader* GoogleStoragePlugin::GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled)
306 { 306 {
307 std::list<std::string> paths; 307 std::list<std::string> paths;
308 paths.push_back(GetPath(uuid, type, encryptionEnabled, false)); 308 paths.push_back(GetPath(uuid, type, encryptionEnabled, false));
309 if (storageContainsUnknownFiles_) 309 if (storageContainsUnknownFiles_)
310 { 310 {