2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2008-07-03 17:49:49 +04:00
|
|
|
#ifndef cmProcess_h
|
|
|
|
#define cmProcess_h
|
|
|
|
|
2016-08-24 23:01:40 +03:00
|
|
|
#include <cmConfigure.h> // IWYU pragma: keep
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2008-07-03 17:49:49 +04:00
|
|
|
#include <cmsys/Process.h>
|
2016-08-24 23:01:40 +03:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2008-07-03 17:49:49 +04:00
|
|
|
|
|
|
|
/** \class cmProcess
|
|
|
|
* \brief run a process with c++
|
|
|
|
*
|
|
|
|
* cmProcess wraps the kwsys process stuff in a c++ class.
|
|
|
|
*/
|
2012-08-13 21:42:58 +04:00
|
|
|
class cmProcess
|
2008-07-03 17:49:49 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmProcess();
|
|
|
|
~cmProcess();
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* GetCommand() { return this->Command.c_str(); }
|
2008-07-03 17:49:49 +04:00
|
|
|
void SetCommand(const char* command);
|
|
|
|
void SetCommandArguments(std::vector<std::string> const& arg);
|
2016-05-16 17:34:04 +03:00
|
|
|
void SetWorkingDirectory(const char* dir) { this->WorkingDirectory = dir; }
|
|
|
|
void SetTimeout(double t) { this->Timeout = t; }
|
2016-02-18 21:59:18 +03:00
|
|
|
void ChangeTimeout(double t);
|
|
|
|
void ResetStartTime();
|
2008-07-03 17:49:49 +04:00
|
|
|
// Return true if the process starts
|
|
|
|
bool StartProcess();
|
2009-09-11 20:26:41 +04:00
|
|
|
|
2008-07-03 17:49:49 +04:00
|
|
|
// return the process status
|
|
|
|
int GetProcessStatus();
|
2012-08-13 21:42:58 +04:00
|
|
|
// Report the status of the program
|
2008-07-03 17:49:49 +04:00
|
|
|
int ReportStatus();
|
|
|
|
int GetId() { return this->Id; }
|
2016-05-16 17:34:04 +03:00
|
|
|
void SetId(int id) { this->Id = id; }
|
|
|
|
int GetExitValue() { return this->ExitValue; }
|
|
|
|
double GetTotalTime() { return this->TotalTime; }
|
2010-06-22 17:55:09 +04:00
|
|
|
int GetExitException();
|
2009-09-11 20:26:41 +04:00
|
|
|
/**
|
|
|
|
* Read one line of output but block for no more than timeout.
|
|
|
|
* Returns:
|
|
|
|
* cmsysProcess_Pipe_None = Process terminated and all output read
|
2015-06-03 15:47:49 +03:00
|
|
|
* cmsysProcess_Pipe_STDOUT = Line came from stdout or stderr
|
2009-09-11 20:26:41 +04:00
|
|
|
* cmsysProcess_Pipe_Timeout = Timeout expired while waiting
|
|
|
|
*/
|
|
|
|
int GetNextOutputLine(std::string& line, double timeout);
|
2016-05-16 17:34:04 +03:00
|
|
|
|
2008-07-03 17:49:49 +04:00
|
|
|
private:
|
|
|
|
double Timeout;
|
2008-12-30 01:49:17 +03:00
|
|
|
double StartTime;
|
|
|
|
double TotalTime;
|
2008-07-03 17:49:49 +04:00
|
|
|
cmsysProcess* Process;
|
2016-05-16 17:34:04 +03:00
|
|
|
class Buffer : public std::vector<char>
|
2009-09-11 20:26:41 +04:00
|
|
|
{
|
|
|
|
// Half-open index range of partial line already scanned.
|
|
|
|
size_type First;
|
|
|
|
size_type Last;
|
2016-05-16 17:34:04 +03:00
|
|
|
|
2009-09-11 20:26:41 +04:00
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
Buffer()
|
|
|
|
: First(0)
|
|
|
|
, Last(0)
|
|
|
|
{
|
|
|
|
}
|
2009-09-11 20:26:41 +04:00
|
|
|
bool GetLine(std::string& line);
|
|
|
|
bool GetLast(std::string& line);
|
|
|
|
};
|
2015-06-03 15:47:49 +03:00
|
|
|
Buffer Output;
|
2008-07-03 17:49:49 +04:00
|
|
|
std::string Command;
|
|
|
|
std::string WorkingDirectory;
|
|
|
|
std::vector<std::string> Arguments;
|
|
|
|
std::vector<const char*> ProcessArgs;
|
|
|
|
int Id;
|
|
|
|
int ExitValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|