1 /** 2 * Orthanc - A Lightweight, RESTful DICOM Store 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 4 * Department, University Hospital of Liege, Belgium 5 * Copyright (C) 2017-2021 Osimis S.A., Belgium 6 * 7 * This program is free software: you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation, either version 3 of the 10 * License, or (at your option) any later version. 11 * 12 * In addition, as a special exception, the copyright holders of this 13 * program give permission to link the code of its release with the 14 * OpenSSL project's "OpenSSL" library (or with modified versions of it 15 * that use the same license as the "OpenSSL" library), and distribute 16 * the linked executables. You must obey the GNU General Public License 17 * in all respects for all of the code used other than "OpenSSL". If you 18 * modify file(s) with this exception, you may extend this exception to 19 * your version of the file(s), but you are not obligated to do so. If 20 * you do not wish to do so, delete this exception statement from your 21 * version. If you delete this exception statement from all source files 22 * in the program, then also delete it here. 23 * 24 * This program is distributed in the hope that it will be useful, but 25 * WITHOUT ANY WARRANTY; without even the implied warranty of 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 * General Public License for more details. 28 * 29 * You should have received a copy of the GNU General Public License 30 * along with this program. If not, see <http://www.gnu.org/licenses/>. 31 **/ 32 33 34 #pragma once 35 36 #if ORTHANC_ENABLE_PLUGINS == 1 37 38 #include "../../../OrthancFramework/Sources/SharedLibrary.h" 39 #include "../../Sources/Database/IDatabaseWrapper.h" 40 #include "../Include/orthanc/OrthancCDatabasePlugin.h" 41 #include "PluginsErrorDictionary.h" 42 43 #include <boost/thread/recursive_mutex.hpp> 44 45 namespace Orthanc 46 { 47 /** 48 * This class is for backward compatibility with database plugins 49 * that don't use the primitives introduced in Orthanc 1.9.2 to deal 50 * with concurrent read-only transactions. 51 * 52 * In Orthanc <= 1.9.1, Orthanc assumed that at most 1 single thread 53 * was accessing the database plugin at anytime, in order to match 54 * the SQLite model. Read-write accesses assumed the plugin to run 55 * the SQL statement "START TRANSACTION SERIALIZABLE" so as to be 56 * able to rollback the modifications. Read-only accesses didn't 57 * start a transaction, as they were protected by the global mutex. 58 **/ 59 class OrthancPluginDatabase : public IDatabaseWrapper 60 { 61 private: 62 class Transaction; 63 64 /** 65 * We need a "recursive_mutex" because of "AnswerReceived()" that 66 * is called by the "answer" primitives of the database SDK once a 67 * transaction is running. 68 **/ 69 boost::recursive_mutex mutex_; 70 71 SharedLibrary& library_; 72 PluginsErrorDictionary& errorDictionary_; 73 OrthancPluginDatabaseBackend backend_; 74 OrthancPluginDatabaseExtensions extensions_; 75 void* payload_; 76 Transaction* activeTransaction_; 77 bool fastGetTotalSize_; 78 uint64_t currentDiskSize_; 79 GetContext()80 OrthancPluginDatabaseContext* GetContext() 81 { 82 return reinterpret_cast<OrthancPluginDatabaseContext*>(this); 83 } 84 85 void CheckSuccess(OrthancPluginErrorCode code); 86 87 public: 88 OrthancPluginDatabase(SharedLibrary& library, 89 PluginsErrorDictionary& errorDictionary, 90 const OrthancPluginDatabaseBackend& backend, 91 const OrthancPluginDatabaseExtensions* extensions, 92 size_t extensionsSize, 93 void *payload); 94 95 virtual void Open() ORTHANC_OVERRIDE; 96 97 virtual void Close() ORTHANC_OVERRIDE; 98 GetSharedLibrary()99 const SharedLibrary& GetSharedLibrary() const 100 { 101 return library_; 102 } 103 FlushToDisk()104 virtual void FlushToDisk() ORTHANC_OVERRIDE 105 { 106 } 107 HasFlushToDisk()108 virtual bool HasFlushToDisk() const ORTHANC_OVERRIDE 109 { 110 return false; 111 } 112 113 virtual IDatabaseWrapper::ITransaction* StartTransaction(TransactionType type, 114 IDatabaseListener& listener) 115 ORTHANC_OVERRIDE; 116 117 virtual unsigned int GetDatabaseVersion() ORTHANC_OVERRIDE; 118 119 virtual void Upgrade(unsigned int targetVersion, 120 IStorageArea& storageArea) ORTHANC_OVERRIDE; 121 HasRevisionsSupport()122 virtual bool HasRevisionsSupport() const ORTHANC_OVERRIDE 123 { 124 return false; // No support for revisions in old API 125 } 126 127 void AnswerReceived(const _OrthancPluginDatabaseAnswer& answer); 128 }; 129 } 130 131 #endif 132