text: /**********************************************************************
   *  Copyright (c) 2008-2016, Alliance for Sustainable Energy.
   *  All rights reserved.
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
   *  License as published by the Free Software Foundation; either
   *  version 2.1 of the License, or (at your option) any later version.
   *
   *  This library is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   *  Lesser General Public License for more details.
   *
   *  You should have received a copy of the GNU Lesser General Public
   *  License along with this library; if not, write to the Free Software
   *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
   **********************************************************************/
  
  #ifndef RUNMANAGER_LIB_PROCESS_HPP
  #define RUNMANAGER_LIB_PROCESS_HPP
  
  #include <string>
  #include "FileInfo.hpp"
  #include "AdvancedStatus.hpp"
  #include <QProcess>
  
  namespace openstudio {
  namespace runmanager {
  
    /// Base class for local processes
    class Process : public QObject
    {
      Q_OBJECT;
  
      public:
        Process();
        virtual ~Process() {}
  
        /// Requests that the process start
        virtual void start() = 0;
  
        /// Blocks until the process has finished
        virtual void waitForFinished() = 0;
  
        /// \returns true if the process is running or starting up
        virtual bool running() const = 0;
  
        /// Removes the vector of output file names passed in from the output directory
        virtual void cleanup(const std::vector<std::string> &t_files) = 0;
  
        /// \returns the vector of outputFiles generated by the process
        virtual std::vector<FileInfo> outputFiles() const = 0;
  
        /// \returns the vector of input files used by the Process.
        virtual std::vector<FileInfo> inputFiles() const = 0;
  
        /// \returns the current status of the Process
        openstudio::runmanager::AdvancedStatus status() const;
  
        /// \returns True if stop() has been called;
        bool stopped() const;
  
        /// request that the process stop
        void stop(); 
  
        /// Request that the process clean up files which were copied into the run directory
        /// because the were required to run the process but are no longer necessary now that
        /// the process has completed.
        virtual void cleanUpRequiredFiles()=0;
  
      protected:
        /// Emit the outputFileChanged(const openstudio::runmanager::FileInfo&) signal
        void emitOutputFileChanged(const openstudio::runmanager::FileInfo &file);
  
        /// Emit the statusChanged signal
        void emitStatusChanged(const openstudio::runmanager::AdvancedStatus &status);
  
        /// request that the process stop
        virtual void stopImpl() = 0;
  
  
      signals:
        /// Emitted when the process is fully running
        void started();
  
        /// Emitted after an output file has changed
        void outputFileChanged(const openstudio::runmanager::FileInfo &file);
  
        /// Emitted after stdout data has been created
        void standardOutDataAdded(const std::string &data);
  
        /// Emitted after stderr data has been created
        void standardErrDataAdded(const std::string &data);
  
        /// Emitted if a process error occurs
        void error(QProcess::ProcessError);
  
        /// Emitted if a process error occurs, with extra description of error
        void error(QProcess::ProcessError, const std::string &description);
  
  
        /// Emitted after the process has finished
        void finished(int exitcode, QProcess::ExitStatus);
  
        /// Emitted whenever the status changes
        void statusChanged(const openstudio::runmanager::AdvancedStatus &s);
  
      private:
        REGISTER_LOGGER("openstudio.runmanager.Process");
  
  
        /// The status of the Process. Defaults to "Idle"
        openstudio::runmanager::AdvancedStatus m_status;
  
  
        /// True if the process has been stopped
        bool m_stopped;
    };
  
  
  }
  }
  
  #endif // RUNMANAGER_LIB_PROCESS_HPP
  