Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MyExternalCmdExecDialog.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
24 // This class is written based on 'exec' sample of wxWidgets library.
25 
26 
27 #ifndef _MYEXTERNALCMDEXECDIALOG__H
28 #define _MYEXTERNALCMDEXECDIALOG__H
29 
30 #include <hugin_shared.h>
31 #include <wx/utils.h>
32 #include "Executor.h"
33 
34 const int HUGIN_EXIT_CODE_CANCELLED = -255;
35 
37 WXIMPEX int MyExecuteCommandOnDialog(wxString command, wxString args, wxWindow* parent, wxString title, bool isQuoted=false);
40 WXIMPEX int MyExecuteCommandQueue(HuginQueue::CommandQueue* queue, wxWindow* parent, const wxString& title, const wxString& comment = wxEmptyString);
41 
42 // Define an array of process pointers used by MyFrame
43 class MyPipedProcess;
44 WX_DEFINE_ARRAY_PTR(MyPipedProcess *, MyProcessesArray);
45 
47 {
48 public:
49  virtual void OnProcessTerminated(MyPipedProcess *process, int pid, int status) = 0;
50  virtual ~MyProcessListener() {}
51 };
52 
53 // Define a new exec dialog
54 class WXIMPEX MyExecPanel : public wxPanel, public MyProcessListener
55 {
56 public:
57  // ctor(s)
58  explicit MyExecPanel(wxWindow * parent);
59 
60  void KillProcess();
61  void PauseProcess(bool pause = true);
62  void ContinueProcess();
63  long GetPid();
64 
65  int ExecWithRedirect(wxString command);
66  int ExecQueue(HuginQueue::CommandQueue* queue);
67 
68  // polling output of async processes
69  void OnTimer(wxTimerEvent& event);
70 
71  // for MyPipedProcess
72  void OnProcessTerminated(MyPipedProcess *process, int pid, int status);
73 
76  bool SaveLog(const wxString &filename);
78  void CopyLogToClipboard();
80  wxArrayString GetLogAsArrayString();
82  void AddString(const wxString& s);
83 
84  virtual ~MyExecPanel();
85 
86 private:
87 
88  void AddToOutput(wxInputStream & s);
89 
90  void DoAsyncExec(const wxString& cmd);
91 
92  void AddAsyncProcess(MyPipedProcess *process);
93 
94  void RemoveAsyncProcess(MyPipedProcess *process);
95 
96  int ExecNextQueue();
97 
98  // the PID of the last process we launched asynchronously
99  long m_pidLast;
100 
101  wxTextCtrl *m_textctrl;
103 
104  MyProcessesArray m_running;
105 
106  // the idle event wake up timer
108  // store queue
111  // if the return code of the process should be checked
113  wxExecuteEnv m_executeEnv;
114  wxStopWatch m_stopWatch;
115  // any class wishing to process wxWidgets events must use this macro
116  DECLARE_EVENT_TABLE()
117 };
118 
119 // ----------------------------------------------------------------------------
120 // wxProcess-derived classes
121 // ----------------------------------------------------------------------------
122 
123 // A specialization of MyProcess for redirecting the output
124 class WXIMPEX MyPipedProcess : public wxProcess
125 {
126 public:
127  MyPipedProcess(MyProcessListener *parent, const wxString& cmd)
128  : wxProcess(0), m_cmd(cmd)
129  {
130  m_parent = parent;
131  Redirect();
132  }
133 
134  // This is the handler for process termination events
135  virtual void OnTerminate(int pid, int status);
136 protected:
138  wxString m_cmd;
139 };
140 
141 // Define a new exec dialog, which uses MyExecPanel defined above
142 class WXIMPEX MyExecDialog : public wxDialog
143 {
144 public:
145 // ctor(s)
146  MyExecDialog(wxWindow * parent, const wxString& title, const wxPoint& pos, const wxSize& size);
147 
148  void OnCancel(wxCommandEvent& event);
149 
150  int ExecWithRedirect(wxString command);
151  int ExecQueue(HuginQueue::CommandQueue* queue);
153  void AddString(const wxString& s);
154 
155  void OnProcessTerminate(wxProcessEvent & event);
156 
157  virtual ~MyExecDialog();
158 
159 private:
160 
163 
164  // any class wishing to process wxWidgets events must use this macro
165  DECLARE_EVENT_TABLE()
166 };
167 
168 wxDECLARE_EXPORTED_EVENT(WXIMPEX, EVT_QUEUE_PROGRESS, wxCommandEvent);
169 
170 #endif
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 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 ...
const int HUGIN_EXIT_CODE_CANCELLED
WX_DEFINE_ARRAY_PTR(MyPipedProcess *, MyProcessesArray)
MyProcessesArray m_running
MyPipedProcess(MyProcessListener *parent, const wxString &cmd)
basic classes and function for queuing commands in wxWidgets
wxExecuteEnv m_executeEnv
#define WXIMPEX
Definition: hugin_shared.h:40
wxTextCtrl * m_textctrl
virtual void OnProcessTerminated(MyPipedProcess *process, int pid, int status)=0
MyExecPanel * m_execPanel
wxDECLARE_EXPORTED_EVENT(WXIMPEX, EVT_QUEUE_PROGRESS, wxCommandEvent)
MyProcessListener * m_parent
std::vector< NormalCommand * > CommandQueue
Definition: Executor.h:61
HuginQueue::CommandQueue * m_queue