diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/stable/process.h | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to '')
-rw-r--r-- | src/stable/process.h | 284 |
1 files changed, 142 insertions, 142 deletions
diff --git a/src/stable/process.h b/src/stable/process.h index 904606a..72b686a 100644 --- a/src/stable/process.h +++ b/src/stable/process.h | |||
@@ -16,151 +16,151 @@ | |||
16 | 16 | ||
17 | namespace Bu | 17 | namespace Bu |
18 | { | 18 | { |
19 | /** | 19 | /** |
20 | * Runs a program and attaches streams to it's stdin, stdout, and stderr. | 20 | * Runs a program and attaches streams to it's stdin, stdout, and stderr. |
21 | * Reading from a Bu::Process will read from the program's standard output, | 21 | * Reading from a Bu::Process will read from the program's standard output, |
22 | * writing to a Bu::Process will write to the program's standard input. | 22 | * writing to a Bu::Process will write to the program's standard input. |
23 | */ | 23 | */ |
24 | class Process : public Bu::Stream | 24 | class Process : public Bu::Stream |
25 | { | 25 | { |
26 | public: | 26 | public: |
27 | enum Flags | 27 | enum Flags |
28 | { | 28 | { |
29 | None = 0x00, | 29 | None = 0x00, |
30 | StdOut = 0x01, | 30 | StdOut = 0x01, |
31 | StdErr = 0x02, | 31 | StdErr = 0x02, |
32 | Both = 0x03 | 32 | Both = 0x03 |
33 | }; | 33 | }; |
34 | 34 | ||
35 | public: | 35 | public: |
36 | class Options | 36 | class Options |
37 | { | 37 | { |
38 | public: | 38 | public: |
39 | enum OptFlags | 39 | enum OptFlags |
40 | { | 40 | { |
41 | None = 0x00, | 41 | None = 0x00, |
42 | SetUid = 0x01, | 42 | SetUid = 0x01, |
43 | SetGid = 0x02, | 43 | SetGid = 0x02, |
44 | }; | 44 | }; |
45 | 45 | ||
46 | Options() : eFlags( None ) {} | 46 | Options() : eFlags( None ) {} |
47 | 47 | ||
48 | int eFlags; | 48 | int eFlags; |
49 | int iUid; | 49 | int iUid; |
50 | int iGid; | 50 | int iGid; |
51 | }; | 51 | }; |
52 | 52 | ||
53 | Process( Flags eFlags, const char *sName, char *const argv[] ); | 53 | Process( Flags eFlags, const char *sName, char *const argv[] ); |
54 | Process( Flags eFlags, const char *sName, const char *argv, ...); | 54 | Process( Flags eFlags, const char *sName, const char *argv, ...); |
55 | Process( Flags eFlags, const Options &opt, const char *sName, char *const argv[] ); | 55 | Process( Flags eFlags, const Options &opt, const char *sName, char *const argv[] ); |
56 | Process( Flags eFlags, const Options &opt, const char *sName, const char *argv, ...); | 56 | Process( Flags eFlags, const Options &opt, const char *sName, const char *argv, ...); |
57 | virtual ~Process(); | 57 | virtual ~Process(); |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Waits until the process exits. This blocks the caller until the | 60 | * Waits until the process exits. This blocks the caller until the |
61 | * child process terminates. | 61 | * child process terminates. |
62 | */ | 62 | */ |
63 | void wait(); | 63 | void wait(); |
64 | 64 | ||
65 | virtual void close(); | 65 | virtual void close(); |
66 | virtual void closeStdIn(); | 66 | virtual void closeStdIn(); |
67 | virtual void closeStdOut(); | 67 | virtual void closeStdOut(); |
68 | virtual Bu::size read( void *pBuf, Bu::size nBytes ); | 68 | virtual Bu::size read( void *pBuf, Bu::size nBytes ); |
69 | virtual Bu::size readErr( void *pBuf, Bu::size nBytes ); | 69 | virtual Bu::size readErr( void *pBuf, Bu::size nBytes ); |
70 | virtual Bu::size write( const void *pBuf, Bu::size nBytes ); | 70 | virtual Bu::size write( const void *pBuf, Bu::size nBytes ); |
71 | using Stream::write; | 71 | using Stream::write; |
72 | 72 | ||
73 | virtual Bu::size tell(); | 73 | virtual Bu::size tell(); |
74 | virtual void seek( Bu::size offset ); | 74 | virtual void seek( Bu::size offset ); |
75 | virtual void setPos( Bu::size pos ); | 75 | virtual void setPos( Bu::size pos ); |
76 | virtual void setPosEnd( Bu::size pos ); | 76 | virtual void setPosEnd( Bu::size pos ); |
77 | virtual bool isEos(); | 77 | virtual bool isEos(); |
78 | virtual bool isOpen(); | 78 | virtual bool isOpen(); |
79 | 79 | ||
80 | virtual void flush(); | 80 | virtual void flush(); |
81 | 81 | ||
82 | virtual bool canRead(); | 82 | virtual bool canRead(); |
83 | virtual bool canWrite(); | 83 | virtual bool canWrite(); |
84 | 84 | ||
85 | virtual bool isReadable(); | 85 | virtual bool isReadable(); |
86 | virtual bool isWritable(); | 86 | virtual bool isWritable(); |
87 | virtual bool isSeekable(); | 87 | virtual bool isSeekable(); |
88 | 88 | ||
89 | virtual bool isBlocking(); | 89 | virtual bool isBlocking(); |
90 | virtual void setBlocking( bool bBlocking=true ); | 90 | virtual void setBlocking( bool bBlocking=true ); |
91 | 91 | ||
92 | virtual void setSize( Bu::size iSize ); | 92 | virtual void setSize( Bu::size iSize ); |
93 | 93 | ||
94 | virtual size getBlockSize() const; | 94 | virtual size getBlockSize() const; |
95 | virtual size getSize() const; | 95 | virtual size getSize() const; |
96 | virtual Bu::String getLocation() const; | 96 | virtual Bu::String getLocation() const; |
97 | 97 | ||
98 | void select( bool &bStdOut, bool &bStdErr ); | 98 | void select( bool &bStdOut, bool &bStdErr ); |
99 | 99 | ||
100 | bool isRunning(); | 100 | bool isRunning(); |
101 | void ignoreStdErr(); | 101 | void ignoreStdErr(); |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Returns the pid of the child process, or zero if there is no | 104 | * Returns the pid of the child process, or zero if there is no |
105 | * currently running child. Note that a read operation must be | 105 | * currently running child. Note that a read operation must be |
106 | * performed in order to discover that the child has ended. | 106 | * performed in order to discover that the child has ended. |
107 | */ | 107 | */ |
108 | pid_t getPid(); | 108 | pid_t getPid(); |
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Returns true if the child exited normally (by calling exit or | 111 | * Returns true if the child exited normally (by calling exit or |
112 | * returning from main). | 112 | * returning from main). |
113 | */ | 113 | */ |
114 | bool childExited(); | 114 | bool childExited(); |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * Returns the 8 bit integer value returned from the child program if | 117 | * Returns the 8 bit integer value returned from the child program if |
118 | * childExited returned true. | 118 | * childExited returned true. |
119 | */ | 119 | */ |
120 | int childExitStatus(); | 120 | int childExitStatus(); |
121 | 121 | ||
122 | /** | 122 | /** |
123 | * Returns true if the child exited because of a signal. | 123 | * Returns true if the child exited because of a signal. |
124 | */ | 124 | */ |
125 | bool childSignaled(); | 125 | bool childSignaled(); |
126 | 126 | ||
127 | /** | 127 | /** |
128 | * Returns the signal ID if the childSignaled return true. | 128 | * Returns the signal ID if the childSignaled return true. |
129 | */ | 129 | */ |
130 | int childSignal(); | 130 | int childSignal(); |
131 | 131 | ||
132 | /** | 132 | /** |
133 | * Returns true if the child left a core dump behind when it exited. | 133 | * Returns true if the child left a core dump behind when it exited. |
134 | */ | 134 | */ |
135 | bool childCoreDumped(); | 135 | bool childCoreDumped(); |
136 | 136 | ||
137 | private: | 137 | private: |
138 | class ProcData | 138 | class ProcData |
139 | { | 139 | { |
140 | public: | 140 | public: |
141 | ProcData(); | 141 | ProcData(); |
142 | #ifdef WIN32 | 142 | #ifdef WIN32 |
143 | void *hStdIn; | 143 | void *hStdIn; |
144 | void *hStdOut; | 144 | void *hStdOut; |
145 | void *hStdErr; | 145 | void *hStdErr; |
146 | void *hProcess; | 146 | void *hProcess; |
147 | #else | 147 | #else |
148 | int iStdIn; | 148 | int iStdIn; |
149 | int iStdOut; | 149 | int iStdOut; |
150 | int iStdErr; | 150 | int iStdErr; |
151 | pid_t iPid; | 151 | pid_t iPid; |
152 | #endif | 152 | #endif |
153 | }; | 153 | }; |
154 | ProcData pd; | 154 | ProcData pd; |
155 | int iProcStatus; | 155 | int iProcStatus; |
156 | bool bBlocking; | 156 | bool bBlocking; |
157 | bool bStdOutEos; | 157 | bool bStdOutEos; |
158 | bool bStdErrEos; | 158 | bool bStdErrEos; |
159 | 159 | ||
160 | void gexec( Flags eFlags, const char *sName, char *const argv[] ); | 160 | void gexec( Flags eFlags, const char *sName, char *const argv[] ); |
161 | void checkClose(); | 161 | void checkClose(); |
162 | Options opt; | 162 | Options opt; |
163 | }; | 163 | }; |
164 | } | 164 | } |
165 | 165 | ||
166 | #endif | 166 | #endif |