File indexing completed on 2024-05-19 04:49:44

0001 /****************************************************************************************
0002  * Copyright (c) 2013 Konrad Zemek <konrad.zemek@gmail.com>                             *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef STATSYNCING_AMAROK_EMBEDDED_SQL_CONNECTION_H
0018 #define STATSYNCING_AMAROK_EMBEDDED_SQL_CONNECTION_H
0019 
0020 #include "importers/ImporterSqlConnection.h"
0021 
0022 #include <QDir>
0023 #include <QFileInfo>
0024 #include <QMutex>
0025 #include <QProcess>
0026 #include <QTimer>
0027 
0028 namespace StatSyncing
0029 {
0030 
0031 class AmarokEmbeddedSqlConnection : public ImporterSqlConnection
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     AmarokEmbeddedSqlConnection( const QFileInfo &mysqld, const QDir &datadir );
0037     ~AmarokEmbeddedSqlConnection() override;
0038 
0039 protected:
0040     QSqlDatabase connection() override;
0041 
0042 private:
0043     bool startServer( const int port, const QString &socketPath, const QString &pidPath );
0044 
0045     const QFileInfo m_mysqld;
0046     const QDir m_datadir;
0047 
0048     QProcess m_srv;
0049     QMutex m_srvMutex;
0050     QTimer m_shutdownTimer;
0051 
0052     /// Number of msecs after which server will shut down
0053     static const int SERVER_SHUTDOWN_AFTER = 30000;
0054     /// Number of msecs to wait for server to start up
0055     static const int SERVER_START_TIMEOUT = 30000;
0056 
0057 private Q_SLOTS:
0058     void stopServer();
0059 };
0060 
0061 } // namespace StatSyncing
0062 
0063 #endif // STATSYNCING_AMAROK_EMBEDDED_SQL_CONNECTION_H