-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJob.h
121 lines (107 loc) · 2.75 KB
/
Job.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
This file is part of Leela Zero.
Copyright (C) 2017-2018 Marco Calignano
Leela Zero is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Leela Zero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Leela Zero. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef JOB_H
#define JOB_H
#include "Game.h"
#include "Result.h"
#include "Order.h"
#include <QObject>
#include <QAtomicInt>
#include <QTextStream>
#if defined(LEELA_GTP)
#include <functional>
#endif
class Management;
using VersionTuple = std::tuple<int, int, int>;
#if defined(LEELA_GTP)
typedef void (*SendMsgSignal)(int);
#endif
class Job : public QObject {
Q_OBJECT
public:
enum {
RUNNING = 0,
FINISHING,
STORING
};
enum {
Production = 0,
Validation
};
Job(QString gpu, Management *parent);
~Job() = default;
virtual Result execute() = 0;
virtual void init(const Order &o);
void finish() { m_state.store(FINISHING); }
void store() {
m_state.store(STORING);
}
#if defined(LEELA_GTP)
void connect_sendmessage(const QObject *arecver, const char *amember) {
connect(this, SIGNAL(sendmessage(int)),
arecver, amember, Qt::DirectConnection);
}
void should_sendmsg() { m_should_sendmsg = true; }
#endif
protected:
QAtomicInt m_state;
QString m_gpu;
int m_moves;
VersionTuple m_leelazMinVersion;
#if defined(LEELA_GTP)
bool m_should_sendmsg;
#endif
Management *m_boss;
#if defined(LEELA_GTP)
signals:
void sendmessage(int);
#endif
};
class ProductionJob : public Job {
Q_OBJECT
public:
ProductionJob(QString gpu, Management *parent);
~ProductionJob() = default;
void init(const Order &o);
Result execute();
private:
Engine m_engine;
QString m_sgf;
bool m_debug;
bool m_restore;
};
class ValidationJob : public Job {
Q_OBJECT
public:
ValidationJob(QString gpu, Management *parent);
~ValidationJob() = default;
void init(const Order &o);
Result execute();
private:
Engine m_engineFirst;
Engine m_engineSecond;
QString m_sgf;
};
class WaitJob : public Job {
Q_OBJECT
public:
WaitJob(QString gpu, Management *parent);
~WaitJob() = default;
void init(const Order &o);
Result execute();
private:
int m_minutes;
};
#endif // JOB_H