OnlineAstrometryParser::OnlineAstrometryParser() : AstrometryParser() { job_retries=0; solver_retries=0; networkManager = new QNetworkAccessManager(this); connect(this, SIGNAL(authenticateFinished()), this, SLOT(uploadFile())); connect(this, SIGNAL(uploadFinished()), this, SLOT(getJobID())); connect(this, SIGNAL(jobIDFinished()), this, SLOT(checkJobs())); connect(this, SIGNAL(jobFinished()), this, SLOT(checkJobCalibration())); // Reset parity on solver failure connect(this, &OnlineAstrometryParser::solverFailed, this, [&]() { parity = -1;}); connect(this, SIGNAL(solverFailed()), this, SLOT(resetSolver())); connect(this, SIGNAL(solverFinished(double,double,double, double)), this, SLOT(resetSolver())); downsample_factor = 0; isGenerated = true; }
int main(int argc, const char ** argv) { char command[MAX_COMMAND_LEN + 1]; char * nextCommand = NULL; struct jobSet jobList = { NULL, NULL }; struct job newJob; FILE * input = stdin; int i; int status; int inBg; if (argc > 2) { fprintf(stderr, "unexpected arguments; usage: ladsh1 " "<commands>\n"); exit(1); } else if (argc == 2) { input = fopen(argv[1], "r"); if (!input) { perror("fopen"); exit(1); } } /* don't pay any attention to this signal; it just confuses things and isn't really meant for shells anyway */ signal(SIGTTOU, SIG_IGN); while (1) { if (!jobList.fg) { /* no job is in the foreground */ /* see if any background processes have exited */ checkJobs(&jobList); if (!nextCommand) { if (getCommand(input, command)) break; nextCommand = command; } if (!parseCommand(&nextCommand, &newJob, &inBg) && newJob.numProgs) { runCommand(newJob, &jobList, inBg); } } else { /* a job is running in the foreground; wait for it */ i = 0; while (!jobList.fg->progs[i].pid) i++; waitpid(jobList.fg->progs[i].pid, &status, 0); jobList.fg->runningProgs--; jobList.fg->progs[i].pid = 0; if (!jobList.fg->runningProgs) { /* child exited */ removeJob(&jobList, jobList.fg); jobList.fg = NULL; /* move the shell to the foreground */ if (tcsetpgrp(0, getpid())) perror("tcsetpgrp"); } } } return 0; }
void OnlineAstrometryParser::onResult(QNetworkReply* reply) { bool ok; QJsonParseError parseError; QString status; QList<QVariant> jsonArray; int elapsed; if (workflowStage == NO_STAGE) { reply->abort(); return; } if (reply->error() != QNetworkReply::NoError) { align->appendLogText(reply->errorString()); emit solverFailed(); return; } QString json = (QString) reply->readAll(); QJsonDocument json_doc = QJsonDocument::fromJson(json.toUtf8(), &parseError); if (parseError.error != QJsonParseError::NoError) { align->appendLogText(i18n("JSon error during parsing (%1).", parseError.errorString())); emit solverFailed(); return; } QVariant json_result = json_doc.toVariant(); QVariantMap result = json_result.toMap(); if (Options::solverVerbose()) align->appendLogText(json_doc.toJson(QJsonDocument::Compact)); switch (workflowStage) { case AUTH_STAGE: status = result["status"].toString(); if (status != "success") { align->appendLogText(i18n("Astrometry.net authentication failed. Check the validity of the Astrometry.net API Key.")); emit solverFailed(); return; } sessionKey = result["session"].toString(); if (Options::solverVerbose()) align->appendLogText(i18n("Authentication to astrometry.net is successful. Session: %1", sessionKey)); emit authenticateFinished(); break; case UPLOAD_STAGE: status = result["status"].toString(); if (status != "success") { align->appendLogText(i18n("Upload failed.")); emit solverFailed(); return; } subID = result["subid"].toInt(&ok); if (ok == false) { align->appendLogText(i18n("Parsing submission ID failed.")); emit solverFailed(); return; } align->appendLogText(i18n("Upload complete. Waiting for astrometry.net solver to complete...")); emit uploadFinished(); if (isGenerated) QFile::remove(filename); break; case JOB_ID_STAGE: jsonArray = result["jobs"].toList(); if (jsonArray.isEmpty()) jobID = 0; else jobID = jsonArray.first().toInt(&ok); if (jobID == 0 || !ok) { if (job_retries++ < JOB_RETRY_ATTEMPTS) { QTimer::singleShot(JOB_RETRY_DURATION, this, SLOT(getJobID())); return; } else { align->appendLogText(i18n("Failed to retrieve job ID.")); emit solverFailed(); return; } } job_retries=0; emit jobIDFinished(); break; case JOB_STATUS_STAGE: status = result["status"].toString(); if (status == "success") emit jobFinished(); else if (status == "solving") { if (status == "solving" && solver_retries++ < SOLVER_RETRY_ATTEMPTS) { QTimer::singleShot(SOLVER_RETRY_DURATION, this, SLOT(checkJobs())); return; } else { align->appendLogText(i18n("Solver timed out.")); solver_retries=0; emit solverFailed(); return; } } else if (status == "failure") { elapsed = (int) round(solverTimer.elapsed()/1000.0); align->appendLogText(i18np("Solver failed after %1 second.", "Solver failed after %1 seconds.", elapsed)); emit solverFailed(); return; } break; case JOB_CALIBRATION_STAGE: parity = result["parity"].toInt(&ok); if (ok == false) { align->appendLogText(i18n("Error parsing parity.")); emit solverFailed(); return; } orientation = result["orientation"].toDouble(&ok); if (ok == false) { align->appendLogText(i18n("Error parsing orientation.")); emit solverFailed(); return; } orientation *= parity; ra = result["ra"].toDouble(&ok); if (ok == false) { align->appendLogText(i18n("Error parsing RA.")); emit solverFailed(); return; } dec = result["dec"].toDouble(&ok); if (ok == false) { align->appendLogText(i18n("Error parsing DEC.")); emit solverFailed(); return; } pixscale = result["pixscale"].toDouble(&ok); if (ok == false) { align->appendLogText(i18n("Error parsing DEC.")); emit solverFailed(); return; } elapsed = (int) round(solverTimer.elapsed()/1000.0); align->appendLogText(i18np("Solver completed in %1 second.", "Solver completed in %1 seconds.", elapsed)); emit solverFinished(orientation, ra, dec, pixscale); break; default: break; } }