void GraphEstimator::solve() { used_.clear(); mult_.clear(); mult_.push_back(std::set<ProbMultiplier>()); ProbMultiplier m(last_hash_); m.scalar_ = 1.0; mult_[0].insert(m); findPath(src_); double p = extractProb(); std::cout << "Result probability = " << p << std::endl; emit notifyResult(p); }
void WavegenClient::connectAsync(std::string const& serverAddr, AsyncOperationCb &&cb) { { std::lock_guard<std::mutex> lock(mapOperationCallbacksMutex_); if (cb) mapOperationCallbacks_[OperationType::Connect].emplace_back(std::move(cb)); } if (pa_context_connect(paContext_, serverAddr.empty() ? nullptr : serverAddr.c_str(), PA_CONTEXT_NOFLAGS, nullptr) < 0) { // connection failed reportContextError(paContext_, serverAddr); notifyResult(OperationType::Connect, OperationResult::Failed, true); } }
void TrimTask::run() { acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakeLock); for (const auto& path : mPaths) { LOG(DEBUG) << "Starting trim of " << path; int fd = open(path.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW); if (fd < 0) { PLOG(WARNING) << "Failed to open " << path; continue; } struct fstrim_range range; memset(&range, 0, sizeof(range)); range.len = ULLONG_MAX; nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME); if (ioctl(fd, (mFlags & Flags::kDeepTrim) ? FIDTRIM : FITRIM, &range)) { PLOG(WARNING) << "Trim failed on " << path; notifyResult(path, -1, -1); } else { nsecs_t delta = systemTime(SYSTEM_TIME_BOOTTIME) - start; LOG(INFO) << "Trimmed " << range.len << " bytes on " << path << " in " << nanoseconds_to_milliseconds(delta) << "ms"; notifyResult(path, range.len, delta); } close(fd); if (mFlags & Flags::kBenchmarkAfter) { #if BENCHMARK_ENABLED BenchmarkPrivate(path); #else LOG(DEBUG) << "Benchmark disabled"; #endif } } release_wake_lock(kWakeLock); }
void WavegenClient::onContextStateChanged() { switch (pa_context_get_state(paContext_)) { case PA_CONTEXT_FAILED: reportContextError(paContext_, pa_context_get_server(paContext_)); notifyResult(OperationType::Connect, OperationResult::Failed, true); break; case PA_CONTEXT_TERMINATED: notifyResult(OperationType::Connect, OperationResult::Failed, true); break; case PA_CONTEXT_READY: // connection OK if (firstConnection_) { onConnectionEstablishedFirstTime(); firstConnection_ = false; } notifyResult(OperationType::Connect, OperationResult::Success, true); break; default: // connecting in progress... notifyResult(OperationType::Connect, OperationResult::InProgress, false); break; } }
VpnControlDaemonClient::Result VpnControlDaemonClient::readResponse() { Result result; result.type = VpnClientConnection::UNKNOWN; if (m_pSocket->canReadLine()) { QString strResponseLine; while ((strResponseLine = m_pStream->readLine()).length() > 0) { const QStringList strResponseParts(strResponseLine.split(' ', QString::SkipEmptyParts)); const int iParts(strResponseParts.count()); if (iParts > 1) { bool fIsResponseType; const unsigned int iResponseType = strResponseParts[0].toUInt(&fIsResponseType); Q_ASSERT(fIsResponseType); if (fIsResponseType) { switch (iResponseType) { case VpnClientConnection::RESULT: { bool fIsReturnCode; const int iReturnCode(strResponseParts[1].toUInt(&fIsReturnCode)); Q_ASSERT(fIsReturnCode); Q_ASSERT(iParts > 2); if (fIsReturnCode) { const QString strCommand(strResponseLine.mid(strResponseLine.indexOf(strResponseParts[2]))); emit notifyResult(iReturnCode, strCommand); result.iReturnCode = iReturnCode; result.type = VpnClientConnection::RESULT; } } break; case VpnClientConnection::OUTPUT: emit notifyCommandOutput(strResponseLine.mid(strResponseLine.indexOf(' ') + 1)); result.iReturnCode = 0; result.type = VpnClientConnection::OUTPUT; break; case VpnClientConnection::INFORMATION: { bool fIsInformation; const int iInformation(strResponseParts[1].toUInt(&fIsInformation)); Q_ASSERT(fIsInformation); if (fIsInformation && iInformation == VpnClientConnection::CLOSED) m_pSocket->disconnectFromServer(); result.iReturnCode = VpnClientConnection::CLOSED; result.type = VpnClientConnection::INFORMATION; } break; default: // either server changed protocol and we missed this or a malicious software sends us messages Q_ASSERT(false); } } } } } return(result); }