1 #pragma once
2 
3 #ifndef TFARMTASK_H
4 #define TFARMTASK_H
5 
6 #include <memory>
7 
8 #include <QDateTime>
9 #include "tpersist.h"
10 #include "tfarmplatforms.h"
11 #include "tfilepath.h"
12 #ifdef TFARMAPI
13 
14 #undef TFARMAPI
15 #endif
16 
17 #ifdef _WIN32
18 #ifdef TFARM_EXPORTS
19 #define TFARMAPI __declspec(dllexport)
20 #else
21 #define TFARMAPI __declspec(dllimport)
22 #endif
23 #else
24 #define TFARMAPI
25 #endif
26 
27 //------------------------------------------------------------------------------
28 
29 const int cPortNumber = 51005;
30 
31 enum TaskState { Suspended, Waiting, Running, Completed, Aborted, TaskUnknown };
32 
33 enum FrameState { FrameDone, FrameFailed };
34 
35 enum OverwriteBehavior { Overwrite_All = 0, Overwrite_NoPaint, Overwrite_Off };
36 
37 #define RENDER_LICENSE_NOT_FOUND 888
38 
39 //------------------------------------------------------------------------------
40 
41 class TFARMAPI TFarmTask : public TPersist {
42 public:
43   typedef QString Id;
44 
45   class TFARMAPI Dependencies {
46   public:
47     Dependencies();
48     ~Dependencies();
49 
50     Dependencies(const Dependencies &);
51     Dependencies &operator=(const Dependencies &);
52 
53     bool operator==(const Dependencies &);
54     bool operator!=(const Dependencies &);
55 
56     void add(const QString &id);
57     void remove(const QString &id);
58 
59     int getTaskCount() const;
60     QString getTaskId(int i) const;
61 
62   private:
63     class Data;
64     Data *m_data;
65   };
66 
67 public:
68   Id m_id;        //!< Internal task identifier
69   Id m_parentId;  //!< Task id of the parent task (if any)
70 
71   bool m_isComposerTask;  //!< Whether this is a tcomposer task (opposed to
72                           //! tcleanupper task)
73 
74   QString m_name;               //!< User-readable name
75   TFilePath m_taskFilePath;     //!< Path of the input file affected by the task
76   TFilePath m_outputPath;       //!< Path of the task's output file
77   QString m_callerMachineName;  //!< Name of the... caller (submitter?) machine
78 
79   int m_priority;  //!< Priority value used for scheduling order
80 
81   QString m_user;      //!< User who submitted the task
82   QString m_hostName;  //!< Machine on which the task was submitted
83 
84   TaskState
85       m_status;      //!< The task's status (completed, work in progress... etc)
86   QString m_server;  //!< Server node (name) the task was supplied to
87 
88   QDateTime m_submissionDate;
89   QDateTime m_startDate;
90   QDateTime m_completionDate;
91 
92   int m_successfullSteps;  //
93   int m_failedSteps;       //
94   int m_stepCount;  // Why 3 values ? One should be found with the other 2!
95 
96   int m_from, m_to, m_step, m_shrink;  //!< Range data
97   int m_chunkSize;                     //!< Sub-tasks size
98 
99   int m_multimedia;
100   int m_threadsIndex;
101   int m_maxTileSizeIndex;
102 
103   OverwriteBehavior m_overwrite;
104   bool m_onlyVisible;
105 
106   TFarmPlatform m_platform;
107 
108   Dependencies *m_dependencies;
109 
110 public:
111   TFarmTask(const QString &name = "");
112 
113   TFarmTask(const QString &id, const QString &name, const QString &cmdline,
114             const QString &user, const QString &host, int stepCount,
115             int priority);
116 
117   TFarmTask(const QString &id, const QString &name, bool composerTask,
118             const QString &user, const QString &host, int stepCount,
119             int priority, const TFilePath &taskFilePath,
120             const TFilePath &outputPath, int from, int to, int step, int shrink,
121             int multimedia, int chunksize, int threadsIndex,
122             int maxTileSizeIndex, OverwriteBehavior overwrite,
123             bool onlyvisible);
124 
~TFarmTask()125   virtual ~TFarmTask() { delete m_dependencies; }
126 
127   TFarmTask(const TFarmTask &);
128   TFarmTask &operator=(const TFarmTask &);
129 
130   bool operator==(const TFarmTask &task);
131   bool operator!=(const TFarmTask &task);
132 
getTaskCount()133   virtual int getTaskCount() const { return 1; }
getTask(int index)134   virtual TFarmTask *getTask(int index) { return this; }
135 
136   QString getCommandLine(bool isFarmTask = false) const;
137   void parseCommandLine(QString commandLine);
138 
139   // TPersist
140   void loadData(TIStream &is) override;
141   void saveData(TOStream &os) override;
142   const TPersistDeclaration *getDeclaration() const override;
143 };
144 
145 //------------------------------------------------------------------------------
146 
147 class TFARMAPI TFarmTaskGroup final : public TFarmTask {
148 public:
149   TFarmTaskGroup();
150 
151   TFarmTaskGroup(const QString &id, const QString &name, const QString &user,
152                  const QString &host, int stepCount, int priority,
153                  const TFilePath &taskFilePath, const TFilePath &outputPath,
154                  int from, int to, int step, int shrink, int multimedia,
155                  int chunksize, int threadsIndex, int maxTileSizeIndex);
156 
157   TFarmTaskGroup(const QString &id, const QString &name, const QString &user,
158                  const QString &host, int stepCount, int priority,
159                  const TFilePath &taskFilePath, OverwriteBehavior overwrite,
160                  bool onlyvisible);
161 
162   TFarmTaskGroup(const QString &id, const QString &name, const QString &cmdline,
163                  const QString &user, const QString &host, int stepCount,
164                  int priority);
165 
166   TFarmTaskGroup(const TFarmTaskGroup &src);
167 
168   ~TFarmTaskGroup();
169 
170   void addTask(TFarmTask *task);
171   void removeTask(TFarmTask *task);
172 
173   int getTaskCount() const override;
174   TFarmTask *getTask(int index) override;
175   bool changeChunkSize(int chunksize);
176 
177   // TPersist
178   void loadData(TIStream &is) override;
179   void saveData(TOStream &os) override;
180   const TPersistDeclaration *getDeclaration() const override;
181 
182 private:
183   class Imp;
184   std::unique_ptr<Imp> m_imp;
185 };
186 
187 #endif
188