1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_FLOWTASK_H_
23 #define _U2_FLOWTASK_H_
24 
25 #include <U2Core/CmdlineTaskRunner.h>
26 
27 #include <U2Lang/WorkflowManager.h>
28 
29 namespace U2 {
30 
31 namespace Workflow {
32 class CommunicationChannel;
33 class Schema;
34 class WorkflowMonitor;
35 }  // namespace Workflow
36 using namespace Workflow;
37 
38 class U2LANG_EXPORT WorkflowAbstractRunner : public CmdlineTask {
39     Q_OBJECT
40 public:
41     WorkflowAbstractRunner(const QString &name, TaskFlags flags);
42     virtual QList<WorkerState> getState(Actor *) = 0;
43     virtual int getMsgNum(const Link *) = 0;
44     virtual int getMsgPassed(const Link *) = 0;
45 
46     const QList<WorkflowMonitor *> &getMonitors() const;
47 
48 protected:
49     QList<WorkflowMonitor *> monitors;
50 };  // WorkflowAbstractRunner
51 
52 class U2LANG_EXPORT WorkflowAbstractIterationRunner : public Task {
53     Q_OBJECT
54 public:
55     WorkflowAbstractIterationRunner(const QString &name, TaskFlags flags);
~WorkflowAbstractIterationRunner()56     virtual ~WorkflowAbstractIterationRunner() {
57     }
58     virtual WorkerState getState(const ActorId &actor) = 0;
59     virtual int getMsgNum(const Link *l) = 0;
60     virtual int getMsgPassed(const Link *l) = 0;
61 
62     virtual int getDataProduced(const ActorId &actor) = 0;
63 
64 signals:
65     void si_updateProducers();
66 };
67 
68 typedef QMap<ActorId, ActorId> ActorMap;
69 
70 class U2LANG_EXPORT WorkflowRunTask : public WorkflowAbstractRunner {
71     Q_OBJECT
72 public:
73     WorkflowRunTask(const Schema &, const ActorMap &rmap = ActorMap(), WorkflowDebugStatus *debugInfo = nullptr);
74     virtual QList<WorkerState> getState(Actor *);
75     virtual int getMsgNum(const Link *);
76     virtual int getMsgPassed(const Link *);
77 
78 private:
79     QString generateReport() const;
80     // CmdlineTask
81     QString getTaskError() const;
82 
83 signals:
84     void si_ticked();
85 
86 private:
87     QMap<ActorId, ActorId> rmap;
88     QList<Link *> flows;
89 
90 };  // WorkflowRunTask
91 
92 class WorkflowIterationRunTask : public WorkflowAbstractIterationRunner {
93     Q_OBJECT
94 public:
95     WorkflowIterationRunTask(const Schema &, WorkflowDebugStatus *initDebugInfo);
96     ~WorkflowIterationRunTask();
97     virtual void prepare();
98     virtual ReportResult report();
99 
100     virtual WorkerState getState(const ActorId &actor);
101     virtual int getMsgNum(const Link *l);
102     virtual int getMsgPassed(const Link *l);
103     virtual int getDataProduced(const ActorId &actor);
104 
105     WorkflowMonitor *getMonitor() const;
106 
107 signals:
108     void si_ticked();
109 
110 protected:
111     virtual QList<Task *> onSubTaskFinished(Task *subTask);
112 
113 private slots:
114     void sl_pauseStateChanged(bool isPaused);
115     void sl_busInvestigationIsRequested(const Workflow::Link *bus, int messageNumber);
116     void sl_busCountOfMessagesRequested(const Workflow::Link *bus);
117     void sl_singleStepIsRequested(const ActorId &actor);
118     void sl_convertMessages2Documents(const Workflow::Link *bus, const QString &messageType, int messageNumber, const QString &schemeName);
119 
120 private:
121     static TaskFlags getAdditionalFlags();
122 
123     QList<CommunicationChannel *> getActorLinks(const QString &actor);
124 
125     WorkflowContext *context;
126     Schema *schema;
127     Scheduler *scheduler;
128     QMap<ActorId, ActorId> rmap;
129     QMap<QString, CommunicationChannel *> lmap;
130 
131     WorkflowDebugStatus *debugInfo;
132     bool nextTickRestoring;
133     bool contextInitialized;
134 };
135 
136 }  // namespace U2
137 
138 #endif
139