Refactoring and cleanup. The progress report mechanism should now be much

more flexible. May need this in the alphabranch...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32903 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-09-02 14:52:13 +00:00
parent 4aa6ec093b
commit 8dadca32b1
2 changed files with 219 additions and 167 deletions
+38 -29
View File
@@ -22,63 +22,72 @@ class BString;
namespace BPrivate {
class BCommandPipe {
public:
public:
BCommandPipe();
virtual ~BCommandPipe();
status_t AddArg(const char* argv);
void PrintToStream() const;
// FlushArgs() deletes the commands while Close() explicity closes all
// pending pipe-ends
// Note: Internally FlushArgs() calls Close()
void FlushArgs();
void Close();
// You MUST NOT free/delete the strings in the array, but you MUST free
// just the array itself.
const char** Argv(int32& _argc) const;
// If you use these, you must explicitly call "close" for the parameters
// (outdes/errdes) when you are done with them!
thread_id Pipe(int* outdes, int* errdes) const;
thread_id Pipe(int* outdes) const;
thread_id PipeAll(int* outAndErrDes) const;
// (stdOut/stdErr) when you are done with them!
thread_id Pipe(int* stdOut, int* stdErr) const;
thread_id Pipe(int* stdOut) const;
thread_id PipeAll(int* stdOutAndErr) const;
// If you use these, you need NOT call "fclose" for the parameters
// (out/err) when you are done with them, also you need not do any
// allocation for these FILE* pointers, just use FILE* out = NULL
// and pass &out and so on...
thread_id PipeInto(FILE** _out, FILE** _err);
thread_id PipeInto(FILE** _outAndErr);
// Run() is a synchronous call, and waits till the command has finished
// executing RunAsync() is an asynchronous call that returns immediately
// after launching the command Neither of these bother about redirecting
// pipes for you to use
void Run();
void RunAsync();
// This function reads line-by-line from "file", cancels its reading
// when "*cancel" is true. It reports each line it has read to "target"
// using the supplied "_message" and string field name. "cancel" can be
// NULL
BString ReadLines(FILE* file, bool* cancel,
BMessenger& target, const BMessage& message,
const BString& stringFieldName);
// You need NOT free/delete the return array of strings
const char** Argv(int32& _argc) const;
// Reading the Pipe output
class LineReader {
public:
virtual bool IsCanceled() = 0;
virtual status_t ReadLine(const BString& line) = 0;
// TODO: Add a Timeout() method.
};
// This function reads line-by-line from "file". It calls IsCanceled()
// on the passed LineReader instance for each byte read from file
// (currently). And it calls ReadLine() for each complete line.
status_t ReadLines(FILE* file, LineReader* lineReader);
// This method can be used to read the entire file into a BString.
BString ReadLines(FILE* file);
// Stardard append operators, if you use pointers to a BCommandPipe,
// you must use *pipe << "command"; and not pipe << "command" (as it
// will not compile that way)
BCommandPipe& operator<<(const char *arg);
BCommandPipe& operator<<(const char* arg);
BCommandPipe& operator<<(const BString& arg);
BCommandPipe& operator<<(const BCommandPipe& arg);
protected:
protected:
BList fArgList;
int fOutDes[2];
int fErrDes[2];
bool fOutDesOpen;
bool fErrDesOpen;
int fStdOut[2];
int fStdErr[2];
bool fStdOutOpen;
bool fStdErrOpen;
};
} // namespace BPrivate