Updated formatting of documentation plus a little reorganization.
[cmake.git] / Source / CTest / cmProcess.h
blobd9b15af018b9e35b04c32371545413ae1cd53e2d
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmProcess.h,v $
5 Language: C++
6 Date: $Date: 2009-09-11 16:26:41 $
7 Version: $Revision: 1.8 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmProcess_h
18 #define cmProcess_h
21 #include "cmStandardIncludes.h"
22 #include <cmsys/Process.h>
25 /** \class cmProcess
26 * \brief run a process with c++
28 * cmProcess wraps the kwsys process stuff in a c++ class.
30 class cmProcess
32 public:
33 cmProcess();
34 ~cmProcess();
35 const char* GetCommand() { return this->Command.c_str();}
36 void SetCommand(const char* command);
37 void SetCommandArguments(std::vector<std::string> const& arg);
38 void SetWorkingDirectory(const char* dir) { this->WorkingDirectory = dir;}
39 void SetTimeout(double t) { this->Timeout = t;}
40 // Return true if the process starts
41 bool StartProcess();
43 // return the process status
44 int GetProcessStatus();
45 // Report the status of the program
46 int ReportStatus();
47 int GetId() { return this->Id; }
48 void SetId(int id) { this->Id = id;}
49 int GetExitValue() { return this->ExitValue;}
50 double GetTotalTime() { return this->TotalTime;}
52 /**
53 * Read one line of output but block for no more than timeout.
54 * Returns:
55 * cmsysProcess_Pipe_None = Process terminated and all output read
56 * cmsysProcess_Pipe_STDOUT = Line came from stdout
57 * cmsysProcess_Pipe_STDOUT = Line came from stderr
58 * cmsysProcess_Pipe_Timeout = Timeout expired while waiting
60 int GetNextOutputLine(std::string& line, double timeout);
61 private:
62 double Timeout;
63 double StartTime;
64 double TotalTime;
65 cmsysProcess* Process;
66 class Buffer: public std::vector<char>
68 // Half-open index range of partial line already scanned.
69 size_type First;
70 size_type Last;
71 public:
72 Buffer(): First(0), Last(0) {}
73 bool GetLine(std::string& line);
74 bool GetLast(std::string& line);
76 Buffer StdErr;
77 Buffer StdOut;
78 std::string Command;
79 std::string WorkingDirectory;
80 std::vector<std::string> Arguments;
81 std::vector<const char*> ProcessArgs;
82 std::string Output;
83 int Id;
84 int ExitValue;
87 #endif