HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ReadPipe.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_ReadPipe.h ( UT Library, C++)
7  *
8  * COMMENTS: This is a read pipe which gets around the problem of having a
9  * broken pipe if you close before reading all of the input from
10  * the pipe command.
11  */
12 
13 #ifndef __UT_ReadPipe__
14 #define __UT_ReadPipe__
15 
16 #include "UT_API.h"
17 #include "UT_NonCopyable.h"
18 #include <SYS/SYS_Types.h> // for pid_t, etc.
19 
20 #include <stdio.h>
21 
23 {
24 public:
25  UT_ReadPipe();
26 
27  // If the pipe is open and destructed, the process will be killed.
28  ~UT_ReadPipe();
29 
31 
33  {
34  Stdout = 0,
35  Stderr
36  };
37 
38  FILE *open(const char *cmd, const Descriptor desc=Descriptor::Stdout);
39 
40  int close();
41  FILE *getFilePtr() { return myFilePtr; }
42 
43  // Get the error for the pipe
44  int getErrno() const { return myErrno; }
45 
46  // If close() succeeds, you can get the exit status of the child process by
47  // calling the following method.
48  int getStatus() const { return myExitStatus; }
49 
50  // This method will return the child process id.
51  pid_t getPid() const { return myPid; }
52 
53 private:
54  FILE *myFilePtr;
55  int myErrno;
56  int myExitStatus;
57  pid_t myPid;
58 #ifdef WIN32
59  void *myPipe;
60  void *myHProcess;
61 #endif
62 };
63 
64 #endif
65 
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:632
#define UT_API
Definition: UT_API.h:14
void close() override
FILE * getFilePtr()
Definition: UT_ReadPipe.h:41
int getStatus() const
Definition: UT_ReadPipe.h:48
int open(float queuesize) override
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
pid_t getPid() const
Definition: UT_ReadPipe.h:51
int getErrno() const
Definition: UT_ReadPipe.h:44