bool IndexerJob::visit(int build) { if (!mUnits.at(build).second) { abort(); return false; } clang_getInclusions(mUnits.at(build).second, IndexerJob::inclusionVisitor, this); if (isAborted()) return false; clang_visitChildren(clang_getTranslationUnitCursor(mUnits.at(build).second), IndexerJob::indexVisitor, this); if (isAborted()) return false; if (testLog(VerboseDebug)) { VerboseVisitorUserData u = { 0, "<VerboseVisitor " + mClangLines.at(build) + ">\n", this }; clang_visitChildren(clang_getTranslationUnitCursor(mUnits.at(build).second), IndexerJob::verboseVisitor, &u); u.out += "</VerboseVisitor " + mClangLines.at(build) + ">"; if (getenv("RTAGS_INDEXERJOB_DUMP_TO_FILE")) { char buf[1024]; snprintf(buf, sizeof(buf), "/tmp/%s.log", mSourceInformation.sourceFile.fileName()); FILE *f = fopen(buf, "w"); assert(f); fwrite(u.out.constData(), 1, u.out.size(), f); fclose(f); } else { logDirect(VerboseDebug, u.out); } } return !isAborted(); }
void BulkImport::loadCompileEarly(const QStringList& filepaths, const QString& qspec) { Progress prog(Progress::BULK_COMPILE_EARLY); reportProcessBegin(prog); for(int i=0; i<filepaths.length() && !isAborted(); i++){ const QString& filepath = filepaths.at(i); try{ cache()->importXmlFile(filepath, qspec); reportProgress(prog(filepaths.count(), i+1, QStringList() << filepath << filepath)); }catch(std::exception& ex){ prog.setTag(filepath); emit error(ex, prog); }catch(...){ prog.setTag(filepath); emit error(std::runtime_error("Unknown error!"), prog); } } reportProcessEnd(prog(Progress::BULK_COMPILE_EARLY)); if (isAborted()){ emit aborted(); }else{ emit finished(); } }
void ChangeRouterWanSettingsOp::onSoapFinished() { AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (isAborted()) { return; } int result = op->result(); if (result != NoError) { return notifyFinished(result); } QVariant varResponseCode = op->value("responseCode"); if (!varResponseCode.isValid()) { return notifyFinished(UnknownError); } bool ok; int responseCode = varResponseCode.toInt(&ok); if (!ok) { return notifyFinished(UnknownError); } notifyFinished(NoError); }
void CheckInternetOp::onConnectHostFinished() { AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (isAborted()) { LOG_DEBUG(QString::fromUtf8("connectHost self aborted!")); return; } if (op->isAborted()) { LOG_DEBUG(QString::fromUtf8("connectHost op aborted!")); return notifyFinished(AbortedError); } int result = op->result(); LOG_DEBUG(QString::fromUtf8("connectHost result: %1").arg(result)); if (result != NoError) { return retry(); } notifyFinished(NoError); }
/*! Invokes the abort-callback (if set) and closes/releases this connection. * * \see close() * \see HttpRequest::finish() */ void HttpConnection::abort() { TRACE("abort()"); if (isAborted()) return; //assert(!isAborted() && "The connection may be only aborted once."); flags_ |= IsAborted; if (isOutputPending()) { TRACE("abort: clearing pending output (%ld)", output_.size()); output_.clear(); } if (abortHandler_) { assert(request_ != nullptr); // the client aborted the connection, so close the client-socket right away to safe resources socket_->close(); abortHandler_(abortData_); } else { request_->clearCustomData(); close(); } }
void ReconnectRouterOp::onDiscoverRouterFinished() { AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (isAborted()) { LOG_DEBUG(QString::fromUtf8("discoverRouter self aborted!")); return; } if (op->isAborted()) { LOG_DEBUG(QString::fromUtf8("discoverRouter op aborted!")); return notifyFinished(AbortedError); } int result = op->result(); LOG_DEBUG(QString::fromUtf8("discoverRouterSoap result: %1").arg(result)); if (result != NoError) { return retry(); } int matchIndex = op->value("matchIndex").toInt(); LOG_DEBUG(QString::fromUtf8("matchIndex %1").arg(matchIndex)); if (matchIndex < 0) { return retry(); } copyValues(op); notifyFinished(NoError); }
void ReconnectRouterOp::onConnectProfileFinished() { AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (isAborted()) { LOG_DEBUG(QString::fromUtf8("connectProfile self aborted!")); return; } if (op->isAborted()) { LOG_DEBUG(QString::fromUtf8("connectProfile op aborted!")); return notifyFinished(AbortedError); } int result = op->result(); LOG_DEBUG(QString::fromUtf8("connectWlanProfile %1 result: %1").arg(m_wifiName).arg(result)); if (result == WlanProfileNotFound ) { LOG_DEBUG(QString::fromUtf8("recreate profile?")); notifyFinished(WlanProfileNotFound); } if (result != NoError) { return retry(); } discoverRouter(); }
void BaseOp::stagePostFinished() { if (isAborted() || m_reply == NULL) { DBGLOG(LOG_DEBUG, 10, QString::fromUtf8("Aborted at 'post' stage")); return report(WTFStatus_Aborted); } if (m_reply->error() != QNetworkReply::NoError) { DBGLOG(LOG_ERROR, 2, QString::fromUtf8("Network error, code=%1").arg(m_reply->error())); setProperty("varNetworkError", m_reply->error()); m_reply->deleteLater(); m_reply = NULL; return report(WTFStatus_NetworkError); } QByteArray responseData = m_reply->readAll(); m_reply->deleteLater(); m_reply = NULL; DBGLOG(LOG_DEBUG, 10, QString::fromUtf8("response data: %1").arg(QString::fromUtf8(responseData))); QVariantMap result; if (!parseResultXml(responseData, result)) { DBGLOG(LOG_DEBUG, 2, QString::fromUtf8("parseResultXml failed!")); result.clear(); } report(processImpl(responseData, result)); }
void EnsureSoapOp::onTimeout() { if (!isAborted()) { LOG_DEBUG(QString::fromUtf8("EnsureSoap: delayed retry start")); restart(); } }
/** start first async operation for this HttpConnection. * * This is done by simply registering the underlying socket to the the I/O service * to watch for available input. * * \note This method must be invoked right after the object construction. * * \see stop() */ void HttpConnection::start(ServerSocket* listener, Socket* client, const HttpWorker::ConnectionHandle& handle) { handle_ = handle; listener_ = listener; socket_ = client; socket_->setReadyCallback<HttpConnection, &HttpConnection::io>(this); sink_.setSocket(socket_); #if defined(TCP_NODELAY) if (worker_->server().tcpNoDelay()) socket_->setTcpNoDelay(true); #endif #if !defined(NDEBUG) setLoggingPrefix("HttpConnection[%d,%llu|%s:%d]", worker_->id(), id_, remoteIP().c_str(), remotePort()); #endif TRACE("starting (fd=%d)", socket_->handle()); ref(); // <-- this reference is being decremented in close() worker_->server_.onConnectionOpen(this); if (isAborted()) { // The connection got directly closed (aborted) upon connection instance creation (e.g. within the onConnectionOpen-callback), // so delete the object right away. close(); return; } request_ = new HttpRequest(*this); ref(); if (socket_->state() == Socket::Handshake) { TRACE("start: handshake."); socket_->handshake<HttpConnection, &HttpConnection::handshakeComplete>(this); } else { #if defined(TCP_DEFER_ACCEPT) && defined(WITH_TCP_DEFER_ACCEPT) TRACE("start: processing input"); // it is ensured, that we have data pending, so directly start reading if (readSome()) process(); else close(); TRACE("start: processing input done"); #else TRACE("start: watchInput."); // client connected, but we do not yet know if we have data pending watchInput(worker_->server_.maxReadIdle()); #endif } unref(); }
/** start first async operation for this HttpConnection. * * This is done by simply registering the underlying socket to the the I/O service * to watch for available input. * * \note This method must be invoked right after the object construction. * * \see stop() */ void HttpConnection::start(ServerSocket* listener, Socket* client) { setStatus(ReadingRequest); listener_ = listener; socket_ = client; socket_->setReadyCallback<HttpConnection, &HttpConnection::io>(this); sink_.setSocket(socket_); #if defined(TCP_NODELAY) if (worker_->server().tcpNoDelay()) socket_->setTcpNoDelay(true); #endif if (worker_->server().lingering()) socket_->setLingering(worker_->server().lingering()); TRACE(1, "starting (fd=%d)", socket_->handle()); ref(); // <-- this reference is being decremented in close() worker_->server_.onConnectionOpen(this); if (isAborted()) { // The connection got directly closed (aborted) upon connection instance creation (e.g. within the onConnectionOpen-callback), // so delete the object right away. close(); return; } if (!request_) request_ = new HttpRequest(*this); ref(); if (socket_->state() == Socket::Handshake) { TRACE(1, "start: handshake."); socket_->handshake<HttpConnection, &HttpConnection::handshakeComplete>(this); } else { #if defined(TCP_DEFER_ACCEPT) && defined(ENABLE_TCP_DEFER_ACCEPT) TRACE(1, "start: processing input"); // it is ensured, that we have data pending, so directly start reading io(nullptr, ev::READ); TRACE(1, "start: processing input done"); #else TRACE(1, "start: watchInput."); // client connected, but we do not yet know if we have data pending watchInput(worker_->server_.maxReadIdle()); #endif } unref(); }
/** write source into the connection stream and notifies the handler on completion. * * \param buffer the buffer of bytes to be written into the connection. * \param handler the completion handler to invoke once the buffer has been either fully written or an error occured. */ void HttpConnection::write(Source* chunk) { if (!isAborted()) { TRACE("write() chunk (%s)", chunk->className()); output_.push_back(chunk); watchOutput(); //writeSome(); } else { TRACE("write() ignore chunk (%s) - (connection aborted)", chunk->className()); delete chunk; } }
/** write source into the connection stream and notifies the handler on completion. * * \param buffer the buffer of bytes to be written into the connection. * \param handler the completion handler to invoke once the buffer has been either fully written or an error occured. */ void HttpConnection::write(Source* chunk) { if (!isAborted()) { TRACE(1, "write() chunk (%s)", chunk->className()); output_.push_back(chunk); if (autoFlush_) { flush(); } } else { TRACE(1, "write() ignore chunk (%s) - (connection aborted)", chunk->className()); delete chunk; } }
/** processes a (partial) request from buffer's given \p offset of \p count bytes. */ bool HttpConnection::process() { TRACE(2, "process: offset=%lu, size=%lu (before processing) %s, %s", inputOffset_, input_.size(), state_str(), status_str()); while (state() != MESSAGE_BEGIN || status() == ReadingRequest || status() == KeepAliveRead) { BufferRef chunk(input_.ref(inputOffset_)); if (chunk.empty()) break; // ensure status is up-to-date, in case we came from keep-alive-read if (status_ == KeepAliveRead) { TRACE(1, "process: status=keep-alive-read, resetting to reading-request"); setStatus(ReadingRequest); if (request_->isFinished()) { TRACE(1, "process: finalizing request"); request_->finalize(); } } TRACE(1, "process: (size: %lu, isHandlingRequest:%d, state:%s status:%s", chunk.size(), isHandlingRequest(), state_str(), status_str()); //TRACE(1, "%s", input_.ref(input_.size() - rv).str().c_str()); size_t rv = HttpMessageProcessor::process(chunk, &inputOffset_); TRACE(1, "process: done process()ing; fd=%d, request=%p state:%s status:%s, rv:%d", socket_->handle(), request_, state_str(), status_str(), rv); if (isAborted()) { TRACE(1, "abort detected"); return false; } if (state() == SYNTAX_ERROR) { TRACE(1, "syntax error detected"); if (!request_->isFinished()) { abort(HttpStatus::BadRequest); } TRACE(1, "syntax error detected: leaving process()"); return false; } if (rv < chunk.size()) { request_->log(Severity::debug1, "parser aborted early."); return false; } } TRACE(1, "process: offset=%lu, bs=%lu, state=%s (after processing) io.timer:%d", inputOffset_, input_.size(), state_str(), socket_->timerActive()); return true; }
void ChangeRouterWifiPasswordOp::onSetWLANFinished() { AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (isAborted()) { return; } int result = op->result(); LOG_DEBUG(QString::fromUtf8("onSetWLANFinished %1").arg(result)); if (result != NoError) { return notifyFinished(result); } QVariant varResponseCode = op->value("responseCode"); if (!varResponseCode.isValid()) { return notifyFinished(UnknownError); } bool ok; int responseCode = varResponseCode.toInt(&ok); if (!ok) { return notifyFinished(UnknownError); } if (responseCode != 0) { return notifyFinished(UnknownError); } if (m_configFinish) { m_op = m_bean->m_soapCore->invoke(QLatin1String("DeviceConfig"), QLatin1String("ConfigurationFinished"), QLatin1String("NewStatus"), QLatin1String("ChangesApplied")); connect(m_op, SIGNAL(finished()), SLOT(onCommitFinished())); connect(&m_timer1, SIGNAL(timeout()), SLOT(onTimeout1())); m_timer1.setSingleShot(true); m_timer1.start(8000); } else { notifyFinished(NoError); } }
void ChangeRouterWifiPasswordOp::onCommitFinished() { AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (isAborted()) { return; } LOG_DEBUG(QString::fromUtf8("onCommitFinished %1").arg(op->result())); notifyFinished(NoError); }
/** internally invoked when the response has been <b>fully</b> flushed to the client and we're to pass control back to the underlying connection. * * The request's reply has been fully transmitted to the client, so we are to invoke the request-done callback * and clear request-local custom data. * * After that, the connection gets either \p close()'d or will enter \p resume() state, to receive and process the next request. * * \see finish() */ void HttpRequest::finalize() { TRACE("finalize()"); connection.worker().server().onRequestDone(this); clearCustomData(); if (isAborted() || !connection.shouldKeepAlive()) { TRACE("finalize: closing"); connection.close(); } else { TRACE("finalize: resuming"); clear(); connection.resume(); } }
void ChangeRouterPasswordOp::onGetKeysFinished() { AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (isAborted()) { return; } int result = op->result(); if (result != NoError) { return notifyFinished(result); } QVariant varResponseCode = op->value("responseCode"); if (!varResponseCode.isValid()) { return notifyFinished(UnknownError); } bool ok; int responseCode = varResponseCode.toInt(&ok); if (!ok) { return notifyFinished(UnknownError); } if (responseCode != 0) { return notifyFinished(UnknownError); } QVariant varResponse = op->value("response"); if (!varResponse.isValid()) { return notifyFinished(UnknownError); } QVariantMap resp = qvariant_cast<QVariantMap>(varResponse); m_currentWifiKey = resp.value(QLatin1String("NewWPAPassphrase")).toString(); m_bean->m_soapCore->setWrappedMode(false); m_op = m_bean->m_soapCore->invoke(QLatin1String("LANConfigSecurity"), QLatin1String("GetInfo")); connect(m_op, SIGNAL(finished()), SLOT(onGetLanInfoFinished())); }
void ChangeRouterPasswordOp::onConfigOutFinished() { m_timer1.stop(); AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (op->isAborted()) { return; } if (isAborted()) { return; } int result = op->result(); if (result != NoError) { return notifyFinished(result); } QVariant varResponseCode = op->value("responseCode"); if (!varResponseCode.isValid()) { return notifyFinished(UnknownError); } bool ok; int responseCode = varResponseCode.toInt(&ok); if (!ok) { return notifyFinished(UnknownError); } // if (responseCode != 0) { // return notifyFinished(UnknownError); // } // notifyFinished(NoError); updateProfile(); }
void BaseOp::startImpl() { if (isAborted()) { DBGLOG(LOG_DEBUG, 6, QString::fromUtf8("aborted")); return report(WTFStatus_Aborted); } m_reply = routerApiPost(m_nam, m_url, m_namespace, m_command, m_paramNames, m_paramValues); if (!m_reply) { DBGLOG(LOG_ERROR, 2, QString::fromUtf8("routerApiPost failed!")); return report(WTFStatus_UnexpectedError); } getRidOfSslErrors(m_reply); connect(m_reply, SIGNAL(finished()), SLOT(stagePostFinished())); m_stage = Stage_Post; }
void ChangeRouterPasswordOp::onWifiConfigFinished() { AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (isAborted()) { return; } int result = op->result(); if (result != NoError) { return notifyFinished(result); } QVariant varResponseCode = op->value("responseCode"); if (!varResponseCode.isValid()) { return notifyFinished(UnknownError); } bool ok; int responseCode = varResponseCode.toInt(&ok); if (!ok) { return notifyFinished(UnknownError); } if (responseCode != 0) { return notifyFinished(UnknownError); } if (!m_adminPassword.isNull()) { startAdminConfig(); } else { startConfigOut(); } }
/** processes a (partial) request from buffer's given \p offset of \p count bytes. */ bool HttpConnection::process() { TRACE("process: offset=%ld, size=%ld (before processing)", inputOffset_, input_.size()); while (state() != MESSAGE_BEGIN || status() == ReadingRequest || status() == KeepAliveRead) { BufferRef chunk(input_.ref(inputOffset_)); if (chunk.empty()) break; // ensure status is up-to-date, in case we came from keep-alive-read if (status_ == KeepAliveRead) { TRACE("process: status=keep-alive-read, resetting to reading-request"); status_ = ReadingRequest; if (request_->isFinished()) { TRACE("process: finalizing request"); request_->finalize(); } } TRACE("process: (size: %ld, isHandlingRequest:%d, state:%s status:%s", chunk.size(), (flags_ & IsHandlingRequest) != 0, state_str(), status_str()); //TRACE("%s", input_.ref(input_.size() - rv).str().c_str()); HttpMessageProcessor::process(chunk, &inputOffset_); TRACE("process: done process()ing; fd=%d, request=%p state:%s status:%s", socket_->handle(), request_, state_str(), status_str()); if (isAborted()) return false; if (state() == SYNTAX_ERROR) { if (!request_->isFinished()) { setShouldKeepAlive(false); request_->status = HttpError::BadRequest; request_->finish(); } return false; } } TRACE("process: offset=%ld, bs=%ld, state=%s (after processing) io.timer:%d", inputOffset_, input_.size(), state_str(), socket_->timerActive()); return true; }
void IndexerJobEsprima::index() { JSParser parser; if (!parser.init()) { error() << "Can't init JSParser for" << mSourceInformation.sourceFile(); return; } if (isAborted()) return; String dump; if (!parser.parse(mSourceInformation.sourceFile(), &mData->symbols, &mData->symbolNames, mType == Dump ? 0 : &mData->dependencies, mType == Dump ? &dump : 0)) { error() << "Can't parse" << mSourceInformation.sourceFile(); } mParseTime = time(0); if (mType == Dump) { dump += "\n"; { Log stream(&dump); stream << "symbols:\n"; for (SymbolMap::const_iterator it = mData->symbols.begin(); it != mData->symbols.end(); ++it) { stream << it->first << it->second.toString(0) << '\n'; } stream << "symbolnames:\n"; for (SymbolNameMap::const_iterator it = mData->symbolNames.begin(); it != mData->symbolNames.end(); ++it) { stream << it->first << it->second << '\n'; } assert(id() != -1); } write(dump); mData->symbols.clear(); mData->symbolNames.clear(); } else { mData->message = String::format<128>("%s in %dms. (%d syms, %d symNames, %d refs)", mSourceInformation.sourceFile().toTilde().constData(), static_cast<int>(mTimer.elapsed()) / 1000, mData->symbols.size(), mData->symbolNames.size(), mData->references.size()); } }
Set<String> ListSymbolsJob::listSymbols(const shared_ptr<Project> &project) { Set<String> out; const bool hasFilter = Job::hasFilter(); const bool stripParentheses = queryFlags() & QueryMessage::StripParentheses; Scope<const SymbolNameMap&> symbolNames = project->lockSymbolNamesForRead(); const SymbolNameMap &map = symbolNames.data(); SymbolNameMap::const_iterator it = string.isEmpty() ? map.begin() : map.lower_bound(string); int count = 0; while (it != map.end()) { const String &entry = it->first; ++it; if (!string.isEmpty() && !entry.startsWith(string)) break; bool ok = true; if (hasFilter) { ok = false; const Set<Location> &locations = it->second; for (Set<Location>::const_iterator i = locations.begin(); i != locations.end(); ++i) { if (filter(i->path())) { ok = true; break; } } } if (ok) { const int paren = entry.indexOf('('); if (paren == -1) { out.insert(entry); } else { out.insert(entry.left(paren)); if (!stripParentheses) out.insert(entry); } } if (!(++count % 100) && isAborted()) break; } return out; }
void ChangeRouterWifiPasswordOp::onConfigStarted() { AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (isAborted()) { return; } int result = op->result(); LOG_DEBUG(QString::fromUtf8("onConfigStarted %1").arg(result)); if (result != NoError) { return notifyFinished(result); } QVariant varResponseCode = op->value("responseCode"); if (!varResponseCode.isValid()) { return notifyFinished(UnknownError); } bool ok; int responseCode = varResponseCode.toInt(&ok); if (!ok) { return notifyFinished(UnknownError); } if (responseCode != 0) { return notifyFinished(UnknownError); } m_op = m_bean->m_soapCore->invoke(NS_WLANConfiguration, QLatin1String("GetInfo")); connect(m_op, SIGNAL(finished()), SLOT(onGetInfoFinished())); }
void RestartRouterOp::onConfigStarted() { AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (isAborted()) { return; } int result = op->result(); LOG_DEBUG(QString::fromUtf8("onConfigStarted %1").arg(result)); if (result != NoError) { return notifyFinished(result); } QVariant varResponseCode = op->value("responseCode"); if (!varResponseCode.isValid()) { return notifyFinished(UnknownError); } bool ok; int responseCode = varResponseCode.toInt(&ok); if (!ok) { return notifyFinished(UnknownError); } if (responseCode != 0) { return notifyFinished(UnknownError); } m_op = m_bean->m_soapCore->invoke(QLatin1String("DeviceConfig"), QLatin1String("ConfigurationFinished"), QLatin1String("NewStatus"), QLatin1String("RebootRequired")); connect(m_op, SIGNAL(finished()), SLOT(onConfigFinished())); }
void Solver::run() { quint32 step = 0; QQueue<Matrix *> queue; queue.enqueue(_tree); Matrix * matrix = NULL; Matrix * child = NULL; qint8 n = _tree->getDimension() - _tree->getRotationSize() + static_cast<qint8>(1); while(!queue.isEmpty() && !isAborted()) { matrix = queue.dequeue(); if(!_explored.contains(matrix->getHash())) { ++step; emit progress(step); _explored.insert(matrix->getHash(), matrix); _maxLevel = qMax(_maxLevel, matrix->getLevel()); for(qint8 i=0; i<n; ++i) { for(qint8 j=0; j<n; ++j) { Cell topLeftCell = j + i * matrix->getDimension(); Rotation rotation(topLeftCell, CW); child = new Matrix(matrix, rotation); matrix->addChild(rotation, child); queue.enqueue(child); rotation = Rotation(topLeftCell, CCW); child = new Matrix(matrix, rotation); matrix->addChild(rotation, child); queue.enqueue(child); } } } } }
void RestartRouterOp::onConfigFinished() { AsyncOp *op = m_op; m_op->deleteLater(); m_op = NULL; if (isAborted()) { return; } int result = op->result(); LOG_DEBUG(QString::fromUtf8("onConfigFinished %1").arg(result)); if (result != NoError) { return notifyFinished(result); } QVariant varResponseCode = op->value("responseCode"); if (!varResponseCode.isValid()) { return notifyFinished(UnknownError); } bool ok; int responseCode = varResponseCode.toInt(&ok); if (!ok) { return notifyFinished(UnknownError); } if (responseCode != 0) { return notifyFinished(UnknownError); } notifyFinished(NoError); }
CXChildVisitResult DumpThread::visit(const CXCursor &cursor) { if (isAborted()) return CXChildVisit_Break; const Location location = createLocation(cursor); if (!location.isNull()) { if (mQueryFlags & QueryMessage::DumpCheckIncludes) { checkIncludes(location, cursor); return CXChildVisit_Recurse; } else { Flags<Location::ToStringFlag> locationFlags; if (mQueryFlags & QueryMessage::NoColor) locationFlags |= Location::NoColor; CXSourceRange range = clang_getCursorExtent(cursor); CXSourceLocation rangeEnd = clang_getRangeEnd(range); unsigned int endLine, endColumn; clang_getPresumedLocation(rangeEnd, 0, &endLine, &endColumn); if (!(mQueryFlags & QueryMessage::DumpIncludeHeaders) && location.fileId() != mSource.fileId) { return CXChildVisit_Continue; } String message; message.reserve(256); if (!(mQueryFlags & QueryMessage::NoContext)) { message = location.context(locationFlags); } if (endLine == location.line()) { message += String::format<32>(" // %d-%d, %d: ", location.column(), endColumn, mIndentLevel); } else { message += String::format<32>(" // %d-%d:%d, %d: ", location.column(), endLine, endColumn, mIndentLevel); } message += RTags::cursorToString(cursor, RTags::AllCursorToStringFlags); message.append(" " + RTags::typeName(cursor));; if (clang_getCursorKind(cursor) == CXCursor_VarDecl) { const std::shared_ptr<RTags::Auto> autoResolved = RTags::resolveAuto(cursor); if (autoResolved && !clang_equalCursors(autoResolved->cursor, nullCursor)) { message += "auto resolves to " + RTags::cursorToString(autoResolved->cursor, RTags::AllCursorToStringFlags); } } CXCursor ref = clang_getCursorReferenced(cursor); if (clang_equalCursors(ref, cursor)) { message.append("refs self"); } else if (!clang_equalCursors(ref, nullCursor)) { message.append("refs "); message.append(RTags::cursorToString(ref, RTags::AllCursorToStringFlags)); } CXCursor canonical = clang_getCanonicalCursor(cursor); if (!clang_equalCursors(canonical, cursor) && !clang_equalCursors(canonical, nullCursor)) { message.append("canonical "); message.append(RTags::cursorToString(canonical, RTags::AllCursorToStringFlags)); } CXCursor specialized = clang_getSpecializedCursorTemplate(cursor); if (!clang_equalCursors(specialized, cursor) && !clang_equalCursors(specialized, nullCursor)) { message.append("specialized "); message.append(RTags::cursorToString(specialized, RTags::AllCursorToStringFlags)); } writeToConnetion(message); } } ++mIndentLevel; clang_visitChildren(cursor, DumpThread::visitor, this); if (isAborted()) return CXChildVisit_Break; --mIndentLevel; return CXChildVisit_Continue; }
bool Deconvolution::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Deconvolution Sharpening", "app", "619F3C8A-FB70-44E0-B211-B116E604EDDA"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); RasterElement* pCube = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); if (pCube == NULL) { std::string msg = "A raster cube must be specified."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pCube->getDataDescriptor()); VERIFY(pDesc != NULL); EncodingType ResultType = pDesc->getDataType(); if (pDesc->getDataType() == INT4SCOMPLEX) { ResultType = INT4SBYTES; } else if (pDesc->getDataType() == FLT8COMPLEX) { ResultType = FLT8BYTES; } FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BSQ); DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release()); ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() + "_Deconvolution_Sharpening_Result", pDesc->getRowCount(), pDesc->getColumnCount(), ResultType)); if (pResultCube.get() == NULL) { std::string msg = "A raster cube could not be created."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } FactoryResource<DataRequest> pResultRequest; pResultRequest->setWritable(true); DataAccessor pDestAcc = pResultCube->getDataAccessor(pResultRequest.release()); Service<DesktopServices> pDesktop; DeconvolutionDlg dlg(pDesktop->getMainWidget()); int stat = dlg.exec(); if (stat != QDialog::Accepted) { return true; } double minGrayValue; double maxGrayValue; double deltaValue = 0.0; int nFilterType = dlg.getCurrentFilterType(); int windowSize = dlg.getCurrentWindowSize(); double sigmaVal = dlg.getSigmaValue(); double gamaVal = dlg.getGamaValue(); windowSize = (windowSize-1)/2; if (NULL != pOriginalImage) { free(pOriginalImage); } pOriginalImage = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *OrigData = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *NewData = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *ConvoData = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *pTempData; InitializeData(pSrcAcc, pOriginalImage, OrigData, pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType()); GetGrayScale(&minGrayValue, &maxGrayValue, pDesc->getDataType()); //Perform deconvolution iteratively for (int num = 0; num < MAX_ITERATION_NUMBER; num++) { if (pProgress != NULL) { pProgress->updateProgress("Deconvolution process", num*100/MAX_ITERATION_NUMBER, NORMAL); } if (isAborted()) { std::string msg = getName() + " has been aborted."; pStep->finalize(Message::Abort, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ABORT); } free(OrigData); free(NewData); free(ConvoData); return false; } deltaValue = DeconvolutionFunc(OrigData, pOriginalImage, NewData, ConvoData, sigmaVal, gamaVal, windowSize, pDesc->getRowCount(), pDesc->getColumnCount(), nFilterType, maxGrayValue, minGrayValue); pTempData = OrigData; OrigData = NewData; NewData = pTempData; double errorRate = deltaValue/(maxGrayValue-minGrayValue); if (errorRate < CONVERGENCE_THRESHOLD) { break; } } free(NewData); free(ConvoData); //Output result unsigned int nCount = 0; for (int i = 0; i < pDesc->getRowCount(); i++) { for (int j = 0; j < pDesc->getColumnCount(); j++) { if (!pDestAcc.isValid()) { std::string msg = "Unable to access the cube data."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } free(OrigData); return false; } pDestAcc->toPixel(i, j); switchOnEncoding(ResultType, restoreImageValue, pDestAcc->getColumn(), (OrigData+nCount)); nCount++; } } free(OrigData); if (!isBatch()) { Service<DesktopServices> pDesktop; SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(pDesktop->createWindow(pResultCube->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { std::string msg = "Unable to create view."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pView->setPrimaryRasterElement(pResultCube.get()); pView->createLayer(RASTER, pResultCube.get()); } if (pProgress != NULL) { pProgress->updateProgress("Deconvolution enhancement is complete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("Deconvolution enhancement Result", pResultCube.release()); pStep->finalize(); return true; }