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 #if wxCHECK_VERSION(3,0,0)
00112     wxExecuteEnv m_executeEnv;
00113 #endif
00114     // any class wishing to process wxWidgets events must use this macro
00115     DECLARE_EVENT_TABLE()
00116 };
00117 
00118 // ----------------------------------------------------------------------------
00119 // wxProcess-derived classes
00120 // ----------------------------------------------------------------------------
00121 
00122 // A specialization of MyProcess for redirecting the output
00123 class WXIMPEX MyPipedProcess : public wxProcess
00124 {
00125 public:
00126     MyPipedProcess(MyProcessListener *parent, const wxString& cmd)
00127         : wxProcess(0), m_cmd(cmd)
00128         {
00129             m_parent = parent;
00130             Redirect();
00131         }
00132 
00133     // This is the handler for process termination events
00134     virtual void OnTerminate(int pid, int status);
00135 protected:
00136     MyProcessListener *m_parent;
00137     wxString m_cmd;
00138 };
00139 
00140 // Define a new exec dialog, which uses MyExecPanel defined above
00141 class WXIMPEX MyExecDialog : public wxDialog
00142 {
00143 public:
00144 // ctor(s)
00145     MyExecDialog(wxWindow * parent, const wxString& title, const wxPoint& pos, const wxSize& size);
00146 
00147     void OnCancel(wxCommandEvent& event);
00148 
00149     int ExecWithRedirect(wxString command);
00150     int ExecQueue(HuginQueue::CommandQueue* queue);
00152     void AddString(const wxString& s);
00153 
00154     void OnProcessTerminate(wxProcessEvent & event);
00155     
00156     virtual ~MyExecDialog();
00157 
00158 private:
00159     
00160     MyExecPanel * m_execPanel;
00161     bool m_cancelled;
00162 
00163     // any class wishing to process wxWidgets events must use this macro
00164     DECLARE_EVENT_TABLE()
00165 };
00166 
00167 DECLARE_EXPORTED_EVENT_TYPE(WXIMPEX, EVT_QUEUE_PROGRESS, -1)
00168 
00169 #endif

Generated on 1 Sep 2015 for Hugintrunk by  doxygen 1.4.7