Version: 0.6.0
task.h
1 /******************************************************************************
2  * Project: wxGIS (Task Manager)
3  * Purpose: Task and TaskCategoryList classes.
4  * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2012-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 
22 #pragma once
23 
24 #include "wxgis/tskmngr_app/tskmngr.h"
25 #include "wxgis/core/process.h"
26 #include "wxgis/core/json/jsonval.h"
27 
28 #include <wx/dynarray.h>
29 #include <wx/thread.h>
30 #define SUBTSKDIR wxT("subtasks")
31 
32 class wxGISTaskBase;
33 WX_DECLARE_HASH_MAP( int, wxGISTaskBase*, wxIntegerHash, wxIntegerEqual, wxGISTaskMap );
34 
35 
43 class wxGISTaskBase :
44  public wxObject
45 {
46  DECLARE_ABSTRACT_CLASS(wxGISTaskBase)
47 public:
48  wxGISTaskBase(wxGISTaskBase *pParentTask);
49  virtual ~wxGISTaskBase(void);
50  virtual wxString GetName() const;
51  virtual int GetId(void) const;
52  virtual int GetNewId(void);
53  virtual void Delete(wxGISTaskBase *pTask);
54  virtual bool HasName(const wxString &sName) const;
55  //start/stop
56  virtual void OnDestroy(void);
57  virtual void StartNextQueredTask(void);
58  //sorage
59  virtual wxString GetNewStorePath(const wxString &sAddToName, const wxString &sSubDir = wxEmptyString );
60  virtual wxString GetStorePath() const;
61  virtual bool Save(void);
62  virtual bool Load(void) = 0;
63  //network
64  virtual void SendNetMessage(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, wxGISMessagePriority ePrio, const wxJSONValue &val, const wxString &sMsg, long nMessageId = wxNOT_FOUND, int nUserId = wxNOT_FOUND) = 0;
65  virtual void NetMessage(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, const wxJSONValue &val, long nMessageId = wxNOT_FOUND, int nUserId = wxNOT_FOUND) = 0;
66  virtual void NetCommand(wxGISNetCommandState eCmdState, const wxJSONValue &val, long nMessageId = wxNOT_FOUND, int nUserId = wxNOT_FOUND) = 0;
67 protected:
68  virtual wxJSONValue GetStoreConfig(void) = 0;
69  virtual void ClearTasks(void);
70 
71  //virtual void SendNetMessageAsync(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, const wxJSONValue &val);
72  //virtual wxGISNetCommandState SendNetMessageSync(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, const wxJSONValue &val);
73  //virtual void NetMessage(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, const wxJSONValue &val);
74  //virtual void NetCommand(wxGISNetCommandState eCmdState, const wxJSONValue &val);
75  //virtual void NetNote(wxGISNetCommandState eCmdState, const wxJSONValue &val);
76 protected:
77  wxGISTaskBase *m_pParentTask;
78  int m_nId, m_nTaskCounter;
79  wxString m_sName, m_sStoragePath;
80  wxString m_sLastError;
81  wxGISTaskMap m_omSubTasks;
82 };
83 
84 class wxGISTask;
85 
86 WX_DEFINE_ARRAY(wxGISTask *, wxGISQueredTasksArray);
87 
95 class wxGISTask :
96  public wxGISTaskBase,
97  public wxGISProcess
98 {
99  DECLARE_CLASS(wxGISTask)
100 public:
101  wxGISTask(wxGISTaskBase* pParentTask, const wxString &sPath);
102  virtual ~wxGISTask(void);
103  virtual int GetGroupId(void) const;
104  virtual bool Load(void);
105  virtual bool Delete(long nMessageId = -2, int nUserId = -2);
106  virtual void GetChildren(long nMessageId, int nUserId);
107  virtual bool StartTask(long nMessageId, int nUserId);
108  virtual bool StopTask(long nMessageId, int nUserId);
109  virtual bool ChangeTask(const wxJSONValue& TaskVal, long nMessageId, int nUserId);
110  virtual bool Create(const wxJSONValue& TaskConfig);
111  virtual wxJSONValue GetAsJSON(void);
112  virtual long GetCommonPriority(void);
113 
114 
115  //start/process/stop
116  virtual void OnDestroy(void);
117  virtual void OnStart(void);
118  virtual void OnStop(void);
119  virtual void OnTerminate(int pid, int status);
120  virtual int GetRunningTaskCount(void) const;
121  virtual void GetQueredTasks(wxGISQueredTasksArray &oaTasks);
122  virtual void ChangeTask(void);
123  virtual void ChangeTaskMsg(wxGISEnumMessageType nType, const wxString &sInfoData);
124 
125  //
126  virtual long Execute(void);
127  virtual bool IsGroupIdExecuting(int nGroupId) const;
128  virtual void AddInfo(wxGISEnumMessageType nType, const wxString &sInfoData);
129 
130  virtual void UpdatePercent(const wxString &sPercentData);
131  //virtual void SetPriority(long nNewPriority);
132  //virtual long GetPriority(void) const {return m_nPriority;};
133  virtual bool Start(void);
134  //virtual size_t GetMessageCount() const {return m_staMessages.size();};
135 
136  typedef struct _message
137  {
138  wxString m_sMessage;
139  wxDateTime m_dt;
140  wxGISEnumMessageType m_nType;
141  }MESSAGE;
142  //virtual wxGISTask::MESSAGE GetMessage(size_t nIndex) const {return m_staMessages[nIndex];};
143  virtual void SendNetMessage(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, wxGISMessagePriority ePrio, const wxJSONValue &val, const wxString &sMsg, long nMessageId = wxNOT_FOUND, int nUserId = wxNOT_FOUND);
144  virtual void NetMessage(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, const wxJSONValue &val, long nMessageId = wxNOT_FOUND, int nUserId = wxNOT_FOUND);
145  virtual void NetCommand(wxGISNetCommandState eCmdState, const wxJSONValue &val, long nMessageId = wxNOT_FOUND, int nUserId = wxNOT_FOUND);
146 protected:
147  virtual wxJSONValue GetStoreConfig(void);
148 protected:
149  wxString m_sDescription;
150  int m_nGroupId;
151  wxULongLong m_nVolume;//value in, eg. bytes
152  wxString m_sExecPath;
153  long m_nPriority;
154  wxJSONValue m_Params;
155  double m_dfPrevDone;
156  wxDateTime m_dtCreated;
157  //wxVector<MESSAGE> m_staMessages;
158 };
159 
167 class wxGISTaskCategory :
168  public wxGISTaskBase
169 {
170  DECLARE_CLASS(wxGISTaskCategory)
171 public:
172  wxGISTaskCategory(const wxString &sPath, wxGISTaskManager* pTaskManager);
173  virtual ~wxGISTaskCategory(void);
174  virtual bool Load(void);
175  virtual void SetMaxExecTaskCount(int nMaxExecTasks);
176  virtual wxString GetNewStorePath(const wxString &sAddToName, const wxString &sSubDir = wxEmptyString );
177  virtual bool Save(void);
178  virtual void GetChildren(long nMessageId, int nUserId);
179  virtual bool AddTask(const wxJSONValue &TaskConfig, long nMessageId, int nUserId);
180  //start/stop
181  virtual bool IsGroupIdExecuting(int nGroupId) const;
182  virtual int GetRunningTaskCount(void) const;
183  virtual void GetQueredTasks(wxGISQueredTasksArray &oaTasks);
184 
185 // bool ChangeTaskPriority(int nTaskId, long nPriority, int nId, wxString &sErrMsg);
186 // bool ChangeTask(const wxXmlNode* pTaskNode, int nId, wxString &sErrMsg);
187 // bool GetTasks(int nId, wxString &sErrMsg);
188 // void GetTaskMessages(int nTaskId, int nId);
189 // wxString GetTaskConfigPath(const wxString& sCatName);
190 // bool SetMaxExecTasks(int nMaxTaskExec, wxString &sErrMsg);
191  virtual void StartNextQueredTask(void);
192  virtual void SendNetMessage(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, wxGISMessagePriority ePrio, const wxJSONValue &val, const wxString &sMsg, long nMessageId = wxNOT_FOUND, int nUserId = wxNOT_FOUND);
193  virtual void NetMessage(wxGISNetCommand eCmd, wxGISNetCommandState eCmdState, const wxJSONValue &val, long nMessageId = wxNOT_FOUND, int nUserId = wxNOT_FOUND);
194  virtual void NetCommand(wxGISNetCommandState eCmdState, const wxJSONValue &val, long nMessageId = wxNOT_FOUND, int nUserId = wxNOT_FOUND);
195 protected:
196  virtual wxJSONValue GetStoreConfig(void);
197  virtual wxGISTask* const GetQueredTask(void);
198 protected:
199  wxGISTaskManager* m_pTaskManager;
200  short m_nMaxTasks;
201  wxCriticalSection m_CritSect;
202 };
Definition: task.h:125
The JSON value class implementation.
Definition: jsonval.h:91
Task Manager Server communicate class.
Definition: tskmngr.h:89
The process class which stores the application execution data.
Definition: process.h:43
Definition: task.h:252
Definition: task.h:136
Definition: task.h:177