File indexing completed on 2025-01-05 04:25:59

0001 /****************************************************************************************
0002  * Copyright (c) 2012 Matěj Laitl <matej@laitl.cz>                                      *
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 IPODWRITEDATABASEJOB_H
0018 #define IPODWRITEDATABASEJOB_H
0019 
0020 #include <ThreadWeaver/Job>
0021 
0022 class IpodCollection;
0023 
0024 /**
0025  * A job designed to call IpodCollection::writeDatabase() in a thread so that main
0026  * thread is not blocked with it. It is guaranteed by IpodCollection that is doesn't
0027  * destroy itself while this job is alive. Memory management of this job is up to
0028  * the caller of it.
0029  */
0030 class IpodWriteDatabaseJob : public QObject, public ThreadWeaver::Job
0031 {
0032     Q_OBJECT
0033 
0034     public:
0035         explicit IpodWriteDatabaseJob( IpodCollection *collection );
0036         void run(ThreadWeaver::JobPointer self = QSharedPointer<ThreadWeaver::Job>(), ThreadWeaver::Thread *thread = nullptr) override;
0037 
0038     Q_SIGNALS:
0039         /** This signal is emitted when this job is being processed by a thread. */
0040         void started(ThreadWeaver::JobPointer);
0041         /** This signal is emitted when the job has been finished (no matter if it succeeded or not). */
0042         void done(ThreadWeaver::JobPointer);
0043         /** This job has failed.
0044          * This signal is emitted when success() returns false after the job is executed. */
0045         void failed(ThreadWeaver::JobPointer);
0046 
0047     protected:
0048         void defaultBegin(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override;
0049         void defaultEnd(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override;
0050 
0051     private:
0052         IpodCollection *m_coll;
0053 };
0054 
0055 #endif // IPODWRITEDATABASEJOB_H