1
2
3 #include "tasks.h"
4 #include "tconvert.h"
5 #include "casmfileinfo.h"
6 #include "util.h"
7 #include "texception.h"
8 #include "tsystem.h"
9
10 #define DDR_OUTPUTSCRIPT_FILENAME "D@D@R"
11
12 //==============================================================================
13
getFilePath()14 string SubmitPageTask::getFilePath() { return m_filePath; }
15
16 //------------------------------------------------------------------------------
17
setFilePath(const string & filePath)18 void SubmitPageTask::setFilePath(const string &filePath) {
19 m_filePath = filePath;
20 }
21
22 //------------------------------------------------------------------------------
23
getName()24 string SubmitPageTask::getName() { return m_name; }
25
26 //------------------------------------------------------------------------------
27
setName(const string & name)28 void SubmitPageTask::setName(const string &name) { m_name = name; }
29
30 //------------------------------------------------------------------------------
31
getDependencies()32 map<string, string> SubmitPageTask::getDependencies() { return m_depTasks; }
33
34 //------------------------------------------------------------------------------
35
setDependencies(const map<string,string> & tasks)36 void SubmitPageTask::setDependencies(const map<string, string> &tasks) {
37 m_depTasks = tasks;
38 }
39
40 //------------------------------------------------------------------------------
41
checkNameUnc()42 void SubmitPageTask::checkNameUnc() {
43 if (m_filePath == "") return;
44
45 TFilePath fp(m_filePath);
46 string uncString = "";
47 try {
48 uncString = convertToUncString(fp);
49 } catch (TException &) {
50 if (!TFileStatus(fp).doesExist()) {
51 string msg = toString(fp.getWideString()) + "\n";
52 msg += "File not found\n";
53 msg += "Please verify that the path is correct";
54 throw TException(msg);
55 }
56 }
57 }
58
59 //==============================================================================
60
CasmTask2()61 CasmTask2::CasmTask2() { setDefaultValue(); }
62
63 //------------------------------------------------------------------------------
64
CasmTask2(const string & s,const string & setupFilePath)65 CasmTask2::CasmTask2(const string &s, const string &setupFilePath)
66 : m_setupFile(setupFilePath) {
67 setCommandLine(s);
68 }
69
70 //------------------------------------------------------------------------------
71
setDefaultValue()72 void CasmTask2::setDefaultValue() {
73 m_taskChunksize = 1;
74 m_start = 0;
75 m_end = 9999;
76 m_step = 1;
77 m_filePath = "";
78 m_name = "";
79 m_outname = "";
80 m_firstFrame = 0;
81 m_lastFrame = 0;
82 m_reduction = 1;
83 m_moveType = M_BG_FRACMOVE;
84 m_prec = 32;
85 m_renderTile = 1.;
86 m_memChunk = 4.;
87 m_multimedia = false;
88 m_logfile = false;
89 m_cf = false;
90 m_restype = RES_TYPE_STANDARD;
91 m_noOverwrite = false;
92 m_clap = false;
93 m_mprocess = false;
94 m_numColumn = -1;
95 m_lineart = -1;
96 m_edgeAliasing = -1;
97 m_gamma = -1.;
98 m_bcScript = "";
99 m_acScript = "";
100 m_outputScript = "";
101 m_outputScriptArgument = "";
102 m_setupFile = "";
103 xsize = 0;
104 ysize = 0;
105 }
106
107 //------------------------------------------------------------------------------
108
setFileArg(const string & fp)109 void CasmTask2::setFileArg(const string &fp) {
110 TFilePath filePath = TFilePath(fp);
111 CasmFileInfo casmFileInfo(filePath);
112 int start, end;
113 bool interlaced;
114 casmFileInfo.getFrameRange(start, end, interlaced);
115
116 m_filePath = fp;
117 m_start = start;
118 m_end = end;
119 m_step = 1;
120
121 setName(TFilePath(fp).getName());
122 }
123
124 //------------------------------------------------------------------------------
125
getCommandLine() const126 string CasmTask2::getCommandLine() const {
127 string qualifiers, prgname, dirname, biname;
128
129 if (m_reduction != 1) qualifiers += " -shrink " + toString(m_reduction) + " ";
130
131 if (m_moveType != moveType::M_BG_FRACMOVE)
132 qualifiers +=
133 (m_moveType == moveType::M_FRACMOVE) ? " -fracmove " : " -intmove ";
134 if (m_prec == 64)
135 qualifiers += " -64bit";
136 else
137 qualifiers += " -32bit";
138
139 qualifiers += " -tile " + toString(m_renderTile) + " ";
140
141 qualifiers += " -mem " + toString(m_memChunk) + " ";
142
143 if (m_multimedia) {
144 if (m_numColumn < 0)
145 qualifiers += " -mm ";
146 else
147 qualifiers += " -mmsingle " + toString(m_numColumn) + " ";
148 }
149
150 if (m_logfile) qualifiers += " -logfile +output/casm_batches.log ";
151
152 if (m_lineart > -1) qualifiers += " -lineart " + toString(m_lineart) + " ";
153 if (m_edgeAliasing > -1)
154 qualifiers += " -edgealiasing " + toString(m_edgeAliasing) + " ";
155 if (m_gamma > -1.0) qualifiers += " -gamma " + toString(m_gamma) + " ";
156
157 switch (m_restype) {
158 CASE RES_TYPE_STANDARD : qualifiers += " -sq ";
159 CASE RES_TYPE_IMPROVED : qualifiers += " -iq ";
160 CASE RES_TYPE_HIGH : qualifiers += " -hq ";
161 }
162
163 if (m_cf) qualifiers += " -cf ";
164
165 if (m_noOverwrite) qualifiers += " -no_overwrite ";
166
167 if (m_clap) qualifiers += " -clap ";
168
169 if (m_bcScript != "") qualifiers += " -bc " + m_bcScript + " ";
170
171 if (m_acScript != "" && m_outputScript == "")
172 qualifiers += " -ac " + m_acScript + " ";
173
174 if (m_outputScript != "") {
175 bool outputToDdr = (m_outputScript == DDR_OUTPUTSCRIPT_FILENAME);
176
177 if (!outputToDdr) qualifiers += " -ac " + m_outputScript + " ";
178 if (m_outputScriptArgument != "") {
179 string entry_point = m_outputScriptArgument;
180 string parity = "odd";
181 int i;
182 i = entry_point.size();
183 if (i > 0 && entry_point[i - 1] == '+') {
184 parity = "even";
185 entry_point[i - 1] = '\0';
186 }
187 // convert_timecode_to_frame (entry_point);//??????
188 if (outputToDdr)
189 qualifiers += " -ddr " + entry_point + " ";
190 else {
191 string app;
192 #ifdef WIN32
193 app = " -ac_args \"$filename $count " + entry_point;
194 app += " " + parity;
195 app += " $total\" ";
196 qualifiers += app;
197 #else
198 app = " -ac_args '$filename $count " + entry_point;
199 app += " " + parity;
200 app += " $total' ";
201 qualifiers += " app;
202 #endif
203 }
204 } else {
205 if (outputToDdr)
206 qualifiers += " -ddr " + toString(0) + " ";
207 else
208 #ifdef WIN32
209 qualifiers += " -ac_args \"$filename $count $total\" ";
210 #else
211 qualifiers += " -ac_args '$filename $count $total' ";
212 #endif
213 }
214 }
215
216 qualifiers += " -step " + toString(m_step);
217
218 if (m_start > m_firstFrame || m_end < m_lastFrame)
219 qualifiers += " -range " + toString(m_start) + " " + toString(m_end) + " ";
220
221 // qualifiers += " -chunk "+toString(m_taskChunksize)+" ";
222
223 return qualifiers;
224 }
225
226 //------------------------------------------------------------------------------
227
228 static bool is_num(string word) {
229 string::iterator it = word.begin();
230 while (it != word.end()) {
231 if ((*it < '0' || *it > '9') && *it != '.') return false;
232 it++;
233 }
234 return true;
235 }
236
237 //------------------------------------------------------------------------------
238
239 static string cpy_word(string &word, string s) {
240 /* salto gli spazi bianchi iniziali */
241 string::iterator it = s.begin();
242 word = "";
243 string::iterator it2 = word.begin();
244 while (s[0] == ' ' || s[0] == '\t') it++;
245 if (s[0] == '\'' || s[0] == '\"') {
246 /* argomento fra virgolette */
247 char quote = *it++;
248 while (*it && *it != '\n') {
249 if (*it == '\\') {
250 it++;
251 if (*it == '\0' || *it == '\n') break;
252 switch (*it) {
253 CASE '\\' : *it2++ = '\\';
254 DEFAULT:
255 *it2++ = *it;
256 }
257 it++;
258 } else if (*it == quote) {
259 it++;
260 break;
261 } else
262 *it2++ = *it++;
263 }
264 } else {
265 /* argomento senza virgolette */
266 while (*it && *it != ' ' && *it != '\t' && *it != '\n') *it2++ = *it++;
267 }
268 //*word = '\0';
269
270 /* salto gli spazi bianchi finali */
271 while (*it == ' ' || *it == '\t') it++;
272 return s.erase(s.begin(), it);
273 }
274
275 //------------------------------------------------------------------------------
276
277 void CasmTask2::setCommandLine(const string &cmdLine) {
278 if (cmdLine.empty()) return;
279
280 setDefaultValue();
281 string s = cmdLine;
282 string::iterator it = s.begin();
283 string word;
284 while (it != s.end()) {
285 s = cpy_word(word, s);
286
287 if (word == "-64bit")
288 m_prec = 64;
289 else if (word == "-32bit")
290 m_prec = 32;
291 else if (word == "-sq")
292 m_restype = RES_TYPE_STANDARD;
293 else if (word == "-iq")
294 m_restype = RES_TYPE_IMPROVED;
295 else if (word == "-hq")
296 m_restype = RES_TYPE_HIGH;
297 else if (word == "-step") {
298 s = cpy_word(word, s);
299 if (is_num(word)) m_step = atoi(word.c_str());
300 } else if (word == "-range") {
301 s = cpy_word(word, s);
302 if (is_num(word)) m_start = atoi(word.c_str());
303 s = cpy_word(word, s);
304 if (is_num(word)) m_end = atoi(word.c_str());
305 } else if (word == "-shrink") {
306 s = cpy_word(word, s);
307 if (is_num(word)) m_reduction = atoi(word.c_str());
308 } else if (word == "-fracmove") {
309 m_moveType = M_FRACMOVE;
310 } else if (word == "-intmove") {
311 m_moveType = M_INTMOVE;
312 }
313 /* else
314 if (STR_EQ(word, "-64bit"))
315 task->prec = 64;
316 else
317 if (STR_EQ(word, "-32bit"))
318 task->prec = 32;*/
319 else if (word == "-tile") {
320 s = cpy_word(word, s);
321 if (is_num(word)) m_renderTile = atof(word.c_str());
322 } else if (word == "-mem") {
323 s = cpy_word(word, s);
324 if (is_num(word)) m_taskChunksize = atoi(word.c_str());
325 } else if (word == "-chunk") {
326 s = cpy_word(word, s);
327 if (is_num(word)) m_memChunk = atof(word.c_str());
328 } else if (word == "-mm") {
329 m_multimedia = true;
330 m_numColumn = -1;
331 } else if (word == "-mmsingle") {
332 m_multimedia = true;
333 s = cpy_word(word, s);
334 if (is_num(word)) m_numColumn = atoi(word.c_str());
335 } else if (word == "-lineart") {
336 s = cpy_word(word, s);
337 if (is_num(word)) m_lineart = atoi(word.c_str());
338 } else if (word == "-edgealiasing") {
339 s = cpy_word(word, s);
340 if (is_num(word)) m_edgeAliasing = atoi(word.c_str());
341 } else if (word == "-gamma") {
342 s = cpy_word(word, s);
343 if (is_num(word)) m_gamma = atof(word.c_str());
344 } else if (word == "-cf") {
345 m_cf = true;
346 } else if (word == "-no_overwrite") {
347 m_noOverwrite = true;
348 } else if (word == "-clap") {
349 m_clap = true;
350 } else if (word == "-bc") {
351 s = cpy_word(word, s);
352 m_bcScript = word;
353 } else if (word == "-ac") {
354 s = cpy_word(word, s);
355 m_outputScript = word;
356 } else if (word == "-ac_args") { /*
357 char output_script_argument[1024];
358 s = cpy_word(word, s);
359 if(parse_ac_args(output_script_argument, word))
360 task->output_script_argument = strsave(output_script_argument);*/
361 } else if (word == "-logfile") {
362 s = cpy_word(word, s);
363 m_logfile = true;
364 }
365 /* else
366 if (!word.compare("-range"))
367 {
368 s = cpy_word(word, s);
369 if (is_num(word))
370 task->start = atoi(word);
371 else
372 {
373 delete_job((TASK *)task);
374 return NULL;
375 }
376 s = cpy_word(word, s);
377 if (is_num(word))
378 task->end = atoi(word);
379 else
380 {
381 delete_job((TASK *)task);
382 return NULL;
383 }
384 }*/
385 /* else
386 if (*word!='\n' && *word!='\0')
387 {
388 t = tim_get_type(word);
389 if (*t == '.') t++;
390 if (FILESTR_NE(t, "casm"))
391 {
392 delete_job((TASK *)task);
393 // return NULL;
394 }
395 else
396 {
397 TCALLOC(task->casm_file, strlen(word)+1);
398 strcpy(task->casm_file, word);
399 compute_casm_range(task->casm_file, &(task->first_frame), &(task->last_frame),
400 &dummy);
401 if (task->start<task->first_frame)
402 task->start=task->first_frame;
403 if (task->end>task->last_frame)
404 task->end=task->last_frame;
405 task->xsize = task->ysize = 0;
406 casm_camera_size(task->casm_file, &task->xsize, &task->ysize);
407
408
409 }
410 }*/
411 it = s.begin();
412 }
413 }
414
415 //------------------------------------------------------------------------------
416
417 void CasmTask2::checkNameUnc() {
418 SubmitPageTask::checkNameUnc();
419 if (m_setupFile == "") return;
420
421 TFilePath fp(m_setupFile);
422 string uncString = "";
423 try {
424 uncString = convertToUncString(fp);
425 } catch (TException &) {
426 if (!TFileStatus(fp).doesExist()) {
427 string msg = toString(fp.getWideString()) + "\n";
428 msg += "File not found\n";
429 msg += "Please verify that the path is correct";
430 throw TException(msg);
431 }
432 }
433 }
434
435 //==============================================================================
436
437 ScriptTask::ScriptTask() { setDefaultValue(); }
438
439 //------------------------------------------------------------------------------
440
441 ScriptTask::ScriptTask(const string &s, const string &setupFilePath)
442 : m_setupFile(setupFilePath) {
443 setCommandLine(s);
444 }
445
446 //------------------------------------------------------------------------------
447
448 void ScriptTask::setFileArg(const string &fp) {
449 m_filePath = fp;
450 m_name = TFilePath(fp).getName();
451 }
452
453 //------------------------------------------------------------------------------
454
455 string ScriptTask::getCommandLine() const {
456 string cmdLine;
457 if (m_filePath == "") {
458 assert(false);
459 return "";
460 }
461 #ifdef WIN32
462 /*
463 if (is_fg)
464 cmdLine = m_filePath;
465 else
466 */
467 // viene sempre fatto girare in background
468 cmdLine = "CALL " + m_filePath + " ";
469 #else
470 cmdLine = m_filePath;
471 #endif
472 cmdLine += " ";
473
474 if (m_arg1 != "") cmdLine += m_arg1 + " ";
475 if (m_arg2 != "") cmdLine += m_arg2 + " ";
476 if (m_arg3 != "") cmdLine += m_arg3 + " ";
477 if (m_arg4 != "") cmdLine += m_arg4 + " ";
478 if (m_arg5 != "") cmdLine += m_arg5 + " ";
479 return cmdLine;
480 }
481
482 //------------------------------------------------------------------------------
483
484 void ScriptTask::setCommandLine(const string &cmdLine) {
485 setDefaultValue();
486 string s = cmdLine;
487 string word;
488 if (s == "") {
489 s = cpy_word(word, s);
490 // if (word == "")
491 m_arg1 = word;
492 // else
493 // m_arg1 = "";
494 }
495 if (s == "") {
496 s = cpy_word(word, s);
497 // if (word == "")
498 m_arg2 = word;
499 }
500 if (s == "") {
501 s = cpy_word(word, s);
502 // if (word == "")
503 m_arg3 = word;
504 }
505 if (s == "") {
506 s = cpy_word(word, s);
507 // if (word == "")
508 m_arg4 = word;
509 }
510 if (s == "") {
511 s = cpy_word(word, s);
512 // if (word == "")
513 m_arg5 = word;
514 }
515 }
516
517 //------------------------------------------------------------------------------
518
519 void ScriptTask::setDefaultValue() {
520 m_name = "";
521 m_filePath = "";
522 m_setupFile = "";
523 m_arg1 = "";
524 m_arg2 = "";
525 m_arg3 = "";
526 m_arg4 = "";
527 m_arg5 = "";
528 }
529
530 //------------------------------------------------------------------------------
531
532 void ScriptTask::checkNameUnc() {
533 SubmitPageTask::checkNameUnc();
534 if (m_arg1 == "") return;
535
536 TFilePath fp(m_arg1);
537 string uncString = "";
538 try {
539 uncString = convertToUncString(fp);
540 } catch (TException &) {
541 if (!TFileStatus(fp).doesExist()) {
542 string msg = toString(fp.getWideString()) + "\n";
543 msg += "File not found\n";
544 msg += "Please verify that the path is correct";
545 throw TException(msg);
546 }
547 }
548 }
549