MyExternalCmdExecDialog.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 // This class is written based on 'exec' sample of wxWidgets library.
00025 
00026 
00027 #ifndef _MYEXTERNALCMDEXECDIALOG__H
00028 #define _MYEXTERNALCMDEXECDIALOG__H
00029 
00030 #include <hugin_shared.h>
00031 #include <wx/utils.h>
00032 #include "Executor.h"
00033 
00034 const int HUGIN_EXIT_CODE_CANCELLED = -255;
00035 
00037 WXIMPEX int MyExecuteCommandOnDialog(wxString command, wxString args, wxWindow* parent, wxString title, bool isQuoted=false);
00040 WXIMPEX int MyExecuteCommandQueue(HuginQueue::CommandQueue* queue, wxWindow* parent, const wxString& title, const wxString& comment = wxEmptyString);
00041 
00042 // Define an array of process pointers used by MyFrame
00043 class MyPipedProcess;
00044 WX_DEFINE_ARRAY_PTR(MyPipedProcess *, MyProcessesArray);
00045 
00046 class WXIMPEX MyProcessListener
00047 {
00048 public:
00049     virtual void OnProcessTerminated(MyPipedProcess *process, int pid, int status) = 0;
00050     virtual ~MyProcessListener() {}
00051 };
00052 
00053 // Define a new exec dialog
00054 class WXIMPEX MyExecPanel : public wxPanel, public MyProcessListener
00055 {
00056 public:
00057     // ctor(s)
00058     explicit MyExecPanel(wxWindow * parent);
00059 
00060     void KillProcess();
00061         void PauseProcess(bool pause = true);
00062         void ContinueProcess();
00063         long GetPid();
00064 
00065     int ExecWithRedirect(wxString command);
00066     int ExecQueue(HuginQueue::CommandQueue* queue);
00067 
00068     // polling output of async processes
00069     void OnTimer(wxTimerEvent& event);
00070 
00071     // for MyPipedProcess
00072     void OnProcessTerminated(MyPipedProcess *process, int pid, int status);
00073 
00076     bool SaveLog(const wxString &filename);
00078     void CopyLogToClipboard();
00080     void AddString(const wxString& s);
00081 
00082     virtual ~MyExecPanel();
00083 
00084 private:
00085 
00086     void AddToOutput(wxInputStream & s);
00087 
00088     void DoAsyncExec(const wxString& cmd);
00089 
00090     void AddAsyncProcess(MyPipedProcess *process);
00091 
00092     void RemoveAsyncProcess(MyPipedProcess *process);
00093 
00094     int ExecNextQueue();
00095 
00096     // the PID of the last process we launched asynchronously
00097     long m_pidLast;
00098 
00099     wxTextCtrl *m_textctrl;
00100     long m_lastLineStart;
00101 
00102     MyProcessesArray m_running;
00103 
00104     // the idle event wake up timer
00105     wxTimer m_timerIdleWakeUp;
00106     // store queue
00107     HuginQueue::CommandQueue* m_queue;
00108     size_t m_queueLength;
00109     // if the return code of the process should be checked
00110     bool m_checkReturnCode;
00111     wxExecuteEnv m_executeEnv;
00112     // any class wishing to process wxWidgets events must use this macro
00113     DECLARE_EVENT_TABLE()
00114 };
00115 
00116 // ----------------------------------------------------------------------------
00117 // wxProcess-derived classes
00118 // ----------------------------------------------------------------------------
00119 
00120 // A specialization of MyProcess for redirecting the output
00121 class WXIMPEX MyPipedProcess : public wxProcess
00122 {
00123 public:
00124     MyPipedProcess(MyProcessListener *parent, const wxString& cmd)
00125         : wxProcess(0), m_cmd(cmd)
00126         {
00127             m_parent = parent;
00128             Redirect();
00129         }
00130 
00131     // This is the handler for process termination events
00132     virtual void OnTerminate(int pid, int status);
00133 protected:
00134     MyProcessListener *m_parent;
00135     wxString m_cmd;
00136 };
00137 
00138 // Define a new exec dialog, which uses MyExecPanel defined above
00139 class WXIMPEX MyExecDialog : public wxDialog
00140 {
00141 public:
00142 // ctor(s)
00143     MyExecDialog(wxWindow * parent, const wxString& title, const wxPoint& pos, const wxSize& size);
00144 
00145     void OnCancel(wxCommandEvent& event);
00146 
00147     int ExecWithRedirect(wxString command);
00148     int ExecQueue(HuginQueue::CommandQueue* queue);
00150     void AddString(const wxString& s);
00151 
00152     void OnProcessTerminate(wxProcessEvent & event);
00153     
00154     virtual ~MyExecDialog();
00155 
00156 private:
00157     
00158     MyExecPanel * m_execPanel;
00159     bool m_cancelled;
00160 
00161     // any class wishing to process wxWidgets events must use this macro
00162     DECLARE_EVENT_TABLE()
00163 };
00164 
00165 DECLARE_EXPORTED_EVENT_TYPE(WXIMPEX, EVT_QUEUE_PROGRESS, -1)
00166 
00167 #endif

Generated on 23 Aug 2016 for Hugintrunk by  doxygen 1.4.7