HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ReadWritePipe.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_ReadWritePipe.h (UT Library, C++)
7  *
8  * COMMENTS: This class spawns a program and allows bidirectional
9  * communication between this process and the program by using
10  * two pipes. The program only has to use stdin and stdout.
11  * This process must use the pipe files.
12  */
13 
14 #ifndef __UT_ReadWritePipe_h__
15 #define __UT_ReadWritePipe_h__
16 
17 #include "UT_API.h"
18 #include "UT_Spawn.h"
19 #include <stdio.h>
20 
22 public:
23  // Note that the constructor does not open the pipe. Instead, you must
24  // call open().
26 
27  // If the pipe is still open when this object is destructed, the
28  // child process will be killed.
30 
31  // If the command could not be run for any reason, open() will return
32  // false. The reason for the failure can be determined with getErrno().
33  bool open(const char *cmd);
34  int getErrno() const { return myErrno; }
35 
36  // If the pipe was already closed, close() will return false. If the child
37  // is still running, close() will kill the child with a SIGINT.
38  bool close();
39 
40  // If close() succeeds, you can get the exit status of the child process
41  // with this method.
42  int getChildExitStatus() const { return myChildExitStatus; }
43 
44  // Use these files to read from and write to the pipe. Note that if you
45  // try to write to the pipe when the child has exited, you will get a
46  // SIGPIPE. When you write, you should call fflush() to force the
47  // pipe to be flushed.
48  FILE *getReadFile() { return myReadFile; }
49  FILE *getWriteFile() { return myWriteFile; }
50 
51  // This method will return the process id of the command that was executed.
52  pid_t getChildPid() const { return myChildPid; }
53 
54 private:
55  FILE *myReadFile;
56  FILE *myWriteFile;
57 
58  pid_t myChildPid;
59  int myChildExitStatus;
60  int myErrno;
61 
62 #ifdef WIN32
63  void *myReadPipe;
64  void *myWritePipe;
65  void *myHProcess;
66 #endif
67 };
68 
69 #endif
int getErrno() const
#define UT_API
Definition: UT_API.h:13
pid_t getChildPid() const
virtual int open(float queuesize)
int getChildExitStatus() const
virtual void close()