27 #include "hugin_config.h"
36 #include "wx/process.h"
37 #include "wx/mimetype.h"
38 #include <wx/sstream.h>
39 #include <wx/tokenzr.h>
46 #include <sys/types.h>
80 m_timerIdleWakeUp(this), m_queue(NULL), m_queueLength(0), m_checkReturnCode(true)
84 wxBoxSizer * topsizer =
new wxBoxSizer( wxVERTICAL );
86 m_textctrl =
new wxTextCtrl(
this, wxID_ANY, _T(
""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY);
89 wxFont font(wxDEFAULT, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
91 m_textctrl->SetFont(font);
94 topsizer->Add(m_textctrl, 1, wxEXPAND | wxALL, 10);
103 wxKillError rc = wxProcess::Kill(
m_pidLast, wxSIGKILL, wxKILL_CHILDREN);
106 wxKillError rc = wxProcess::Kill(
m_pidLast, wxSIGTERM, wxKILL_CHILDREN);
108 if ( rc != wxKILL_OK ) {
109 static const wxChar *errorText[] =
112 _T(
"signal not supported"),
113 _T(
"permission denied"),
114 _T(
"no such process"),
115 _T(
"unspecified error"),
118 wxLogError(_(
"Failed to kill process %ld, error %d: %s"),
128 HANDLE hProcessSnapshot = NULL;
129 PROCESSENTRY32 pEntry = {0};
130 THREADENTRY32 tEntry = {0};
133 hProcessSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
135 if (hProcessSnapshot == INVALID_HANDLE_VALUE)
136 wxLogError(_(
"Error pausing process %ld, code 1"),
m_pidLast);
139 pEntry.dwSize =
sizeof(PROCESSENTRY32);
140 tEntry.dwSize =
sizeof(THREADENTRY32);
143 if(Process32First(hProcessSnapshot, &pEntry))
151 HANDLE hThreadSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
152 if (hThreadSnapshot == INVALID_HANDLE_VALUE)
153 wxLogError(_(
"Error pausing process %ld, code 2"),
m_pidLast);
156 if(Thread32First(hThreadSnapshot, &tEntry))
161 if(tEntry.th32OwnerProcessID == pEntry.th32ProcessID)
163 HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, tEntry.th32ThreadID);
165 SuspendThread(hThread);
167 ResumeThread(hThread);
168 CloseHandle(hThread);
170 }
while(Thread32Next(hThreadSnapshot, &tEntry));
172 CloseHandle(hThreadSnapshot);
174 }
while(Process32Next(hProcessSnapshot, &pEntry));
177 CloseHandle(hProcessSnapshot);
203 #if defined __WXMAC__ && defined __ppc__
207 int os = wxGetOsVersion(&osVersionMajor, &osVersionMinor);
209 cout <<
"osVersionCheck: os is " << os <<
"\n" << endl;
210 cout <<
"osVersionCheck: osVersionMajor = " << osVersionMajor << endl;
211 cout <<
"osVersionCheck: osVersionMinor = " << osVersionMinor << endl;
212 if ((osVersionMajor == 0x10) && (osVersionMinor >= 0x50))
216 signal(SIGCHLD,SIG_IGN);
217 cout <<
"osVersionCheck: Leopard loop 1" << endl;
221 cout <<
"osVersionCheck: Tiger loop 1" << endl;
229 wxLogError(_T(
"Execution of '%s' failed."), cmd.c_str());
247 wxConfigBase* config = wxConfigBase::Get();
248 const long threads = config->Read(wxT(
"/output/NumberOfThreads"), 0l);
259 wxString tempDir = config->Read(wxT(
"tempDir"), wxT(
""));
260 if (!tempDir.IsEmpty())
293 if (this->GetParent())
295 wxCommandEvent event(EVT_QUEUE_PROGRESS, wxID_ANY);
297 this->GetParent()->GetEventHandler()->AddPendingEvent(event);
342 #if defined __WXGTK__
343 wxTextInputStream ts(s,
" \t", wxConvLibc);
345 wxTextInputStream ts(s);
350 wxChar c = ts.GetChar();
354 if (!currLine.empty()) {
355 if (currLine.Last() != wxChar(
'\n') )
358 }
else if (c == 0x0) {
361 }
else if (c == 0x0d) {
365 if (currLine.Last() != wxChar(
'\n') ) {
366 currLine = currLine.BeforeLast(
'\n');
367 if(!currLine.empty()) {
368 currLine.Append(
'\n');
372 }
else if (c ==
'\n') {
379 if (currLine.Last() != wxChar(
'\n') ) {
380 currLine = currLine.BeforeLast(
'\n');
381 if(!currLine.empty()) {
382 currLine.Append(
'\n');
393 size_t lret = currLine.find_last_of(wxChar(
'\n'));
394 if (lret != wxString::npos && lret>0 && lret+1 < currLine.size()) {
402 for (
size_t n = 0; n < count; n++ )
404 while (
m_running[n]->IsInputAvailable() )
408 while (
m_running[n]->IsErrorAvailable() )
415 #if defined __WXMAC__ && defined __ppc__
419 int os = wxGetOsVersion(&osVersionMajor, &osVersionMinor);
421 cerr <<
"osVersionCheck: os is " << os <<
"\n" << endl;
422 cerr <<
"osVersionCheck: osVersionMajor = " << osVersionMajor << endl;
423 cerr <<
"osVersionCheck: osVersionMinor = " << osVersionMinor << endl;
425 if ((osVersionMajor == 0x10) && (osVersionMinor >= 0x50))
427 cerr <<
"osVersionCheck: Leopard loop 2" << endl;
432 DEBUG_DEBUG(
"Found terminated process: " << (pid_t)m_pidLast)
438 if (this->GetParent()) {
439 wxProcessEvent event( wxID_ANY, m_pidLast, 0);
440 event.SetEventObject(
this );
442 this->GetParent()->ProcessEvent( event );
449 cerr <<
"osVersionCheck: Tiger loop 2" << endl;
456 DEBUG_TRACE(
"process terminated: pid " << pid <<
" exit code:" << status);
480 std::ldiv_t result=std::ldiv(duration, 60l);
481 *
m_textctrl <<
"\n" << wxString::Format(_(
"Process took %ld:%2ld min"), result.quot, result.rem) <<
"\n";
485 *
m_textctrl <<
"\n" << wxString::Format(_(
"Process took %ld s"), duration) <<
"\n";
489 if (this->GetParent())
492 event.SetEventObject(
this);
494 this->GetParent()->GetEventHandler()->AddPendingEvent(event);
496 wxCommandEvent event2(EVT_QUEUE_PROGRESS, wxID_ANY);
498 this->GetParent()->GetEventHandler()->AddPendingEvent(event2);
520 return wxStringTokenize(
m_textctrl->GetValue(),
"\r\n");
538 DEBUG_DEBUG(
"Process " << pid <<
" terminated with return code: " << status);
550 EVT_END_PROCESS(wxID_ANY,
MyExecDialog::OnProcessTerminate)
554 : wxDialog(parent, wxID_ANY, title, pos, size, wxRESIZE_BORDER | wxCAPTION | wxCLOSE_BOX | wxSYSTEM_MENU)
557 wxBoxSizer * topsizer =
new wxBoxSizer( wxVERTICAL );
561 topsizer->Add(m_execPanel, 1, wxEXPAND | wxALL, 2);
563 topsizer->Add(
new wxButton(
this, wxID_CANCEL, _(
"Cancel")),
564 0, wxALL | wxALIGN_RIGHT, 10);
568 this->SetBackgroundColour(m_execPanel->GetBackgroundColour());
570 SetSizer( topsizer );
576 DEBUG_DEBUG(
"Process terminated with return code: " << event.GetExitCode());
577 if(wxConfigBase::Get()->Read(wxT(
"CopyLogToClipboard"), 0l)==1l)
584 EndModal(event.GetExitCode());
624 wxString title,
bool isQuoted)
630 wxString cmdline = command + wxT(
" ") + args;
632 wxDefaultPosition, wxSize(640, 400));
634 dlg.CentreOnParent();
641 MyExecDialog dlg(parent, title, wxDefaultPosition, wxSize(640, 400));
643 dlg.CentreOnParent();
645 if (!comment.IsEmpty())
650 while (!queue->empty())
652 delete queue->back();
wxDEFINE_EVENT(EVT_QUEUE_PROGRESS, wxCommandEvent)
int MyExecuteCommandOnDialog(wxString command, wxString args, wxWindow *parent, wxString title, bool isQuoted)
execute a single command in own dialog, redirect output to frame and allow canceling ...
int ExecWithRedirect(wxString command)
int MyExecuteCommandQueue(HuginQueue::CommandQueue *queue, wxWindow *parent, const wxString &title, const wxString &comment)
execute all commands in queue with redirection of output to frame and allow canceling the queue will ...
void RemoveAsyncProcess(MyPipedProcess *process)
normal command for queue, processing is stopped if an error occurred in program
virtual wxString GetCommand() const
wxArrayString GetLogAsArrayString()
returns the output
int ExecNextQueue()
execute next command in queue
void AddToOutput(wxInputStream &s)
void AddString(const wxString &s)
display the string in the panel
void OnCancel(wxCommandEvent &event)
const int HUGIN_EXIT_CODE_CANCELLED
int ExecQueue(HuginQueue::CommandQueue *queue)
void OnProcessTerminated(MyPipedProcess *process, int pid, int status)
MyProcessesArray m_running
int ExecQueue(HuginQueue::CommandQueue *queue)
include file for the hugin project
int ExecWithRedirect(wxString command)
void OnTimer(wxTimerEvent &event)
void OnProcessTerminate(wxProcessEvent &event)
virtual void OnTerminate(int pid, int status)
wxExecuteEnv m_executeEnv
wxTimer m_timerIdleWakeUp
void AddString(const wxString &s)
display the string in the panel
virtual void OnProcessTerminated(MyPipedProcess *process, int pid, int status)=0
include file for the hugin project
wxString GetComment() const
void AddAsyncProcess(MyPipedProcess *process)
MyExecPanel * m_execPanel
MyProcessListener * m_parent
void PauseProcess(bool pause=true)
function to pause running process, argument pause defaults to true - to resume, set it to false ...
str wxQuoteFilename(const str &arg)
Quote a filename, so that it is surrounded by "".
virtual bool CheckReturnCode() const
std::vector< NormalCommand * > CommandQueue
void CopyLogToClipboard()
copy the content of the log window into the clipboard
bool SaveLog(const wxString &filename)
save the content of the window into a given log file
HuginQueue::CommandQueue * m_queue