-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBatchJobManager.cpp
More file actions
182 lines (150 loc) · 4.49 KB
/
BatchJobManager.cpp
File metadata and controls
182 lines (150 loc) · 4.49 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "BatchJobManager.h"
#include "wxFactory.h"
#include "wxConfigPath.h"
#include "wxWebcam/wxCamera.h"
BatchJobManager::BatchJobManager()
: m_active(false)
{
//ctor
}
BatchJobManager::~BatchJobManager()
{
//dtor
}
void BatchJobManager::DefineBatchJobs(const BatchList& batch_list)
{
// keep the GUI list
m_batch_list = batch_list;
// produce the list that will be consumed during exposure
m_batch_jobs.clear();
BatchList::iterator i = m_batch_list.begin();
while(i != m_batch_list.end()) {
const ExpNumSpec& expnum = *i++;
if(expnum.active) {
m_batch_jobs.push_back(BatchJob(expnum.exptime,expnum.numexp));
}
}
// Job confirmed, save to config at this stage
SaveToConfig();
}
BatchJobManager::iterator BatchJobManager::begin()
{
return m_batch_list.begin();
}
BatchJobManager::iterator BatchJobManager::end()
{
return m_batch_list.end();
}
void BatchJobManager::setActive(bool active)
{
m_active = active;
}
bool BatchJobManager::active()
{
return m_active;
}
bool BatchJobManager::JobAvailable() // true if one is available with ActiveJob()
{
return (m_batch_jobs.size()>0);
}
BatchJob& BatchJobManager::ActiveJob() // get ref to Job on QueueHead
{
return m_batch_jobs.front();
}
bool BatchJobManager::CommitJob() // job is done, remove it
{
m_batch_jobs.pop_front();
return true;
}
// return total number of batch jobs
size_t BatchJobManager::size()
{
return m_batch_list.size();
}
size_t BatchJobManager::active_size()
{
size_t n_active = 0;
BatchList::iterator ib = m_batch_list.begin();
while(ib != m_batch_list.end()) {
const ExpNumSpec& expnum = *ib++;
if(expnum.active)n_active++;
}
return n_active;
}
// return number of remaining jobs
size_t BatchJobManager::remaining()
{
if(m_active) return m_batch_jobs.size();
else return 0;
}
void BatchJobManager::SaveToConfig()
{
if(wxCamera* cam = wxF()->cam()) {
wxConfig* config = wxF()->config();
// delete old batch job data
DeleteConfigJobs(config,cam);
// set path to new config dir
wxConfigPath path(config,ConfigPath(cam));
// write batch job entries
int counter = 0;
BatchList::iterator ib = m_batch_list.begin();
while(ib != m_batch_list.end()) {
const ExpNumSpec& expnum = *ib++;
int iactive = (expnum.active)? 1 : 0;
wxString keyword = wxString::Format(wxT("Batch%03i"),++counter);
wxString value = wxString::Format(wxT("%f/%d/%d"), expnum.exptime, expnum.numexp,iactive);
config->Write(keyword,value);
}
}
}
bool BatchJobManager::RestoreFromConfig()
{
// erase current content
m_batch_list.clear();
if(wxCamera* cam = wxF()->cam()) {
wxConfig* config = wxF()->config();
wxConfigPath path(config,ConfigPath(cam));
int counter = 0;
bool value_found = true;
while(value_found) {
wxString keyword;
keyword.Printf(wxT("Batch%03i"),++counter);
wxString value;
if(value_found = config->Read(keyword,&value,wxT(" "))) {
long numexp = 0;
double exptime = 0.0;
long iactive = 0;
// find the forward slash and extract the FITS keyword
int s1 = value.Find('/');
wxString s_exptime = value.Mid(0,s1);
s_exptime.Trim();
s_exptime.ToDouble(&exptime);
// extract the remaining string
value = value.Mid(s1+1);
value.Trim();
s1 = value.Find('/');
wxString s_numexp = value.Mid(0,s1);
s_numexp.Trim();
s_numexp.ToLong(&numexp);
wxString s_active = value.Mid(s1+1);
s_active.ToLong(&iactive);
bool active = (iactive == 1)? true : false;
// push the entry
m_batch_list.push_back(ExpNumSpec(exptime,numexp,active));
}
}
}
return (m_batch_list.size() > 0);
}
void BatchJobManager::DeleteConfigJobs(wxConfig* config, wxCamera* cam)
{
wxConfigPath path(config,ConfigPath(cam));
config->SetPath(wxT(".."));
config->DeleteGroup(wxT("Jobs"));
}
wxString BatchJobManager::ConfigPath(wxCamera* cam)
{
if(!cam)return _T("/Batch/Jobs");
wxString path = _T("/Batch/") + cam->CameraName() +_T("(")+ cam->CameraSerial() + _T(")/Jobs");
return path;
}