File indexing completed on 2025-01-05 03:54:13

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-11-14
0007  * Description : Mysql internal database server
0008  *
0009  * SPDX-FileCopyrightText: 2009-2011 by Holger Foerster <Hamsi2k at freenet dot de>
0010  * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2016      by Swati Lodha <swatilodha27 at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_DATABASE_SERVER_H
0018 #define DIGIKAM_DATABASE_SERVER_H
0019 
0020 // QT includes
0021 
0022 #include <QProcess>
0023 #include <QThread>
0024 #include <QString>
0025 
0026 // Local includes
0027 
0028 #include "databaseserverstarter.h"
0029 #include "databaseservererror.h"
0030 #include "dbengineparameters.h"
0031 #include "digikam_export.h"
0032 
0033 class QCoreApplication;
0034 
0035 namespace Digikam
0036 {
0037 
0038 class DIGIKAM_EXPORT DatabaseServer : public QThread
0039 {
0040     Q_OBJECT
0041 
0042 public:
0043 
0044     enum DatabaseServerStateEnum
0045     {
0046         started,
0047         running,
0048         notRunning,
0049         stopped
0050     };
0051     DatabaseServerStateEnum databaseServerStateEnum;
0052 
0053 public:
0054 
0055     explicit DatabaseServer(const DbEngineParameters& params,
0056                             DatabaseServerStarter* const parent = DatabaseServerStarter::instance());
0057     ~DatabaseServer() override;
0058 
0059     /**
0060      * Starts the database management server.
0061      */
0062     DatabaseServerError startDatabaseProcess();
0063 
0064     /**
0065      * Terminates the databaser server process.
0066      */
0067     void stopDatabaseProcess();
0068 
0069     /**
0070      * Returns true if the server process is running.
0071      */
0072     bool isRunning()                                                     const;
0073 
0074 Q_SIGNALS:
0075 
0076     void done();
0077 
0078 protected:
0079 
0080     void run() override;
0081 
0082 private:
0083 
0084     /**
0085      * Inits and Starts Mysql server.
0086      */
0087     DatabaseServerError startMysqlDatabaseProcess();
0088 
0089     /**
0090      * Checks if Mysql binaries and database directories exists and creates
0091      * the latter if necessary.
0092      */
0093     DatabaseServerError checkDatabaseDirs()                              const;
0094 
0095     /**
0096      * Finds and updates (if necessary) configuration files for the mysql
0097      * server.
0098      */
0099     DatabaseServerError initMysqlConfig()                                const;
0100 
0101     /**
0102      * Copy and remove mysql error log files.
0103      */
0104     void copyAndRemoveMysqlLogs()                                        const;
0105 
0106     /**
0107      * Creates initial Mysql database files for internal server.
0108      */
0109     DatabaseServerError createMysqlFiles()                               const;
0110 
0111     /**
0112      * Starts the server for the internal database.
0113      */
0114     DatabaseServerError startMysqlServer();
0115 
0116     /**
0117      * Creates or connects to database digikam in mysql.
0118      */
0119     DatabaseServerError initMysqlDatabase(bool useDatabase)              const;
0120 
0121     /**
0122      * Perform a mysql database upgrade.
0123      */
0124     DatabaseServerError upgradeMysqlDatabase();
0125 
0126     /**
0127      * Return the current user account name.
0128      */
0129     QString getcurrentAccountUserName()                                  const;
0130 
0131     /**
0132      * Returns i18n converted error message and writes to qCDebug.
0133      */
0134     QString processErrorLog(QProcess* const process, const QString& msg) const;
0135 
0136 private:
0137 
0138     class Private;
0139     Private* const d;
0140 };
0141 
0142 } // namespace Digikam
0143 
0144 #endif // DIGIKAM_DATABASE_SERVER_H