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>
75 m_timerIdleWakeUp(this), m_queue(NULL), m_queueLength(0), m_checkReturnCode(true)
79 wxBoxSizer * topsizer =
new wxBoxSizer( wxVERTICAL );
81 m_textctrl =
new wxTextCtrl(
this, wxID_ANY, _T(
""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY);
84 wxFont font(wxDEFAULT, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
89 topsizer->Add(
m_textctrl, 1, wxEXPAND | wxALL, 10);
99 wxKillError rc = wxProcess::Kill(
m_pidLast, wxSIGKILL, wxKILL_CHILDREN);
102 wxKillError rc = wxProcess::Kill(
m_pidLast, wxSIGTERM, wxKILL_CHILDREN);
104 if ( rc != wxKILL_OK ) {
105 static const wxChar *errorText[] =
108 _T(
"signal not supported"),
109 _T(
"permission denied"),
110 _T(
"no such process"),
111 _T(
"unspecified error"),
114 wxLogError(_(
"Failed to kill process %ld, error %d: %s"),
124 HANDLE hProcessSnapshot = NULL;
125 PROCESSENTRY32 pEntry = {0};
126 THREADENTRY32 tEntry = {0};
129 hProcessSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
131 if (hProcessSnapshot == INVALID_HANDLE_VALUE)
132 wxLogError(_(
"Error pausing process %ld, code 1"),
m_pidLast);
135 pEntry.dwSize =
sizeof(PROCESSENTRY32);
136 tEntry.dwSize =
sizeof(THREADENTRY32);
139 if(Process32First(hProcessSnapshot, &pEntry))
147 HANDLE hThreadSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
148 if (hThreadSnapshot == INVALID_HANDLE_VALUE)
149 wxLogError(_(
"Error pausing process %ld, code 2"),
m_pidLast);
152 if(Thread32First(hThreadSnapshot, &tEntry))
157 if(tEntry.th32OwnerProcessID == pEntry.th32ProcessID)
159 HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, tEntry.th32ThreadID);
161 SuspendThread(hThread);
163 ResumeThread(hThread);
164 CloseHandle(hThread);
166 }
while(Thread32Next(hThreadSnapshot, &tEntry));
168 CloseHandle(hThreadSnapshot);
170 }
while(Process32Next(hProcessSnapshot, &pEntry));
173 CloseHandle(hProcessSnapshot);
199 #if defined __WXMAC__ && defined __ppc__
203 int os = wxGetOsVersion(&osVersionMajor, &osVersionMinor);
205 cout <<
"osVersionCheck: os is " << os <<
"\n" << endl;
206 cout <<
"osVersionCheck: osVersionMajor = " << osVersionMajor << endl;
207 cout <<
"osVersionCheck: osVersionMinor = " << osVersionMinor << endl;
208 if ((osVersionMajor == 0x10) && (osVersionMinor >= 0x50))
212 signal(SIGCHLD,SIG_IGN);
213 cout <<
"osVersionCheck: Leopard loop 1" << endl;
217 cout <<
"osVersionCheck: Tiger loop 1" << endl;
225 wxLogError(_T(
"Execution of '%s' failed."), cmd.c_str());
243 wxConfigBase* config = wxConfigBase::Get();
244 const long threads = config->Read(wxT(
"/output/NumberOfThreads"), 0l);
255 wxString tempDir = config->Read(wxT(
"tempDir"), wxT(
""));
256 if (!tempDir.IsEmpty())
289 if (this->GetParent())
291 wxCommandEvent event(EVT_QUEUE_PROGRESS, wxID_ANY);
293 this->GetParent()->GetEventHandler()->AddPendingEvent(event);
338 #if defined __WXGTK__
339 wxTextInputStream ts(s,
" \t", wxConvLibc);
341 wxTextInputStream ts(s);
346 wxChar c = ts.GetChar();
350 if (!currLine.empty()) {
351 if (currLine.Last() != wxChar(
'\n') )
354 }
else if (c == 0x0) {
357 }
else if (c == 0x0d) {
361 if (currLine.Last() != wxChar(
'\n') ) {
362 currLine = currLine.BeforeLast(
'\n');
363 if(!currLine.empty()) {
364 currLine.Append(
'\n');
368 }
else if (c ==
'\n') {
375 if (currLine.Last() != wxChar(
'\n') ) {
376 currLine = currLine.BeforeLast(
'\n');
377 if(!currLine.empty()) {
378 currLine.Append(
'\n');
389 size_t lret = currLine.find_last_of(wxChar(
'\n'));
390 if (lret != wxString::npos && lret>0 && lret+1 < currLine.size()) {
398 for (
size_t n = 0; n < count; n++ )
400 while (
m_running[n]->IsInputAvailable() )
404 while (
m_running[n]->IsErrorAvailable() )
411 #if defined __WXMAC__ && defined __ppc__
415 int os = wxGetOsVersion(&osVersionMajor, &osVersionMinor);
417 cerr <<
"osVersionCheck: os is " << os <<
"\n" << endl;
418 cerr <<
"osVersionCheck: osVersionMajor = " << osVersionMajor << endl;
419 cerr <<
"osVersionCheck: osVersionMinor = " << osVersionMinor << endl;
421 if ((osVersionMajor == 0x10) && (osVersionMinor >= 0x50))
423 cerr <<
"osVersionCheck: Leopard loop 2" << endl;
428 DEBUG_DEBUG(
"Found terminated process: " << (pid_t)m_pidLast)
434 if (this->GetParent()) {
435 wxProcessEvent event( wxID_ANY, m_pidLast, 0);
436 event.SetEventObject(
this );
438 this->GetParent()->ProcessEvent( event );
445 cerr <<
"osVersionCheck: Tiger loop 2" << endl;
452 DEBUG_TRACE(
"process terminated: pid " << pid <<
" exit code:" << status);
476 std::ldiv_t result=std::ldiv(duration, 60l);
477 *
m_textctrl <<
"\n" << wxString::Format(_(
"Process took %ld:%2ld min"), result.quot, result.rem) <<
"\n";
481 *
m_textctrl <<
"\n" << wxString::Format(_(
"Process took %ld s"), duration) <<
"\n";
485 if (this->GetParent())
488 event.SetEventObject(
this);
490 this->GetParent()->GetEventHandler()->AddPendingEvent(event);
492 wxCommandEvent event2(EVT_QUEUE_PROGRESS, wxID_ANY);
494 this->GetParent()->GetEventHandler()->AddPendingEvent(event2);
516 return wxStringTokenize(
m_textctrl->GetValue(),
"\r\n");
534 DEBUG_DEBUG(
"Process " << pid <<
" terminated with return code: " << status);
544 : wxDialog(parent, wxID_ANY, title, pos, size, wxRESIZE_BORDER | wxCAPTION | wxCLOSE_BOX | wxSYSTEM_MENU)
547 wxBoxSizer * topsizer =
new wxBoxSizer( wxVERTICAL );
551 topsizer->Add(
m_execPanel, 1, wxEXPAND | wxALL, 2);
553 topsizer->Add(
new wxButton(
this, wxID_CANCEL, _(
"Cancel")),
554 0, wxALL | wxALIGN_RIGHT, 10);
556 SetSizer( topsizer );
564 DEBUG_DEBUG(
"Process terminated with return code: " << event.GetExitCode());
565 if(wxConfigBase::Get()->Read(wxT(
"CopyLogToClipboard"), 0l)==1l)
572 EndModal(event.GetExitCode());
612 wxString title,
bool isQuoted)
618 wxString cmdline = command + wxT(
" ") + args;
620 wxDefaultPosition, wxSize(640, 400));
622 dlg.CentreOnParent();
629 MyExecDialog dlg(parent, title, wxDefaultPosition, wxSize(640, 400));
631 dlg.CentreOnParent();
633 if (!comment.IsEmpty())
638 while (!queue->empty())
640 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)
MyExecDialog(wxWindow *parent, const wxString &title, const wxPoint &pos, const wxSize &size)
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)
MyExecPanel(wxWindow *parent)
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