#include <camprocess.h>
Inheritance diagram for CamProcess:
Public Member Functions | |
CamProcess (CCLexFile *pInFile=NULL, CCLexFile *pOutFile=NULL) | |
virtual | ~CamProcess () |
virtual void | OnTerminate (intpid, intstatus) |
virtual void | ProcessStdIn () |
virtual void | ProcessStdOut () |
virtual void | ProcessStdErr () |
INT32 | Execute (const wxString &cmd) |
Protected Attributes | |
volatile bool | m_bDead |
volatile INT32 | m_ReturnCode |
CCLexFile * | m_pInFile |
CCLexFile * | m_pOutFile |
INT32 | m_BytesIn |
INT32 | m_BytesOut |
Definition at line 109 of file camprocess.h.
|
Definition at line 108 of file camprocess.cpp. 00109 { 00110 m_bDead = true; 00111 m_ReturnCode = -1; 00112 m_pInFile = pInFile; 00113 m_pOutFile = pOutFile; 00114 m_BytesIn = 0; 00115 m_BytesOut = 0; 00116 }
|
|
Definition at line 118 of file camprocess.cpp. 00119 { 00120 if (!m_bDead) 00121 { 00122 TRACEUSER("Gerry", _T("Process not dead in ~CamProcess")); 00123 } 00124 }
|
|
Definition at line 127 of file camprocess.cpp. 00128 { 00129 // We're now running 00130 m_bDead = false; 00131 00132 // Make sure redirection happens 00133 Redirect(); 00134 00135 long pid = wxExecute(cmd, wxEXEC_ASYNC, this); 00136 if (pid == 0) 00137 { 00138 // Report problem 00139 m_bDead = true; 00140 return 123; 00141 } 00142 00143 BYTE ReadBuffer[4096]; 00144 size_t ReadBytes = 0; 00145 BYTE* ReadPtr = NULL; 00146 bool bMoreInput = true; 00147 size_t InFileLeft = 0; 00148 if (m_pInFile) 00149 { 00150 InFileLeft = m_pInFile->Size(); 00151 // TRACEUSER("Gerry", _T("InFileSize = %d"), InFileLeft); 00152 } 00153 00154 // Loop until m_bDead is true 00155 00156 while (!m_bDead) 00157 { 00158 // Call the virtual function to process any output on stderr 00159 ProcessStdErr(); 00160 00161 wxYield(); 00162 00163 // If we have an output file 00164 if (m_pOutFile) 00165 { 00166 // If there is output from the process 00167 if (!m_bDead && IsInputAvailable()) 00168 { 00169 // Copy the data to the file 00170 00171 size_t NumRead = 4096; 00172 BYTE Buffer[4096]; 00173 00174 // Read a buffer full 00175 GetInputStream()->Read(Buffer, 4096); 00176 00177 NumRead = GetInputStream()->LastRead(); 00178 00179 // Write the buffer to the file 00180 if (NumRead > 0) 00181 { 00182 // TRACEUSER("Gerry", _T("Writing %d bytes of stdout"), NumRead); 00183 m_pOutFile->write(Buffer, NumRead); 00184 } 00185 } 00186 } 00187 else 00188 { 00189 // Call the virtual function to process the output 00190 if (!m_bDead) 00191 ProcessStdOut(); 00192 } 00193 00194 wxYield(); 00195 00196 // If we have an input file 00197 if (m_pInFile) 00198 { 00199 // Copy some data to the process 00200 // This was a while loop 00201 if (!m_bDead && bMoreInput) 00202 { 00203 // If there is nothing in the buffer 00204 if (ReadBytes == 0) 00205 { 00206 ReadBytes = 4096; 00207 if (ReadBytes > InFileLeft) 00208 ReadBytes = InFileLeft; 00209 00210 if (ReadBytes > 0) 00211 { 00212 // Read a buffer full 00213 // TRACEUSER("Gerry", _T("Reading %d"), ReadBytes); 00214 m_pInFile->read(ReadBuffer, ReadBytes); 00215 00216 InFileLeft -= ReadBytes; 00217 ReadPtr = ReadBuffer; 00218 } 00219 } 00220 00221 // If there is something in the buffer 00222 if (ReadBytes > 0 && GetOutputStream()->IsOk()) 00223 { 00224 // TRACEUSER("Gerry", _T("Buffer contains %d"), ReadBytes); 00225 // Try to write it to the process 00226 GetOutputStream()->Write(ReadPtr, ReadBytes); 00227 00228 size_t Done = GetOutputStream()->LastWrite(); 00229 // TRACEUSER("Gerry", _T("Written %d"), Done); 00230 // If we couldn't write it all 00231 if (Done < ReadBytes) 00232 { 00233 // Update the buffer pointer 00234 ReadPtr += Done; 00235 } 00236 // This is correct for all, part or none written 00237 ReadBytes -= Done; 00238 } 00239 else 00240 { 00241 // Indicate there is no more stdin 00242 // TRACEUSER("Gerry", _T("Buffer is empty - closing")); 00243 CloseOutput(); 00244 bMoreInput = false; 00245 } 00246 } 00247 } 00248 else 00249 { 00250 // Call the virtual function to process the input 00251 if (!m_bDead) 00252 ProcessStdIn(); 00253 } 00254 00255 wxYield(); 00256 } 00257 00258 // TRACEUSER("Gerry", _T("Exiting with %d"), m_ReturnCode); 00259 return m_ReturnCode; 00260 }
|
|
Definition at line 303 of file camprocess.cpp. 00303 : Correct*/ pid, int /*TYPENOTE: Correct*/ status) 00304 { 00305 // TRACEUSER("Gerry", _T("CamProcess::OnTerminate pid = %d status = %d"), pid, status); 00306 m_bDead = true; 00307 m_ReturnCode = status; 00308 00309 // Process anything remaining on stderr and stdout 00310 // If we have an output file 00311 if (m_pOutFile) 00312 { 00313 // If there is output from the process 00314 if (IsInputAvailable()) 00315 { 00316 // Copy the data to the file 00317 size_t NumRead = 4096; 00318 BYTE Buffer[4096]; 00319 00320 while (NumRead > 0) 00321 { 00322 // Read a buffer full 00323 GetInputStream()->Read(Buffer, 4096); 00324 00325 NumRead = GetInputStream()->LastRead(); 00326 00327 // Write the buffer to the file 00328 if (NumRead > 0) 00329 { 00330 m_pOutFile->write(Buffer, NumRead); 00331 } 00332 } 00333 } 00334 } 00335 else 00336 { 00337 // Call the virtual function to process the output 00338 ProcessStdOut(); 00339 } 00340 00341 ProcessStdErr(); 00342 }
|
|
Reimplemented in PluginFilterProcess. Definition at line 286 of file camprocess.cpp. 00287 { 00288 if (IsErrorAvailable()) 00289 { 00290 wxTextInputStream tis(*GetErrorStream()); 00291 00292 // This assumes that the output is always line buffered 00293 while (IsErrorAvailable()) 00294 { 00295 wxString line; 00296 line << tis.ReadLine(); 00297 // TRACEUSER("Gerry", _T("(stderr):%s"), line.c_str()); 00298 } 00299 } 00300 }
|
|
Definition at line 262 of file camprocess.cpp.
|
|
Definition at line 268 of file camprocess.cpp. 00269 { 00270 if (IsInputAvailable()) 00271 { 00272 wxTextInputStream tis(*GetInputStream()); 00273 00274 // This assumes that the output is always line buffered 00275 while (IsInputAvailable()) 00276 { 00277 wxString line; 00278 line << tis.ReadLine(); 00279 // TRACEUSER("Gerry", _T("(stdout):%s"), line.c_str()); 00280 } 00281 } 00282 00283 }
|
|
Definition at line 127 of file camprocess.h. |
|
Definition at line 131 of file camprocess.h. |
|
Definition at line 132 of file camprocess.h. |
|
Definition at line 129 of file camprocess.h. |
|
Definition at line 130 of file camprocess.h. |
|
Definition at line 128 of file camprocess.h. |