void wwwauthenticate(HttpState *hs, char *line) { char cred[64], *user, *pass, *realm, *s, *spec, *name; Fmt fmt; UserPasswd *up; spec = nil; up = nil; cred[0] = 0; hs->autherror[0] = 0; if(cistrncmp(line, "basic ", 6) != 0){ werrstr("unknown auth: %s", line); goto error; } line += 6; if(cistrncmp(line, "realm=", 6) != 0){ werrstr("missing realm: %s", line); goto error; } line += 6; user = hs->c->url->user; pass = hs->c->url->passwd; if(user==nil || pass==nil){ realm = unquote(line, &line); fmtstrinit(&fmt); name = servername(hs->netaddr); fmtprint(&fmt, "proto=pass service=http server=%q realm=%q", name, realm); free(name); if(hs->c->url->user) fmtprint(&fmt, " user=%q", hs->c->url->user); spec = fmtstrflush(&fmt); if(spec == nil) goto error; if((up = auth_getuserpasswd(nil, "%s", spec)) == nil) goto error; user = up->user; pass = up->passwd; } if((s = smprint("%s:%s", user, pass)) == nil) goto error; free(up); enc64(cred, sizeof(cred), (uint8_t*)s, strlen(s)); memset(s, 0, strlen(s)); free(s); hs->credentials = smprint("Basic %s", cred); if(hs->credentials == nil) goto error; return; error: free(up); free(spec); snprint(hs->autherror, sizeof hs->autherror, "%r"); fprint(2, "%s: Authentication failed: %r\n", argv0); }
AlreadyOpen::AlreadyOpen(QString name, QWidget *w) { toBeRaised << w; server = new QLocalServer(this); QString sn = servername(name); if (!server->listen(sn)) { // old server lingering QLocalServer::removeServer(sn); if (!server->listen(sn)) { // couldn't remove. this is bad. qDebug() << "AlreadyOpen: Could not construct server. Sorry."; } } connect(server, SIGNAL(newConnection()), SLOT(raise())); connect(w, SIGNAL(newEditorCreated(QWidget *)), SLOT(addEditor(QWidget *))); connect(w, SIGNAL(destroyed(QObject *)), SLOT(dropEditor(QObject *))); }
CmdResult HandleServerTarget(User* source, const Params& parameters) { // If the source isn't allowed to mass message users then reject // the attempt to mass-message users. if (!source->HasPrivPermission("users/mass-message")) return CMD_FAILURE; // Extract the server glob match from the target parameter. std::string servername(parameters[0], 1); // Fire the pre-message events. MessageTarget msgtarget(&servername); CTCTags::TagMessageDetails msgdetails(parameters.GetTags()); if (!FirePreEvents(source, msgtarget, msgdetails)) return CMD_FAILURE; // If the current server name matches the server name glob then send // the message out to the local users. if (InspIRCd::Match(ServerInstance->Config->ServerName, servername)) { CTCTags::TagMessage message(source, "$*", parameters.GetTags()); const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers(); for (UserManager::LocalList::const_iterator iter = list.begin(); iter != list.end(); ++iter) { LocalUser* luser = IS_LOCAL(*iter); // Don't send to unregistered users or the user who is the source. if (luser->registered != REG_ALL || luser == source) continue; // Don't send to exempt users. if (msgdetails.exemptions.count(luser)) continue; // Send to users if they have the capability. if (cap.get(luser)) luser->Send(msgevprov, message); } } // Fire the post-message event. return FirePostEvent(source, msgtarget, msgdetails); }
/* download packages defined in packageList from repo to local path */ bool SensorUpdater::downloadPackagesToPath(const VersionList& packageList, const std::string& localPath) { // download and install the needed packages WebClient web_client(servername()); for (size_t i = 0; i < packageList.size(); i++) { std::cout << "Downloading " << packageList[i].package_name << " ... "; // download std::string pkg_filename = localPath + packageList[i].package_name + std::string(".deb"); bool ret = web_client.getFileToFile(packageList[i].path, pkg_filename); if (!ret) { std::cout << "failed.\n"; std::cout << "[ERROR]: Could not fetch update package from online repository! \n"; exit(1); } std::cout << "done.\n"; } std::cout << std::endl; return true; }
bool IRCdMessage::OnPrivmsg(const Anope::string &source, const std::vector<Anope::string> ¶ms) { const Anope::string &receiver = params.size() > 0 ? params[0] : ""; Anope::string message = params.size() > 1 ? params[1] : ""; /* Messages from servers can happen on some IRCds, check for . */ if (source.empty() || receiver.empty() || message.empty() || source.find('.') != Anope::string::npos) return true; User *u = finduser(source); if (!u) { Log() << message << ": user record for " << source << " not found"; BotInfo *bi = findbot(receiver); if (bi) ircdproto->SendMessage(bi, source, "%s", "Internal error - unable to process request."); return true; } if (receiver[0] == '#') { Channel *c = findchan(receiver); if (c) { FOREACH_MOD(I_OnPrivmsg, OnPrivmsg(u, c, message)); } } else { /* If a server is specified (nick@server format), make sure it matches * us, and strip it off. */ Anope::string botname = receiver; size_t s = receiver.find('@'); if (s != Anope::string::npos) { Anope::string servername(receiver.begin() + s + 1, receiver.end()); botname = botname.substr(0, s); if (!servername.equals_ci(Config->ServerName)) return true; } else if (Config->UseStrictPrivMsg) { BotInfo *bi = findbot(receiver); if (!bi) return true; Log(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << source; u->SendMessage(bi, _("\"/msg %s\" is no longer supported. Use \"/msg %s@%s\" or \"/%s\" instead."), receiver.c_str(), receiver.c_str(), Config->ServerName.c_str(), receiver.c_str()); return true; } BotInfo *bi = findbot(botname); if (bi) { EventReturn MOD_RESULT; FOREACH_RESULT(I_OnBotPrivmsg, OnBotPrivmsg(u, bi, message)); if (MOD_RESULT == EVENT_STOP) return true; if (message[0] == '\1' && message[message.length() - 1] == '\1') { if (message.substr(0, 6).equals_ci("\1PING ")) { Anope::string buf = message; buf.erase(buf.begin()); buf.erase(buf.end() - 1); ircdproto->SendCTCP(bi, u->nick, "%s", buf.c_str()); } else if (message.substr(0, 9).equals_ci("\1VERSION\1")) { Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); ircdproto->SendCTCP(bi, u->nick, "VERSION Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, enc ? enc->name.c_str() : "unknown", Anope::VersionBuildString().c_str()); } return true; } bi->OnMessage(u, message); } } return true; }
/** * \brief Main function of the snowstream application */ int main(int argc, char *argv[]) { debug_set_ident("snowstream"); snowstar::CommunicatorSingleton cs(argc, argv); Ice::CommunicatorPtr ic = CommunicatorSingleton::get(); int ccd_index = 0; astro::camera::Exposure exposure; unsigned short focusposition = 0; std::string filtername; double temperature = std::numeric_limits<double>::quiet_NaN(); int c; int longindex; while (EOF != (c = getopt_long(argc, argv, "b:c:C:deF:f:hp:?t:", longopts, &longindex))) { switch (c) { case 'b': exposure.mode(Binning(optarg)); break; case 'c': astro::config::Configuration::set_default(optarg); break; case 'C': ccd_index = atoi(optarg); break; case 'd': debuglevel = LOG_DEBUG; break; case 'e': exposure.exposuretime(atof(optarg)); break; case 'h': usage(argv[0]); return EXIT_SUCCESS; case 'p': exposure.purpose(astro::camera::Exposure::string2purpose(optarg)); break; case 'F': focusposition = std::stoi(optarg); break; case 'f': filtername = std::string(optarg); break; case 't': temperature = std::stod(optarg); break; case 1: exposure.frame(astro::image::ImageRectangle(optarg)); break; default: throw std::runtime_error("unknown option"); } } // next argument must be the service if (optind >= argc) { short_usage(argv[0]); throw std::runtime_error("service name missing"); } astro::ServerName servername(argv[optind++]); // next argument must be the instrment name if (optind >= argc) { short_usage(argv[0]); throw std::runtime_error("instrument name missing"); } std::string instrumentname(argv[optind++]); // check the configuration astro::config::ConfigurationPtr config = astro::config::Configuration::get(); // check the instrument if (0 == instrumentname.size()) { short_usage(argv[0]); throw std::runtime_error("instrument name not set"); } Ice::ObjectPrx base = ic->stringToProxy( servername.connect("Instruments")); InstrumentsPrx instruments = InstrumentsPrx::checkedCast(base); // create the remote instrument RemoteInstrument ri(instruments, instrumentname); // get the Ccd snowstar::CcdPrx ccd = ri.ccd(ccd_index); // check for focuser FocuserTask focusertask(ri, focusposition); // check for filter wheel FilterwheelTask filterwheeltask(ri, filtername); // check for cooler CoolerTask coolertask(ri, temperature); coolertask.stop_on_exit(true); // now wait for all tasks to complete, this arrangement allows for // all the tasks running in parallel filterwheeltask.wait(); // usually the fastest focusertask.wait(); coolertask.wait(); // usually takes longest // ImageSink to catch the images StreamSink *sink = new StreamSink(); Ice::ObjectPtr sinkptr = sink; CallbackAdapter adapter(ic); Ice::Identity ident = adapter.add(sinkptr); // register the adapter with the server ccd->ice_getConnection()->setAdapter(adapter.adapter()); ccd->registerSink(ident); // start the stream ccd->startStream(convert(exposure)); // wait for the sink to terminate (criterion not yet fixed sink->wait(); // stop and unregister the stream ccd->stopStream(); ccd->unregisterSink(); return EXIT_FAILURE; }
std::string InstrumentComponent::toString() { return stringprintf("%-16.16s %-8.8s %-32.32s %-2ld %s", type_name().c_str(), component_typename().c_str(), name().c_str(), unit(), servername().c_str()); }
bool CServerList::SaveServermetToFile() { if (thePrefs.GetLogFileSaving()) AddDebugLogLine(false, _T("Saving servers list file \"%s\""), SERVER_MET_FILENAME); m_nLastSaved = ::GetTickCount(); CString newservermet(thePrefs.GetMuleDirectory(EMULE_CONFIGDIR)); newservermet += SERVER_MET_FILENAME _T(".new"); CSafeBufferedFile servermet; CFileException fexp; if (!servermet.Open(newservermet, CFile::modeWrite|CFile::modeCreate|CFile::typeBinary|CFile::shareDenyWrite, &fexp)){ CString strError(GetResString(IDS_ERR_SAVESERVERMET)); TCHAR szError[MAX_CFEXP_ERRORMSG]; if (fexp.GetErrorMessage(szError, ARRSIZE(szError))){ strError += _T(" - "); strError += szError; } LogError(LOG_STATUSBAR, _T("%s"), strError); return false; } setvbuf(servermet.m_pStream, NULL, _IOFBF, 16384); try{ servermet.WriteUInt8(0xE0); UINT fservercount = list.GetCount(); servermet.WriteUInt32(fservercount); for (UINT j = 0; j < fservercount; j++) { const CServer* nextserver = GetServerAt(j); // don't write potential out-dated IPs of dynIP-servers servermet.WriteUInt32(nextserver->HasDynIP() ? 0 : nextserver->GetIP()); servermet.WriteUInt16(nextserver->GetPort()); UINT uTagCount = 0; ULONG uTagCountFilePos = (ULONG)servermet.GetPosition(); servermet.WriteUInt32(uTagCount); if (!nextserver->GetListName().IsEmpty()){ CTag servername(ST_SERVERNAME, nextserver->GetListName()); servername.WriteTagToFile(&servermet, utf8strOptBOM); uTagCount++; } if (!nextserver->GetDynIP().IsEmpty()){ CTag serverdynip(ST_DYNIP, nextserver->GetDynIP()); serverdynip.WriteTagToFile(&servermet, utf8strOptBOM); uTagCount++; } if (!nextserver->GetDescription().IsEmpty()){ CTag serverdesc(ST_DESCRIPTION, nextserver->GetDescription()); serverdesc.WriteTagToFile(&servermet, utf8strOptBOM); uTagCount++; } if (nextserver->GetFailedCount()){ CTag serverfail(ST_FAIL, nextserver->GetFailedCount()); serverfail.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetPreference() != SRV_PR_NORMAL){ CTag serverpref(ST_PREFERENCE, nextserver->GetPreference()); serverpref.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetUsers()){ CTag serveruser("users", nextserver->GetUsers()); serveruser.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetFiles()){ CTag serverfiles("files", nextserver->GetFiles()); serverfiles.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetPing()){ CTag serverping(ST_PING, nextserver->GetPing()); serverping.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetLastPingedTime()){ CTag serverlastp(ST_LASTPING, nextserver->GetLastPingedTime()); serverlastp.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetMaxUsers()){ CTag servermaxusers(ST_MAXUSERS, nextserver->GetMaxUsers()); servermaxusers.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetSoftFiles()){ CTag softfiles(ST_SOFTFILES, nextserver->GetSoftFiles()); softfiles.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetHardFiles()){ CTag hardfiles(ST_HARDFILES, nextserver->GetHardFiles()); hardfiles.WriteTagToFile(&servermet); uTagCount++; } if (!nextserver->GetVersion().IsEmpty()){ // as long as we don't receive an integer version tag from the local server (TCP) we store it as string CTag version(ST_VERSION, nextserver->GetVersion()); version.WriteTagToFile(&servermet, utf8strOptBOM); uTagCount++; } if (nextserver->GetUDPFlags()){ CTag tagUDPFlags(ST_UDPFLAGS, nextserver->GetUDPFlags()); tagUDPFlags.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetLowIDUsers()){ CTag tagLowIDUsers(ST_LOWIDUSERS, nextserver->GetLowIDUsers()); tagLowIDUsers.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetServerKeyUDP(true)){ CTag tagServerKeyUDP(ST_UDPKEY, nextserver->GetServerKeyUDP(true)); tagServerKeyUDP.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetServerKeyUDPIP()){ CTag tagServerKeyUDPIP(ST_UDPKEYIP, nextserver->GetServerKeyUDPIP()); tagServerKeyUDPIP.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetObfuscationPortTCP()){ CTag tagObfuscationPortTCP(ST_TCPPORTOBFUSCATION, nextserver->GetObfuscationPortTCP()); tagObfuscationPortTCP.WriteTagToFile(&servermet); uTagCount++; } if (nextserver->GetObfuscationPortUDP()){ CTag tagObfuscationPortUDP(ST_UDPPORTOBFUSCATION, nextserver->GetObfuscationPortUDP()); tagObfuscationPortUDP.WriteTagToFile(&servermet); uTagCount++; } servermet.Seek(uTagCountFilePos, CFile::begin); servermet.WriteUInt32(uTagCount); servermet.SeekToEnd(); } if (thePrefs.GetCommitFiles() >= 2 || (thePrefs.GetCommitFiles() >= 1 && !theApp.emuledlg->IsRunning())){ servermet.Flush(); // flush file stream buffers to disk buffers if (_commit(_fileno(servermet.m_pStream)) != 0) // commit disk buffers to disk AfxThrowFileException(CFileException::hardIO, GetLastError(), servermet.GetFileName()); } servermet.Close(); CString curservermet(thePrefs.GetMuleDirectory(EMULE_CONFIGDIR)); CString oldservermet(thePrefs.GetMuleDirectory(EMULE_CONFIGDIR)); curservermet += SERVER_MET_FILENAME; oldservermet += _T("server_met.old"); if (_taccess(oldservermet, 0) == 0) CFile::Remove(oldservermet); if (_taccess(curservermet, 0) == 0) CFile::Rename(curservermet,oldservermet); CFile::Rename(newservermet,curservermet); } catch(CFileException* error) { CString strError(GetResString(IDS_ERR_SAVESERVERMET2)); TCHAR szError[MAX_CFEXP_ERRORMSG]; if (error->GetErrorMessage(szError, ARRSIZE(szError))){ strError += _T(" - "); strError += szError; } LogError(LOG_STATUSBAR, _T("%s"), strError); error->Delete(); return false; } return true; }
bool SensorUpdater::getVersionsOnServer(VersionList* outPackageList, const REPOS& repo) { // clear the output list outPackageList->clear(); // query the ftp server std::string filelist; std::string repo_ftppath = REPOS_PATH.at(repo); // open ftp connection WebClient web_client(servername()); bool success = web_client.dirList(repo_ftppath, filelist); if (!success) return false; //extract filenames from filelist typedef boost::tokenizer<boost::char_separator<char> > tokenizer; boost::char_separator<char> sep(";"); tokenizer tokensL(filelist, sep); //loop through all filenames for (tokenizer::iterator tokL_iter = tokensL.begin(); tokL_iter != tokensL.end(); ++tokL_iter) { //get the filename std::string filename = *tokL_iter; //parse package file names //typical line: visensor-linux-1.0.1-Linux.deb //design and check on: http://regexpal.com/ boost::regex version_expression("([A-Za-z0-9-]+)-" "([0-9]+)\\." "([0-9]+)\\." "([0-9]+)-" "([A-Za-z0-9-]+)\\.deb"); boost::cmatch what; // find matches if( regex_match(filename.c_str(), what, version_expression) ) { // what[0] contains whole filename // what[1] contains the package name // what[2] contains the major version number // what[3] contains the minor version number // what[4] contains the patch version number // what[5] contains the arch VersionEntry package; package.package_name = what[1]; package.version_major = boost::lexical_cast<unsigned int>(what[2]); package.version_minor = boost::lexical_cast<unsigned int>(what[3]); package.version_patch = boost::lexical_cast<unsigned int>(what[4]); // store the relative ftp path (if we want to downlaod it later...) package.path = REPOS_PATH.at( repo ) + "/" + filename; // store the packages outPackageList->push_back(package); } else { //regex match failed (file is not a valid package name...) std::cout << "regex failed: " << filename.c_str() << "\n"; } } //now remove old version (only the newest version of each package should remain in the list return true; }
bool AlreadyOpen::check(QString fn) { QLocalSocket s; s.connectToServer(servername(fn)); bool r = s.waitForConnected(100); return r; }
/** * \brief Main function for the snowfocus program */ int main(int argc, char *argv[]) { debug_set_ident("snowfocus"); snowstar::CommunicatorSingleton cs(argc, argv); Ice::CommunicatorPtr ic = cs.get(); bool remote = false; int steps = 10; double exposuretime = 1.0; double temperature = std::numeric_limits<double>::quiet_NaN(); std::string binning; std::string frame; std::string filtername; astro::focusing::Focusing::method_type method = astro::focusing::Focusing::BRENNER; int c; int longindex; while (EOF != (c = getopt_long(argc, argv, "b:c:de:f:hi:m:r:Rt:", longopts, &longindex))) switch (c) { case 'b': binning = optarg; break; case 'c': astro::config::Configuration::set_default(optarg); break; case 'd': debuglevel = LOG_DEBUG; break; case 'e': exposuretime = std::stod(optarg); break; case 'f': filtername = optarg; break; case 'h': usage(argv[0]); return EXIT_SUCCESS; case 'm': method = astro::focusing::Focusing::string2method(optarg); break; case 'r': frame = optarg; break; case 'R': remote = true; break; case 's': steps = std::stoi(optarg); break; case 't': temperature = std::stod(optarg); break; default: throw std::runtime_error("unknown option"); } // the next argument is the command if (argc <= optind) { short_usage(argv[0]); throw std::runtime_error("missing service argument"); } std::string argument(argv[optind++]); if ("help" == argument) { usage(argv[0]); return EXIT_SUCCESS; } astro::ServerName servername(argument); if (argc <= optind) { short_usage(argv[0]); throw std::runtime_error("missing instrument name argument"); } // make sure the server offers instruments and guiding if (!remote) { astro::discover::ServiceDiscoveryPtr sd = astro::discover::ServiceDiscovery::get(); sd->start(); astro::discover::ServiceObject so = sd->find(sd->waitfor(argument)); if (!so.has(astro::discover::ServiceSubset::INSTRUMENTS)) { std::cerr << "service '" << argument; std::cerr << "' does not offer focusing service"; std::cerr << std::endl; return EXIT_FAILURE; } if (!so.has(astro::discover::ServiceSubset::FOCUSING)) { std::cerr << "service '" << argument; std::cerr << "' does not offer focusing service"; std::cerr << std::endl; return EXIT_FAILURE; } } std::string instrumentname(argv[optind++]); if (argc <= optind) { short_usage(argv[0]); throw std::runtime_error("missing command argument"); } std::string command = argv[optind++]; debug(LOG_DEBUG, DEBUG_LOG, 0, "command: %s", command.c_str()); // get a proxy for the instruments Ice::ObjectPrx base = ic->stringToProxy( servername.connect("Instruments")); InstrumentsPrx instruments = InstrumentsPrx::checkedCast(base); // get the configuration astro::config::ConfigurationPtr config = astro::config::Configuration::get(); // check whether we have an instrument if (0 == instrumentname.size()) { throw std::runtime_error("instrument name not set"); } RemoteInstrument instrument(instruments, instrumentname); // make sure the server names for focuser and ccd are identical astro::ServerName targetserver = instrument.servername(InstrumentCCD); if (targetserver != instrument.servername(InstrumentFocuser)) { throw std::runtime_error("ccd and focuser are on different " "servers"); } // get the device names CcdPrx ccdprx = instrument.ccd(); std::string ccdname = ccdprx->getName(); FocuserPrx focuserprx = instrument.focuser(); std::string focusername = focuserprx->getName(); debug(LOG_DEBUG, DEBUG_LOG, 0, "ccd: %s focuser: %s", ccdname.c_str(), focusername.c_str()); // first get a connection to the server Ice::ObjectPrx fbase = ic->stringToProxy( targetserver.connect("FocusingFactory")); FocusingFactoryPrx focusingfactory = FocusingFactoryPrx::checkedCast(fbase); // get the focusing interface FocusingPrx focusing = focusingfactory->get(ccdname, focusername); debug(LOG_DEBUG, DEBUG_LOG, 0, "got a focusing proxy"); // creating a callback Ice::ObjectPtr callback = new FocusCallbackI(); CallbackAdapter adapter(ic); Ice::Identity ident = adapter.add(callback); focusing->ice_getConnection()->setAdapter(adapter.adapter()); debug(LOG_DEBUG, DEBUG_LOG, 0, "callback installed"); // handle the simple commands if (command == "help") { short_usage(argv[0]); return EXIT_SUCCESS; } if (command == "status") { std::cout << "status: "; FocusState state = focusing->status(); std::cout << focusingstate2string(state); switch (state) { case FocusFOCUSED: std::cout << " "; std::cout << focusing->getFocuser()->current(); break; default: break; } std::cout << std::endl; return EXIT_SUCCESS; } if (command == "history") { show_history(focusing->history()); return EXIT_SUCCESS; } if (command == "monitor") { std::cout << "current status: "; std::cout << focusingstate2string(focusing->status()); std::cout << std::endl; focusing->registerCallback(ident); signal(SIGINT, handler); while (!signal_received) { sleep(1); } focusing->unregisterCallback(ident); return EXIT_SUCCESS; } if (command == "cancel") { focusing->cancel(); std::cout << "cancel command sent" << std::endl; return EXIT_SUCCESS; } if (command == "repository") { if (optind < argc) { std::string reponame(argv[optind]); focusing->setRepositoryName(reponame); } else { std::string reponame = focusing->getRepositoryName(); if (reponame.size() > 0) { std::cout << "repository: " << reponame; std::cout << std::endl; } else { std::cout << "repository not set" << std::endl; } } return EXIT_SUCCESS; } // throw exception for unknown commands if (command != "start") { short_usage(argv[0]); throw std::runtime_error("unknown command"); } debug(LOG_DEBUG, DEBUG_LOG, 0, "executing start command"); // make sure temperature is set CoolerTask coolertask(instrument, temperature); coolertask.stop_on_exit(true); coolertask.wait(); // next two arguments are the interval boundaries if ((argc - optind) < 2) { short_usage(argv[0]); throw std::runtime_error("missing interval arguments"); } int min = std::stoi(argv[optind++]); int max = std::stoi(argv[optind++]); debug(LOG_DEBUG, DEBUG_LOG, 0, "interval [%d,%d]", min, max); if (min >= max) { short_usage(argv[0]); throw std::runtime_error("not an interval"); } debug(LOG_DEBUG, DEBUG_LOG, 0, "focusing in interval [%d,%d]", min, max); // ensure that focuser is ready FocusState state = focusing->status(); debug(LOG_DEBUG, DEBUG_LOG, 0, "current state = %d", state); if ((state == FocusMOVING) && (state == FocusMEASURING)) { short_usage(argv[0]); throw std::runtime_error("already focusing"); } debug(LOG_DEBUG, DEBUG_LOG, 0, "focuser available"); // set up the exposure astro::camera::Exposure exposure; exposure.purpose(astro::camera::Exposure::focus); exposure.exposuretime(exposuretime); if (binning.size() > 0) { exposure.mode(astro::image::Binning(binning)); } exposure.shutter(astro::camera::Shutter::OPEN); if (frame.size() > 0) { exposure.frame(astro::image::ImageRectangle(frame)); } // set up the focusing focusing->setSteps(steps); focusing->setMethod(convert(method)); focusing->setExposure(convert(exposure)); debug(LOG_DEBUG, DEBUG_LOG, 0, "focusing set up %d steps, method %s", steps, astro::focusing::Focusing::method2string(method).c_str()); // start the focusing process debug(LOG_DEBUG, DEBUG_LOG, 0, "starting between %d and %d", min, max); focusing->start(min, max); debug(LOG_DEBUG, DEBUG_LOG, 0, "focusing started, status: %d", focusing->status()); // wait for the process to complete bool completed = false; signal(SIGINT, handler); do { sleep(1); switch (focusing->status()) { case FocusIDLE: case FocusMOVING: case FocusMEASURING: break; case FocusFOCUSED: case FocusFAILED: completed = true; break; } } while ((!completed) && (!signal_received)); if (completed) { std::cout << "final focus position: " << focuserprx->current(); std::cout << std::endl; // display the history show_history(focusing->history()); } else { std::cout << "focusing incomplete" << std::endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }