File indexing completed on 2024-03-24 03:54:27
0001 /* 0002 This file is part of the KDE Baloo project. 0003 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> 0004 SPDX-FileCopyrightText: 2016 Christoph Cullmann <cullmann@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #ifndef BALOO_DATABASE_H 0010 #define BALOO_DATABASE_H 0011 0012 #include <QMutex> 0013 0014 #include "document.h" 0015 #include "databasedbis.h" 0016 0017 namespace Baloo { 0018 0019 class DatabaseTest; 0020 0021 class BALOO_ENGINE_EXPORT Database 0022 { 0023 public: 0024 /** 0025 * Init database for given DB path, will not open it. 0026 * @param path db path 0027 */ 0028 explicit Database(const QString& path); 0029 0030 /** 0031 * Destruct db, might close it, if opened. 0032 */ 0033 ~Database(); 0034 0035 /** 0036 * Database open mode 0037 */ 0038 enum OpenMode { 0039 /** 0040 * Create + open read-write database. 0041 */ 0042 CreateDatabase, 0043 0044 /** 0045 * Read-Write Database, only works if database exists. 0046 */ 0047 ReadWriteDatabase, 0048 0049 /** 0050 * Read-Only Database, only works if database exists. 0051 */ 0052 ReadOnlyDatabase, 0053 }; 0054 0055 /** 0056 * Open database in given mode. 0057 * Nop after open was done (even if mode differs). 0058 * There is no close as this would invalidate the database for all threads using it. 0059 * @param mode create or open only? 0060 * @return success? 0061 */ 0062 bool open(OpenMode mode); 0063 0064 /** 0065 * Is database open? 0066 * @return database open? 0067 */ 0068 bool isOpen() const; 0069 0070 /** 0071 * Path to database. 0072 * @return database path 0073 */ 0074 QString path() const; 0075 0076 /** 0077 * Is the database available for use? 0078 * For example if indexing is disabled or the indexer did never run this is false. 0079 * @return database available 0080 */ 0081 bool isAvailable() const; 0082 0083 private: 0084 /** 0085 * serialize access, as open might be called from multiple threads 0086 */ 0087 mutable QMutex m_mutex; 0088 0089 /** 0090 * database path 0091 */ 0092 const QString m_path; 0093 0094 MDB_env* m_env; 0095 DatabaseDbis m_dbis; 0096 0097 friend class Transaction; 0098 friend class DatabaseTest; 0099 0100 }; 0101 } 0102 0103 #endif // BALOO_DATABASE_H