WvStreams
wvpipe.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * Provides support for piping data to/from subprocesses.
6  */
7 #ifndef __WVPIPE_H
8 #define __WVPIPE_H
9 
10 #include "wvfdstream.h"
11 #include "wvsubproc.h"
12 
32 class WvPipe : public WvFDStream
33 {
34  WvSubProc proc;
35 protected:
36  void setup(const char *program, const char * const *argv,
37  bool writable, bool readable, bool catch_stderr,
38  int stdin_fd, int stdout_fd, int stderr_fd,
39  WvStringList *env);
40 public:
54  WvPipe(const char *program, const char * const *argv,
55  bool writable, bool readable, bool catch_stderr,
56  int stdin_fd = 0, int stdout_fd = 1, int stderr_fd = 2,
57  WvStringList *env = NULL);
58 
72  WvPipe(const char *program, const char * const *argv,
73  bool writable, bool readable, bool catch_stderr,
74  WvFDStream *stdin_str, WvFDStream *stdout_str = NULL,
75  WvFDStream *stderr_str = NULL, WvStringList *env = NULL);
76 
81  WvPipe(const char *program, const char **argv,
82  bool writable, bool readable, bool catch_stderr,
83  WvFDStream *stdio_str, WvStringList *env = NULL);
84 
86  virtual ~WvPipe();
87 
92  void kill(int signum);
93 
95  int finish(bool wait_children = true);
96 
98  bool child_exited();
99 
101  bool child_killed() const;
102 
108  int exit_status();
109 
110  // returns pid
111  int getpid() const { return proc.pid; };
112 
113  // callback to ignore everything. see comment in wvpipe.cc.
114  static void ignore_read(WvStream &s);
115 
116 public:
117  const char *wstype() const { return "WvPipe"; }
118 };
119 
120 #endif // __WVPIPE_H
WvPipe::finish
int finish(bool wait_children=true)
wait for child to die.
Definition: wvpipe.cc:229
WvSubProc
Definition: wvsubproc.h:29
WvPipe::child_exited
bool child_exited()
returns true if child is dead.
Definition: wvpipe.cc:240
WvPipe
Implementation of a WvPipe stream.
Definition: wvpipe.h:32
WvPipe::kill
void kill(int signum)
send the child a signal (signal names are defined in signal.h)
Definition: wvpipe.cc:221
WvPipe::~WvPipe
virtual ~WvPipe()
kill the child process and close the stream.
Definition: wvpipe.cc:276
WvPipe::WvPipe
WvPipe(const char *program, const char *const *argv, bool writable, bool readable, bool catch_stderr, int stdin_fd=0, int stdout_fd=1, int stderr_fd=2, WvStringList *env=NULL)
default pipe constructor; if you just want to use a pipe, use this.
Definition: wvpipe.cc:58
WvStream
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:24
WvPipe::child_killed
bool child_killed() const
returns true if child is dead because of a signal.
Definition: wvpipe.cc:251
WvFdStream
Base class for streams built on Unix file descriptors.
Definition: wvfdstream.h:20
WvStringList
This is a WvList of WvStrings, and is a really handy way to parse strings.
Definition: wvstringlist.h:27
WvPipe::exit_status
int exit_status()
returns the exit status: if child_killed()==true, the signal that killed the child.
Definition: wvpipe.cc:261