Version: 0.6.0
task.h
1 /******************************************************************************
2  * Project: wxGIS
3  * Purpose: wxGISTask and wxGISTaskCategories classes
4  * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2013,2014 Dmitry Baryshnikov
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 #pragma once
22 
23 #include "wxgis/net/netfactory.h"
24 #include "wxgis/net/netevent.h"
25 #include "wxgis/geoprocessing/tskmngr.h"
26 #include "wxgis/core/json/jsonval.h"
27 #include "wxgis/core/pointer.h"
28 
29 #include <wx/dynarray.h>
30 
37 class WXDLLIMPEXP_GIS_GP wxGISTaskMessage
38 {
39 public:
40  wxGISTaskMessage(long nId = wxNOT_FOUND, const wxString &sMsg = wxEmptyString, wxGISEnumMessageType eType = enumGISMessageUnk, const wxDateTime &dt = wxDateTime::Now())
41  {
42  m_nId = nId;
43  m_sMessage = sMsg;
44  m_dt = dt;
45  m_eType = eType;
46  }
47 
49  {
50  m_sMessage = Msg.m_sMessage;
51  m_dt = Msg.m_dt;
52  m_eType = Msg.m_eType;
53  m_nId = Msg.m_nId;
54  }
55 
56  void operator = ( const wxGISTaskMessage& Msg )
57  {
58  m_sMessage = Msg.m_sMessage;
59  m_dt = Msg.m_dt;
60  m_eType = Msg.m_eType;
61  m_nId = Msg.m_nId;
62  }
63 
64  wxString m_sMessage;
65  wxDateTime m_dt;
66  wxGISEnumMessageType m_eType;
67  long m_nId;
68 };
69 
70 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxGISTaskMessage, wxGISTaskMessagesArray, WXDLLIMPEXP_GIS_GP);
71 
72 class WXDLLIMPEXP_GIS_GP wxGISTaskEvent;
73 
74 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_GIS_GP, wxGISTASK_ADD, wxGISTaskEvent);
75 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_GIS_GP, wxGISTASK_DEL, wxGISTaskEvent);
76 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_GIS_GP, wxGISTASK_CHNG, wxGISTaskEvent);
77 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_GIS_GP, wxGISTASK_MESSAGEADDED, wxGISTaskEvent);
78 
85 class WXDLLIMPEXP_GIS_GP wxGISTaskEvent : public wxEvent
86 {
87 public:
88  wxGISTaskEvent(int nTaskId = 0, wxEventType eventType = wxGISTASK_ADD, long nMessageId = wxNOT_FOUND) : wxEvent(nTaskId, eventType)
89  {
90  m_nMessageId = nMessageId;
91  }
92 
93  wxGISTaskEvent(const wxGISTaskEvent& event) : wxEvent(event), m_nMessageId(event.m_nMessageId)
94  {
95  }
96 
97  virtual wxEvent *Clone() const { return new wxGISTaskEvent(*this); }
98  long GetMessageId(void) const {return m_nMessageId;};
99 protected:
100  long m_nMessageId;
101 private:
102  DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGISTaskEvent)
103 };
104 
105 typedef void (wxEvtHandler::*wxGISTaskEventFunction)(wxGISTaskEvent&);
106 
107 #define wxGISTaskEventHandler(func) \
108  wxEVENT_HANDLER_CAST(wxGISTaskEventFunction, func)
109 
110 #define EVT_GISTASK_ADD(func) wx__DECLARE_EVT0(wxGISTASK_ADD, wxGISTaskEventHandler(func))
111 #define EVT_GISTASK_DEL(func) wx__DECLARE_EVT0(wxGISTASK_DEL, wxGISTaskEventHandler(func))
112 #define EVT_GISTASK_CHNG(func) wx__DECLARE_EVT0(wxGISTASK_CHNG, wxGISTaskEventHandler(func))
113 #define EVT_GISTASK_MESSAGEADDED(func) wx__DECLARE_EVT0(wxGISTASK_MESSAGEADDED, wxGISTaskEventHandler(func))
114 
115 class wxGISTaskBase;
116 WX_DECLARE_HASH_MAP( int, wxGISTaskBase*, wxIntegerHash, wxIntegerEqual, wxGISTaskMap );
117 
125 class WXDLLIMPEXP_GIS_GP wxGISTaskBase :
126  public wxObject,
128 {
129  DECLARE_CLASS(wxGISTaskBase)
130 public:
131  wxGISTaskBase(wxGISTaskBase *pParentTask = NULL);
132  virtual ~wxGISTaskBase(void);
133  virtual wxString GetName() const;
134  virtual wxString GetLastError() const;
135  virtual int GetId(void) const;
136  virtual wxGISEnumTaskStateType GetState(void) const;
137  virtual bool Delete(void);
141  virtual wxJSONValue GetConfig(void);
142  virtual void NetMessage(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, const wxJSONValue &val);
143  virtual size_t GetSubTaskCount(void) const;
144  virtual wxGISTaskBase* GetSubTask(size_t nIndex) const;
145  virtual wxGISTaskBase* GetSubTask(int nId) const;
146  virtual int GetRunTaskCount(void) const;
147  virtual void ChangeTask(const wxJSONValue &val);
148  virtual void AddTask(const wxJSONValue &val);
149  virtual bool RenameTask(const wxString& sNewName);
150  //
151  virtual void OnSubTaskChanged(int nId);
152  //NET messages
153  virtual void SendNetMessageAsync(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, const wxJSONValue &val);
154  virtual wxGISNetCommandState SendNetMessageSync(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, const wxJSONValue &val);
155 protected:
156  virtual void Delete(wxGISTaskBase *pTask);
157  virtual void ClearTasks(void);
158  virtual void NetCommand(wxGISNetCommandState eCmdState, const wxJSONValue &val);
159  virtual void NetNote(wxGISNetCommandState eCmdState, const wxJSONValue &val);
160 protected:
161  wxGISTaskBase *m_pParentTask;
162  int m_nId;
163  wxString m_sName;
164  wxGISEnumTaskStateType m_nState;
165  wxString m_sLastError;
166  wxGISTaskMap m_omSubTasks;
167 };
168 
169 
177 class WXDLLIMPEXP_GIS_GP wxGISTask :
178  public wxGISTaskBase
179 {
180  DECLARE_CLASS(wxGISTask)
181 public:
182  wxGISTask(wxGISTaskBase *pParentTask = NULL, const wxJSONValue &TaskConfig = wxJSONValue());
183  virtual ~wxGISTask(void);
184  virtual wxString GetDescription(void) const;
185  virtual wxString GetExecutable(void) const;
186  virtual wxDateTime GetDateBegin(void) const;
187  virtual wxDateTime GetDateEnd(void) const;
188  virtual wxDateTime GetDateCreated(void) const;
189  virtual wxULongLong GetVolume(void) const;
190  virtual long GetPriority(void) const;
191  virtual void SetPriority(long nPriority);
192  virtual double GetDone(void) const;
193  virtual void SetState(wxGISEnumTaskStateType eState);
194  virtual int GetChildrenCount() const;
198  virtual wxJSONValue GetParameters(void) const;
202  virtual wxJSONValue GetConfig(void);
203  virtual void AddSubTask(wxGISTask* pTask);
204 
205  virtual void ChangeTask(const wxJSONValue &val);
206  virtual wxGISTaskMessagesArray GetMessages(void) const;
207  virtual wxGISTaskMessage GetMessage(long nMessageId) const;
208  virtual void AddMessage(wxGISTaskMessage* pMessage);
209  virtual bool StartTask(bool bWait = false);
210  virtual bool StopTask(bool bWait = false);
211 protected:
212  virtual void NetNote(wxGISNetCommandState eCmdState, const wxJSONValue &val);
213 protected:
214  wxString m_sDescription;
215  wxDateTime m_dtBeg, m_dtEnd, m_dtCreated;
216  wxString m_sExecPath;
217  wxULongLong m_nVolume;//value in, eg. bytes
218  long m_nPriority;
219  int m_nGroupId;
220  double m_dfDone;
221  wxJSONValue m_Params;
222  wxGISTaskMessagesArray m_oaMessages;
223  int m_nChildrenCount;
224 };
225 
233 class WXDLLIMPEXP_GIS_GP wxGISTaskEdit :
234  public wxGISTask
235 {
236  DECLARE_CLASS(wxGISTaskEdit)
237 public:
238  wxGISTaskEdit(void);
239  virtual ~wxGISTaskEdit(void);
240  virtual void SetName(const wxString& sName);
241  virtual void SetDescription(const wxString& sDescription);
242  virtual void SetExecutable(const wxString& sExecutable);
243 };
244 
252 class WXDLLIMPEXP_GIS_GP wxGISTaskCategory :
253  public wxGISTaskBase
254 {
255  DECLARE_CLASS(wxGISTaskCategory)
256 public:
257  wxGISTaskCategory(const wxString &sName, wxGISTaskManager* pTaskManager);
258  virtual ~wxGISTaskCategory(void);
259  virtual void ProcessNetMessage(const wxNetMessage &msg);
260  virtual void SetMaxTaskExec(short nMaxExecTaskCount);
261  virtual bool CreateTask(wxGISTask* const pTask);
262  //NET messages
263  virtual void SendNetMessageAsync(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, const wxJSONValue &val);
264  virtual wxGISNetCommandState SendNetMessageSync(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, const wxJSONValue &val);
265 protected:
266  virtual void NetCommand(const wxNetMessage &msg);
267  virtual void NetNote(const wxNetMessage &msg);
268 protected:
269  wxGISTaskManager* m_pTaskManager;
270  short m_nMaxTasks;
271 };
272 
273  //wxGISEnumReturnType AddTask(const wxString &sCategory, int nMaxExecTaskCount, const wxString &sName, const wxString &sDesc, const wxString &sPath, long nPriority, const wxXmlNode *pParameters, wxString & sMsg);
274  //wxGISTaskMap GetTasks(void);
275  //wxGISTask* const GetTask(int nTaskId);
276  //wxGISEnumReturnType DeleteTask(int nTaskId, wxString & sMsg);
277  //wxGISEnumReturnType StartTask(int nTaskId, wxString & sMsg);
278  //wxGISEnumReturnType StopTask(int nTaskId, wxString & sMsg);
279  //wxGISEnumReturnType ChangeTaskPriority(int nTaskId, long nPriority, wxString & sMsg); TODO:
280 
281  //int GetRunTaskCount(const wxString& sCat);
282  //void AddTask(const wxXmlNode* pIniNode);
283  //void DeleteTask(const wxXmlNode* pIniNode);
284  //void ChangeTask(const wxXmlNode* pIniNode);
285  //void UpdateVolume(const wxXmlNode* pIniNode);
286  //void UpdatePercent(const wxXmlNode* pIniNode);
287  //void AddMessage(const wxXmlNode* pIniNode);
288  //void LoadTasks(const wxXmlNode* pTasksNode);
Definition: task.h:125
The JSON value class implementation.
Definition: jsonval.h:91
Task Manager Server communicate class.
Definition: tskmngr.h:89
Definition: pointer.h:34
The Task event.
Definition: task.h:85
Definition: message.h:42
Definition: task.h:252
Definition: task.h:233
Definition: task.h:37
Definition: task.h:177