OSDN Git Service

Updated Monkey's Audio binaries to v5.54 (2020-08-24), compiled with ICL 19.1 and...
[lamexp/LameXP.git] / src / Tool_Abstract.h
index 0672557..53c3968 100644 (file)
@@ -1,12 +1,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2020 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
+// it under the terms of the GNU GENERAL PUBLIC LICENSE as published by
 // the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version, but always including the *additional*
-// restrictions defined in the "License.txt" file.
+// (at your option) any later version; always including the non-optional
+// LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "License.txt" file!
 //
 // This program is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #pragma once
 
+#include <MUtils\Global.h>
 #include <QObject>
+#include <functional>
 
 class QMutex;
 class QProcess;
-class JobObject;
+class QElapsedTimer;
+
+namespace MUtils
+{
+       class JobObject;
+}
 
 class AbstractTool : public QObject
 {
@@ -36,9 +43,6 @@ public:
        AbstractTool(void);
        ~AbstractTool(void);
        
-       bool startProcess(QProcess &process, const QString &program, const QStringList &args);
-       static QString commandline2string(const QString &program, const QStringList &arguments);
-
 signals:
        void statusUpdated(int progress);
        void messageLogged(const QString &line);
@@ -46,12 +50,39 @@ signals:
 protected:
        static const int m_processTimeoutInterval = 600000;
 
+       typedef enum
+       {
+               RESULT_ABORTED = -2,
+               RESULT_TIMEOUT = -1,
+               RESULT_FAILURE =  0,
+               RESULT_SUCCESS =  1
+       }
+       result_t;
+               
+       static __forceinline bool CHECK_FLAG(QAtomicInt &flag)
+       {
+               return MUTILS_BOOLIFY(flag);
+       }
+
+       static __forceinline int NEXT_PROGRESS(const int &progress)
+       {
+               return (progress < 99) ? qMax(0, progress + 1) : qMin(100, progress);
+       }
+
+       static QString commandline2string(const QString &program, const QStringList &arguments);
+
+       bool startProcess(QProcess &process, const QString &program, const QStringList &args, const QString &workingDir = QString());
+       result_t awaitProcess(QProcess &process, QAtomicInt &abortFlag, int *const exitCode = NULL);
+       result_t awaitProcess(QProcess &process, QAtomicInt &abortFlag, std::function<bool(const QString &text)> &&handler, int *const exitCode = NULL);
+
 private:
-       static quint64 s_startProcessTimer;
-       static QMutex  s_startProcessMutex;
+       static QScopedPointer<MUtils::JobObject> s_jobObjectInstance;
+       static QScopedPointer<QElapsedTimer>     s_startProcessTimer;
+
+       static QMutex s_startProcessMutex;
+       static QMutex s_createObjectMutex;
 
-       static QScopedPointer<JobObject> s_jobObject;
-       static QMutex                    s_jobObjMtx;
+       static quint64 s_referenceCounter;
 
        bool m_firstLaunch;
 };