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_NonCopyable.h"
19 #include "UT_Spawn.h"
20 #include <stdio.h>
21 
23 {
24 public:
25  // Note that the constructor does not open the pipe. Instead, you must
26  // call open().
28 
29  // If the pipe is still open when this object is destructed, the
30  // child process will be killed.
32 
34 
35  // If the command could not be run for any reason, open() will return
36  // false. The reason for the failure can be determined with getErrno().
37  bool open(const char *cmd);
38  int getErrno() const { return myErrno; }
39 
40  // If the pipe was already closed, close() will return false. If the child
41  // is still running, close() will kill the child with a SIGINT.
42  bool close();
43 
44  // If close() succeeds, you can get the exit status of the child process
45  // with this method.
46  int getChildExitStatus() const { return myChildExitStatus; }
47 
48  // Use these files to read from and write to the pipe. Note that if you
49  // try to write to the pipe when the child has exited, you will get a
50  // SIGPIPE. When you write, you should call fflush() to force the
51  // pipe to be flushed.
52  FILE *getReadFile() { return myReadFile; }
53  FILE *getWriteFile() { return myWriteFile; }
54 
55  // This method will return the process id of the command that was executed.
56  pid_t getChildPid() const { return myChildPid; }
57 
58 private:
59  FILE *myReadFile;
60  FILE *myWriteFile;
61 
62  pid_t myChildPid;
63  int myChildExitStatus;
64  int myErrno;
65 
66 #ifdef WIN32
67  void *myReadPipe;
68  void *myWritePipe;
69  void *myHProcess;
70 #endif
71 };
72 
73 #endif
int getErrno() const
#define UT_API
Definition: UT_API.h:14
void close() override
int open(float queuesize) override
pid_t getChildPid() const
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
int getChildExitStatus() const