#include <camprocess.h>
Public Member Functions | |
CamLaunchProcess () | |
CamLaunchProcess constructor. | |
virtual | ~CamLaunchProcess () |
CamLaunchProcess destructor. | |
BOOL | Execute (const wxString &cmd) |
Execute a command which should launch a long-running process. | |
wxKillError | Terminate () |
Kill the process. | |
virtual INT32 | Disconnect () |
Allow a process to continue to run after this object is destroyed. | |
virtual void | OnTerminate (intpid, intstatus) |
Process anything the process writes to the error stream. | |
Protected Member Functions | |
virtual void | ProcessStdErr () |
Process anything the process writes to the error stream. | |
Protected Attributes | |
bool | m_bDead |
bool | m_bConnected |
INT32 | m_ReturnCode |
INT32 | m_pid |
Definition at line 148 of file camprocess.h.
|
CamLaunchProcess constructor.
Definition at line 365 of file camprocess.cpp. 00366 { 00367 m_pid = 0; 00368 m_bDead = true; 00369 m_ReturnCode = -1; 00370 m_bConnected = false; 00371 }
|
|
CamLaunchProcess destructor.
Definition at line 386 of file camprocess.cpp. 00387 { 00388 if (m_bConnected) 00389 { 00390 TRACEUSER("Phil", _T("Process still connected in ~CamLaunchProcess")); 00391 Disconnect(); 00392 } 00393 }
|
|
Allow a process to continue to run after this object is destroyed.
Definition at line 457 of file camprocess.cpp. 00458 { 00459 INT32 pid = m_pid; 00460 00461 m_pid = 0; 00462 m_bConnected = false; 00463 Detach(); 00464 00465 return pid; 00466 }
|
|
Execute a command which should launch a long-running process.
Definition at line 409 of file camprocess.cpp. 00410 { 00411 m_ReturnCode = 0; // Assume success until we find otherwise 00412 00413 // Make sure redirection happens 00414 Redirect(); 00415 00416 TRACEUSER("Phil", _T("Executing %s\n"), (LPCTSTR) cmd); 00417 m_pid = wxExecute(cmd, wxEXEC_ASYNC, this); 00418 if (m_pid==0) 00419 { 00420 // Couldn't even create a process for the command! 00421 m_bDead = true; 00422 return FALSE; 00423 } 00424 00425 // We're now running 00426 m_bDead = false; 00427 m_bConnected = true; 00428 00429 // Give the command 100 milliseconds to return an error condition or die... 00430 // After that we will either use the return code it passed back to OnTerminate 00431 // or assume it is running successfully... 00432 MonotonicTime graceperiod; 00433 while (!m_bDead && m_ReturnCode==0 && !graceperiod.Elapsed(100)) 00434 { 00435 ProcessStdErr(); // Process any output on stderr 00436 wxMilliSleep(1); 00437 wxYield(); 00438 } 00439 00440 TRACEUSER("Phil", _T("Exiting with %d\n"), m_ReturnCode); 00441 return (m_ReturnCode==0); 00442 }
|
|
Process anything the process writes to the error stream.
Definition at line 534 of file camprocess.cpp. 00534 : Correct*/ pid, int /*TYPENOTE: Correct*/ status) 00535 { 00536 ProcessStdErr(); 00537 00538 TRACEUSER("Phil", _T("CamProcess::OnTerminate pid = %d status = %d\n"), pid, status); 00539 m_bDead = true; 00540 m_ReturnCode = status; 00541 m_bConnected = false; 00542 }
|
|
Process anything the process writes to the error stream.
Definition at line 503 of file camprocess.cpp. 00504 { 00505 if (IsErrorAvailable()) 00506 { 00507 wxTextInputStream tis(*GetErrorStream()); 00508 00509 // This assumes that the output is always line buffered 00510 while (!GetErrorStream()->Eof()) 00511 { 00512 wxString line; 00513 line << tis.ReadLine(); 00514 TRACEUSER("Phil", _T("(stderr):%s\n"), line.c_str()); 00515 } 00516 00517 m_ReturnCode = 42; // Signal failure 00518 } 00519 }
|
|
Kill the process.
Definition at line 481 of file camprocess.cpp. 00482 { 00483 if (!m_bDead) 00484 return Kill(m_pid, wxSIGTERM); 00485 00486 return wxKILL_OK; 00487 }
|
|
Definition at line 167 of file camprocess.h. |
|
Definition at line 166 of file camprocess.h. |
|
Definition at line 169 of file camprocess.h. |
|
Definition at line 168 of file camprocess.h. |