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(nullptr), 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);
 
  100         wxKillError rc = wxProcess::Kill(
m_pidLast, wxSIGKILL, wxKILL_CHILDREN);
 
  103         wxKillError rc = wxProcess::Kill(
m_pidLast, wxSIGTERM, wxKILL_CHILDREN);
 
  105         if ( rc != wxKILL_OK ) {
 
  106             static const wxChar *errorText[] =
 
  109                 _T(
"signal not supported"),
 
  110                 _T(
"permission denied"),
 
  111                 _T(
"no such process"),
 
  112                 _T(
"unspecified error"),
 
  115             wxLogError(_(
"Failed to kill process %ld, error %d: %s"),
 
  125         HANDLE hProcessSnapshot = NULL;
 
  126         PROCESSENTRY32 pEntry = {0};
 
  127         THREADENTRY32 tEntry = {0};
 
  130         hProcessSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
 
  132         if (hProcessSnapshot == INVALID_HANDLE_VALUE)
 
  133                 wxLogError(_(
"Error pausing process %ld, code 1"),
m_pidLast);
 
  136                 pEntry.dwSize = 
sizeof(PROCESSENTRY32);
 
  137                 tEntry.dwSize = 
sizeof(THREADENTRY32);
 
  140                 if(Process32First(hProcessSnapshot, &pEntry))
 
  148                                         HANDLE hThreadSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); 
 
  149                                         if (hThreadSnapshot == INVALID_HANDLE_VALUE)
 
  150                                                 wxLogError(_(
"Error pausing process %ld, code 2"),
m_pidLast);
 
  153                                         if(Thread32First(hThreadSnapshot, &tEntry))
 
  158                                                         if(tEntry.th32OwnerProcessID == pEntry.th32ProcessID)
 
  160                                                                 HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, tEntry.th32ThreadID);
 
  162                                                                         SuspendThread(hThread);
 
  164                                                                         ResumeThread(hThread);
 
  165                                                                 CloseHandle(hThread);
 
  167                                                 }
while(Thread32Next(hThreadSnapshot, &tEntry));
 
  169                                         CloseHandle(hThreadSnapshot);
 
  171                         }
while(Process32Next(hProcessSnapshot, &pEntry));
 
  174         CloseHandle(hProcessSnapshot);
 
  200 #if defined __WXMAC__ && defined __ppc__ 
  204     int os = wxGetOsVersion(&osVersionMajor, &osVersionMinor);
 
  206     cout << 
"osVersionCheck: os is " << os << 
"\n"  << endl;
 
  207     cout << 
"osVersionCheck: osVersionMajor = " << osVersionMajor << endl;
 
  208     cout << 
"osVersionCheck: osVersionMinor = " << osVersionMinor << endl;
 
  209     if ((osVersionMajor == 0x10) && (osVersionMinor >= 0x50))
 
  213         signal(SIGCHLD,SIG_IGN);
 
  214         cout <<  
"osVersionCheck: Leopard loop 1" << endl;
 
  218         cout <<  
"osVersionCheck: Tiger loop 1" << endl;
 
  226         wxLogError(_T(
"Execution of '%s' failed."), cmd.c_str());
 
  244     wxConfigBase* config = wxConfigBase::Get();
 
  245     const long threads = config->Read(
"/output/NumberOfThreads", 0l);
 
  256     wxString tempDir = config->Read(
"tempDir", wxEmptyString);
 
  257     if (!tempDir.IsEmpty())
 
  290         if (this->GetParent())
 
  292             wxCommandEvent event(EVT_QUEUE_PROGRESS, wxID_ANY);
 
  294             this->GetParent()->GetEventHandler()->AddPendingEvent(event);
 
  339 #if defined __WXGTK__ 
  340     wxTextInputStream ts(s, 
" \t", wxConvLibc);
 
  342     wxTextInputStream ts(s);
 
  347         wxChar c = ts.GetChar();
 
  351             if (!currLine.empty()) {
 
  352                 if (currLine.Last() != wxChar(
'\n') )
 
  355         } 
else if (c == 0x0) {
 
  358         } 
else if (c == 0x0d) {
 
  362              if (currLine.Last() != wxChar(
'\n') ) {
 
  363                 currLine = currLine.BeforeLast(
'\n');
 
  364                 if(!currLine.empty()) {
 
  365                     currLine.Append(
'\n');
 
  369         } 
else if (c == 
'\n') {
 
  376                 if (currLine.Last() != wxChar(
'\n') ) {
 
  377                     currLine = currLine.BeforeLast(
'\n');
 
  378                     if(!currLine.empty()) {
 
  379                         currLine.Append(
'\n');
 
  390     size_t lret = currLine.find_last_of(wxChar(
'\n'));
 
  391     if (lret != wxString::npos && lret>0 && lret+1 < currLine.size()) {
 
  399     for ( 
size_t n = 0; n < count; n++ )
 
  401         while ( 
m_running[n]->IsInputAvailable() )
 
  405         while ( 
m_running[n]->IsErrorAvailable() )
 
  412 #if defined __WXMAC__ && defined __ppc__ 
  416         int os = wxGetOsVersion(&osVersionMajor, &osVersionMinor);
 
  418         cerr << 
"osVersionCheck: os is " << os << 
"\n"  << endl;
 
  419         cerr << 
"osVersionCheck: osVersionMajor = " << osVersionMajor << endl;
 
  420         cerr << 
"osVersionCheck: osVersionMinor = " << osVersionMinor << endl;
 
  422         if ((osVersionMajor == 0x10) && (osVersionMinor >= 0x50))
 
  424                 cerr <<  
"osVersionCheck: Leopard loop 2" << endl;      
 
  429                                 DEBUG_DEBUG(
"Found terminated process: " << (pid_t)m_pidLast)
 
  435                                 if (this->GetParent()) {
 
  436                                         wxProcessEvent event( wxID_ANY, m_pidLast, 0); 
 
  437                                         event.SetEventObject( 
this );
 
  439                                         this->GetParent()->ProcessEvent( event );
 
  446                 cerr <<  
"osVersionCheck: Tiger loop 2" << endl;
 
  453     DEBUG_TRACE(
"process terminated: pid " << pid << 
" exit code:" << status);
 
  477             std::ldiv_t result=std::ldiv(duration, 60l);
 
  478             *
m_textctrl << 
"\n" << wxString::Format(_(
"Process took %ld:%2ld min"), result.quot, result.rem) << 
"\n";
 
  482             *
m_textctrl << 
"\n" << wxString::Format(_(
"Process took %ld s"), duration) << 
"\n";
 
  486     if (this->GetParent())
 
  489         event.SetEventObject(
this);
 
  491         this->GetParent()->GetEventHandler()->AddPendingEvent(event);
 
  493         wxCommandEvent event2(EVT_QUEUE_PROGRESS, wxID_ANY);
 
  495         this->GetParent()->GetEventHandler()->AddPendingEvent(event2);
 
  526     return wxStringTokenize(
m_textctrl->GetValue(), 
"\r\n");
 
  551     DEBUG_DEBUG(
"Process " << pid << 
" terminated with return code: " << status);
 
  561     : wxDialog(parent, wxID_ANY, title, pos, size, wxRESIZE_BORDER | wxCAPTION | wxCLOSE_BOX | wxSYSTEM_MENU)
 
  564     wxBoxSizer * topsizer = 
new wxBoxSizer( wxVERTICAL );
 
  568     topsizer->Add(
m_execPanel, 1, wxEXPAND | wxALL, 2);
 
  570     topsizer->Add( 
new wxButton(
this, wxID_CANCEL, _(
"Cancel")),
 
  571                    0, wxALL | wxALIGN_RIGHT, 10);
 
  573     SetSizer( topsizer );
 
  581     DEBUG_DEBUG(
"Process terminated with return code: " << event.GetExitCode());
 
  582     if(wxConfigBase::Get()->Read(
"CopyLogToClipboard", 0l)==1l)
 
  589         EndModal(event.GetExitCode());
 
  629                              wxString title, 
bool isQuoted)
 
  635     wxString cmdline = command + 
" " + args;
 
  637                      wxDefaultPosition, wxSize(640, 400));
 
  639     dlg.CentreOnParent();
 
  646     MyExecDialog dlg(parent, title, wxDefaultPosition, wxSize(640, 400));
 
  648     dlg.CentreOnParent();
 
  650     if (!comment.IsEmpty())
 
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
void ClearOutput()
clear the output 
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