Exemplo n.º 1
0
VaApiFilterInfo::VaApiFilterInfo(VAContextID context, VAProcFilterType type) {
	m_type = type;
	uint size = 0;
	auto dpy = VaApi::glx();
	switch (type) {
	case VAProcFilterNoiseReduction:
	case VAProcFilterSharpening: {
		VAProcFilterCap cap; size = 1;
		if (!isSuccess(vaQueryVideoProcFilterCaps(dpy, context, type, &cap, &size)) || size != 1)
			return;
		m_caps.resize(1); m_caps[0].algorithm = type; m_caps[0].range = cap.range;
		break;
	} case VAProcFilterDeinterlacing: {
		size = VAProcDeinterlacingCount;
		VAProcFilterCapDeinterlacing caps[VAProcDeinterlacingCount];
		if (!isSuccess(vaQueryVideoProcFilterCaps(dpy, context, VAProcFilterDeinterlacing, caps, &size)))
			return;
		m_caps.resize(size);
		for (uint i=0; i<size; ++i)
			m_caps[i].algorithm = caps[i].type;
		break;
	} case VAProcFilterColorBalance: {
		size = VAProcColorBalanceCount;
		VAProcFilterCapColorBalance caps[VAProcColorBalanceCount];
		if (!isSuccess(vaQueryVideoProcFilterCaps(dpy, context, VAProcFilterColorBalance, caps, &size)))
			return;
		m_caps.resize(size);
		for (uint i=0; i<size; ++i) {
			m_caps[i].algorithm = caps[i].type;
			m_caps[i].range = caps[i].range;
		}
		break;
	} default:
		return;
	}
	m_algorithms.resize(m_caps.size());
	for (int i=0; i<m_caps.size(); ++i)
		m_algorithms[i] = m_caps[i].algorithm;
}
Exemplo n.º 2
0
VaApiPostProcessor::VaApiPostProcessor() : d(new Data) {
	VAConfigID config;
	d->dpy = VaApi::glx();
	if (!isSuccess(vaCreateConfig(d->dpy, VAProfileNone, VAEntrypointVideoProc, nullptr, 0, &config)))
		return;
	d->config = config;
	VAContextID context;
	if (!isSuccess(vaCreateContext(d->dpy, d->config, 0, 0, 0, NULL, 0, &context)))
		return;
	d->context = context;
	const auto filters = VaApi::filters();
	for (int i=0; i<filters.size(); ++i) {
		switch (filters[i].type()) {
		case VAProcFilterDeinterlacing:
			_New(d->deinterlacer, i, d->context);
			break;
		default:
			continue;
		}
	}
	if (!filters.isEmpty())
		_New(d->pipeline, d->context);
}
Exemplo n.º 3
0
void WindowsPlatformStyle::checkForModernStyle()
{
	if (QSysInfo::windowsVersion() >= QSysInfo::WV_10_0)
	{
		HIGHCONTRAST information = {0};
		information.cbSize = sizeof(HIGHCONTRAST);

		BOOL isSuccess(SystemParametersInfoW(SPI_GETHIGHCONTRAST, 0, &information, 0));

		m_isModernStyle = !(isSuccess && information.dwFlags & HCF_HIGHCONTRASTON);
	}
	else
	{
		m_isModernStyle = false;
	}
}
Exemplo n.º 4
0
void ofApp::setup()
{
    // Testing redirects and https.
    std::string url = "https://httpbin.org/get";

    // Testing redirects and https.
    ofxHTTP::Client client;

    auto response = client.get(url);

    if (response->isSuccess())
    {
        std::cout << response->getBuffer() << std::endl;
    }
    else
    {
        std::cout << response->error() << std::endl;
    }
}
Exemplo n.º 5
0
QString BatchJob::Info()
{
    return QString("Job name: %1\n"
                   "Job id: %2\n"
                   "Program: %3\n"
                   "Arguments: \"%4\"\n"
                   "Log file: %5\n"
                   "Job directory: %6\n"
                   "Running: %7\n"
                   "Success: %8\n")
           .arg(jobName_.toAscii().constData())
           .arg(jobId_)
           .arg(program_.toAscii().constData())
           .arg(arguments_.join("\" \"").toAscii().constData())
           .arg(logFile.toAscii().constData())
           .arg(workingDirectory_.toAscii().constData())
           .arg(isRunning() ? "true" : "false")
           .arg(isSuccess() ? "true" : "false");
}
int main()
{
        int num1, num2, num3;
        int m, success;
        for (m=61; m<=165; m++)
        {   
            num1 = 2 * m;
            num2 = 3 * m;
            num3 = 6 * m;
          
            for(int j=0; j<10; j++)
            {
                a[j] = 0;
            }
            
            Test(num1);
            Test(num2);
            Test(num3);
            
            success = isSuccess(a);
            
            if (success == 1)
            {   
                printf("该数据是%d\n", num3);
                break;
            }              
        } 
   // for (int j=0; j<10; j++)
     //       printf("%d ", a[j]);
     if (success == 0)
     {
         printf("找不到啊!\n");
     }
     getch();
     return 0;
}  
Exemplo n.º 7
0
 operator bool() const {
     return isSuccess();
 }
Exemplo n.º 8
0
 // ------------------------------------------------------------------------
 void ServersManager::RefreshRequest::callback()
 {
     ServersManager::get()->refresh(isSuccess(), getXMLData());
 }   // callback
Exemplo n.º 9
0
KLUPD::FileInfo::ChangeStatus KLUPD::UpdateInfo::getFileStatusAgainstLocal(const FileInfo &etalon,
    const ChangeStateCheck &changeStateCheck, const FileVector &localFilesToCheckAgainst, NoCaseString &statusExplanations)const
{
    if(changeStateCheck == noStateChangeCheck)
        return FileInfo::unchanged;

    statusExplanations.erase();

    LocalFile fileInProductFolder(m_callbacks.productFolder(etalon, m_retranslationMode) + etalon.m_filename);

    //////////////////////////////////////////////////////////////////////////
    // check if file in product folder exists
    if(!fileInProductFolder.exists())
    {
        statusExplanations = L"original files does not exist";
        return FileInfo::added;
    }

    // inlined file is already downloaded together with index file, can be only compared if it changed
    if(etalon.isInlined())
    {
        std::vector<unsigned char> buffer;
        const CoreError readInlinedFileResult = fileInProductFolder.read(buffer);
        if(!isSuccess(readInlinedFileResult))
        {
            TRACE_MESSAGE3("Failed to detect change state for inlined file '%S', file operation error '%S'",
                fileInProductFolder.m_name.toWideChar(), toString(readInlinedFileResult).toWideChar());
            statusExplanations = L"inlined file can not be read";
            return FileInfo::added;
        }

        if(buffer == etalon.m_inlinedContent)
        {
            statusExplanations = L"inlined file is not changed";
            return FileInfo::unchanged;
        }
        else
        {
            statusExplanations = L"inlined file is not modified";
            return FileInfo::modified;
        }
    }


    //////////////////////////////////////////////////////////////////////////
    // check against signature 5
    if(!etalon.m_signature5.empty())
    {
        if(checkInsideSignature5AgainstEtalon(fileInProductFolder.m_name, etalon.m_signature5, pLog))
        {
            statusExplanations = L"signature 5 is not changed";
            return FileInfo::unchanged;
        }
        else
        {
            statusExplanations = L"signature 5 is changed";
            return FileInfo::modified;
        }
    }

    //////////////////////////////////////////////////////////////////////////
    // check file against md5
    if(!etalon.m_md5.empty())
    {
        std::vector<unsigned char> md5;
        if(!calcMD5Hash(fileInProductFolder.m_name, md5))
        {
            statusExplanations = L"failed to calculate md5 hash";
            return FileInfo::added;
        }

        if(md5 == etalon.m_md5)
        {
            statusExplanations = L"md5 unchanged";
            return FileInfo::unchanged;
        }
        else
        {
            statusExplanations = L"md5 changed";
            return FileInfo::modified;
        }
    }

    //////////////////////////////////////////////////////////////////////////
    // check date

    statusExplanations += NoCaseString(L"date from index '") + etalon.m_dateFromIndex + L"', "
        + (localFilesToCheckAgainst.empty() ? L"local bases are not consistent" : L"local bases are consistent");

    if(!etalon.m_dateFromIndex.empty()
        // date check is only performed if file presents in consistent local file set,
        // otherwise file may belong to other Update set and must be updated
        && !localFilesToCheckAgainst.empty())
    {
        FileInfo::ChangeStatus modifiedIfDatesAreIgnored = FileInfo::unchanged;

        // check if index date is newer is only performed for Kaspersky sources
        if(changeStateCheck == checkStateButIgnoreDate)
        {
            modifiedIfDatesAreIgnored = FileInfo::modified;
            statusExplanations = L", dates are ignored for user-specified sources";
        }

        FileInfo localConsistentFile;
        if(localFilesToCheckAgainst.findTheSameFile(etalon, localConsistentFile, m_retranslationMode))
        {
            bool bIndex = etalon.isIndex();
            const NoCaseString& strLocalFileDate = bIndex ? localConsistentFile.m_strUpdateDate : localConsistentFile.m_dateFromIndex;
            NoCaseString strFileType(bIndex ? L"index" : L"non-index"); // for trace

            if(!strLocalFileDate.empty())
            {
                // if expected date on source is less, then file is skipped
                unsigned long nEtalonDate = updateDateStringToSequenceNumber(etalon.m_dateFromIndex);
                unsigned long nLocalFileDate = updateDateStringToSequenceNumber(strLocalFileDate);
                if(nEtalonDate < nLocalFileDate)
                {
                    statusExplanations += NoCaseString(L", ") + FileInfo::toString(modifiedIfDatesAreIgnored).toWideChar() +
                        L" " + strFileType + L" file is found in local consistent set with date '" + localConsistentFile.m_dateFromIndex + L"'";
                    return modifiedIfDatesAreIgnored;
                }
                else if( bIndex || nEtalonDate > nLocalFileDate)
                {
                    statusExplanations += NoCaseString(L", modified ") + strFileType + L" file is found in local consistent set, date from file '" + strLocalFileDate + L"'";
                    return FileInfo::modified;
                }
                else
                    statusExplanations +=  NoCaseString(L", ") + strFileType + L" file is found in local consistent set with same date";
            }
            else
                statusExplanations += NoCaseString(L", ") + strFileType + L" file is found in local consistent set, but there is no date in index specified";
        }
        else
            statusExplanations += L", file is not found in local consistent set";
    }

    //////////////////////////////////////////////////////////////////////////
    // check against signature 6

    bool insideSignature = false;
    NoCaseString errorMessage;
    if(!m_signature6Checker.checkSignature(fileInProductFolder.m_name, insideSignature, errorMessage))
    {
        statusExplanations += NoCaseString(L", signature 6 check changed (") + errorMessage + L")";
        return FileInfo::modified;
    }

    // file may contain inside signature6, then there is no way to determine whether
     //  file is different on source, and that is why must always be downloaded
    if(insideSignature)
    {
        statusExplanations += L", inside signature 6 check unchanged (file needs being downloaded)";
        return FileInfo::modified;
    }
    else
    {
        statusExplanations += L", signature 6 check unchanged";
        return FileInfo::unchanged;
    }
}
Exemplo n.º 10
0
KLUPD::CoreError KLUPD::HttpProtocol::receiveResponseAndData(HttpHeader &httpHeader)
{
    bool httpHeaderFullyReceived = false;

    const char *entity = 0;
    size_t total_entity_bytes = 0;

    const size_t httpBufferSize = 65536;
    char httpBuffer[httpBufferSize + 1];
    memset(httpBuffer, 0, httpBufferSize + 1);
    size_t currentOffsetInHttpBuffer = 0;

    while(true)
    {
        CoreError receiveResult = CORE_NO_ERROR;
        const int bytesReceived = m_socket.recv(httpBuffer + currentOffsetInHttpBuffer,
            httpBufferSize - currentOffsetInHttpBuffer, receiveResult);
        currentOffsetInHttpBuffer += bytesReceived;

        // according to RFC 2616, 4.4 point 5: connection close may indicate
         // file transfer completion if Range or Content-Length is not specified
        if(httpHeaderFullyReceived
            && (receiveResult == CORE_REMOTE_HOST_CLOSED_CONNECTION)
            && (httpHeader.m_contentLength == -1))
        {
            TRACE_MESSAGE2("HTTP connection closed by server, no Content-Length field, consider file is obtained, size %d bytes", currentOffsetInHttpBuffer);
            return CORE_NO_ERROR;
        }
        if(receiveResult != CORE_NO_ERROR)
            return receiveResult;

        // size of entity part that is currently in buffer
        size_t entityBytes = 0;
        if(httpHeaderFullyReceived)
        {
            // http header was obtained on previous iteration
            entityBytes = currentOffsetInHttpBuffer;
            entity = httpBuffer;
        }
        else
        {
            // HTTP header has not been obtained yet, check if it is in httpBuffer
            const char *const headerEndMarker = "\r\n\r\n";
            char *const headerLastPosition = strstr(httpBuffer, headerEndMarker);

            if(!headerLastPosition)
            {
                // no end-of-header marker found
                if(httpBufferSize < currentOffsetInHttpBuffer)
                {
                    TRACE_MESSAGE3("Error: response HTTP header can not fit into %d-bytes buffer (already received %d bytes)",
                        httpBufferSize, currentOffsetInHttpBuffer);
                    return CORE_DOWNLOAD_ERROR;
                }

                // continue reading from socket
                continue;
            }

            httpHeaderFullyReceived = true;

            // pass to applicaiton data included into HTTP header
            fullHttpHeaderReceived(std::string(httpBuffer, headerLastPosition + strlen(headerEndMarker)));

            *headerLastPosition = 0;
            TRACE_MESSAGE2("HTTP response received:\n%s", HTTPRequestBuilder::toString(httpBuffer).c_str());

            // Parse HTTP header, data loaded into httpHeader structure
            if(!httpHeader.load(httpBuffer, m_authorizationDriver))
            {
                TRACE_MESSAGE("Failed to parse HTTP response header");
                return CORE_DOWNLOAD_ERROR;
            }

            // it is expected 206 code in case regetting is used
            if(m_regettingPosition && (httpHeader.httpCode() == 200))
            {
                TRACE_MESSAGE("It is expected 206 code in case regetting is used, but 200 code is received");
                return CORE_DOWNLOAD_ERROR;
            }

            // data from socket after the HTTP header
            entityBytes = (httpBuffer + currentOffsetInHttpBuffer)  // pointer to the end of received bytes
                - (headerLastPosition + strlen(headerEndMarker));   // pointer to the data (begin of the file)
            entity = entityBytes ? headerLastPosition + strlen(headerEndMarker) : 0;
        }

        total_entity_bytes += entityBytes;

        if(httpHeader.isFile()
            // only header has been received, but data is not received yet
            && entityBytes)
        {
            const CoreError saveDataToFileResult = dataReceived(reinterpret_cast<const unsigned char *>(entity), entityBytes);
            if(!isSuccess(saveDataToFileResult))
            {
                TRACE_MESSAGE2("Failed to write data obtained from HTTP Server, result %S",
                    toString(saveDataToFileResult).toWideChar());
                return saveDataToFileResult;
            }
            m_regettingPosition += entityBytes;
        }

        //////////////////////////////////////////////////////////////////////////
        /// check if complete file is downloaded

        // Content-Length header presents
        if(httpHeader.m_contentLength == -1)
        {
            TRACE_MESSAGE("HTTP chunk received (header does not contain the content-length field), continue receiving message until connection is closed by remote peer");
        }
        else if(static_cast<size_t>(httpHeader.m_contentLength) <= total_entity_bytes)
        {
            TRACE_MESSAGE2("HTTP message successfully received, content length = %d", httpHeader.m_contentLength);
            return CORE_NO_ERROR;
        }

        currentOffsetInHttpBuffer = 0;
        entityBytes = 0;
    }
}
Exemplo n.º 11
0
KLUPD::CoreError KLUPD::AdministrationKitProtocol::getFile(
    const Path &fileName, const Path &localPath, const Path &relativeUrlPathIn,
    const bool useMasterAdministrationServer)
{
#ifdef DISABLE_AK_FILETRANSFER
    TRACE_MESSAGE("Administration Kit Transport is not implemented");
    return CORE_DOWNLOAD_ERROR;
#else
    // skip initial slash in relative URL path
    Path relativeUrlPath = relativeUrlPathIn;
    if(!relativeUrlPath.empty()
        && (relativeUrlPath[0] == L'\\' || relativeUrlPath[0] == L'/'))
    {
        relativeUrlPath = relativeUrlPath.toWideChar() + 1;   
    }

    const Path path = relativeUrlPath + fileName;

    ///////////////////////////////////////////////
    /// checking current state and parameters
    const CoreError connectionResult = setupLowLevelConnectionIfNeed(useMasterAdministrationServer);
    if(connectionResult != CORE_NO_ERROR)
    {
        TRACE_MESSAGE2("Failed to setup connection to Administration Server, result '%S'",
            toString(connectionResult).toWideChar());
        return connectionResult;
    }


    ///////////////////////////////////////////////
    /// receiving data by portions
    size_t regettingPosition = LocalFile(localPath + fileName).size();
    AutoStream destinationFile(pLog);
    while(true)
    {
        // check if request should be cancelled
        if(m_downloadProgress.checkCancel())
        {
            TRACE_MESSAGE2("File transfer cancelled '%S'", path.toWideChar());
            return CORE_CANCELLED;
        }

        const long localBufferSize = 65536;
        std::vector<unsigned char> localBuffer(localBufferSize, 0);

        int bytesRead = 0;
        m_downloadProgress.updateSpeedStartTimer();
        const KLFT::FileOpeartionResult getChunkResult = m_adminKitTransprot->GetFileChunk(
            path.toWideChar(),
            regettingPosition,
            &localBuffer[0], localBuffer.size(),
            bytesRead);
        m_downloadProgress.updateSpeedStopTimer();


        // a portion of file got successfully
        if(getChunkResult == KLFT::FR_Ok || getChunkResult == KLFT::FR_OkDownloaded)
        {
            const CoreError saveDataToFileResult = saveDataToFile(
                localPath + fileName,
                &localBuffer[0],
                bytesRead, regettingPosition != 0, destinationFile, pLog);
            if(!isSuccess(saveDataToFileResult))
            {
                TRACE_MESSAGE3("Failed to write data obtained from Administration Server to file '%S', result '%S'",
                    path.toWideChar(), toString(saveDataToFileResult).toWideChar());
                return saveDataToFileResult;
            }

            regettingPosition += bytesRead;
            m_downloadProgress.bytesTransferred(bytesRead);

            // file has been completely downloaded
            if(getChunkResult == KLFT::FR_OkDownloaded)
                return CORE_NO_ERROR;

            continue;
        }

        TRACE_MESSAGE5("Failed to obtain file chunk from Administration Server, file '%S', result '%s', bytes read %d, current position %d",
            path.toWideChar(), toString(getChunkResult).c_str(), bytesRead, regettingPosition);

        if(getChunkResult == KLFT::FR_Timeout)
        {
            // TODO check if time out is over and error should be returned
            continue;
        }

        // error while download happened
        switch(getChunkResult)
        {
        // invalid AdminKit Transport identifier: either receiver was deleted or connect was already called for this receiver
        case KLFT::FR_WrongReceiverId:
            return CORE_AK_WrongReceiverId;

        // invalid arguments for AdminKit Transport
           // wrong offset is requested, consider file is downloaded and signature should be checked
        case KLFT::FR_WrongArguments:
            {            // TODO: this is *work around* about the problem that AdminKit returns
                return CORE_NO_ERROR;    //  FR_WrongArguments code in case source contains
                                        //  valid file in target download folder
                                      // this code can be deleted when problem is fixed in AdminKit
            }

        // file not found on AdminKit server
        case KLFT::FR_FileNotFound:
            return CORE_NO_SOURCE_FILE;

        // AdminKit transport file receive error
        case KLFT::FR_ErrorInOperation:
            return CORE_AK_ErrorInOperation;

        // unknown AdminKit transport receive operation error
        default:
            return CORE_AK_UnknownError;
        }
    }
#endif  // DISABLE_AK_FILETRANSFER
}