cmake/Source/CTest/cmProcess.h

80 lines
2.1 KiB
C
Raw Normal View History

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