Beispiel #1
0
bool FCDInput::startInput(int device)
{
	QMutexLocker mutexLocker(&m_mutex);

	if(m_FCDThread)
		return false;
	/* Apply settings before streaming to avoid bus contention;
	 * there is very little spare bandwidth on a full speed USB device.
	 * Failure is harmless if no device is found */
	applySettings(m_generalSettings, m_settings, true);

	if(!m_sampleFifo.setSize(4096*16)) {
		qCritical("Could not allocate SampleFifo");
		return false;
	}

	if((m_FCDThread = new FCDThread(&m_sampleFifo)) == NULL) {
		qFatal("out of memory");
		return false;
	}

	m_deviceDescription = QString("Funcube Dongle");

	qDebug("FCDInput: start");
	return true;
}
bool QTSServerInterface::RedisGenSession(string& strSessioionID,UInt32 iTimeoutMil)//生成唯一的sessionID并存储在redis上
{
	//算法秒速,生成随机sessionID,看redis上是否有存储,没有就存在redis上,有的话就再生成,直到没有为止
	OSMutexLocker mutexLocker(&fRedisMutex);
	
	if(!ConRedis())
		return false;

	redisReply* reply=NULL;
	char chTemp[128]={0};
	
	do 
	{
		if(reply)//释放上一个回应
			freeReplyObject(reply);

		strSessioionID=OSMapEx::GenerateSessionIdForRedis(fCMSIP.c_str(),fCMSPort);//生成
		sprintf(chTemp,"exists SessionID_%s",strSessioionID.c_str());
		reply = (redisReply*)redisCommand(fRedisCon,chTemp);
		if (NULL == reply)//错误,需要进行重连
		{
			redisFree(fRedisCon);
			fIfConSucess=false;
			return false;
		}
	}
	while(reply->type==REDIS_REPLY_INTEGER&&reply->integer==1);
	freeReplyObject(reply);//释放最后一个的回应
	
	//走到这说明找到了一个唯一的SessionID,现在将它存储到redis上
	sprintf(chTemp,"setex SessionID_%s %d 1",strSessioionID.c_str(),iTimeoutMil/1000);//高级版本支持setpx来设置超时时间为ms
	return RedisCommand(chTemp);
}
Model::Page* Model::DjVuDocument::page(int index) const
{
    QMutexLocker mutexLocker(&m_mutex);

    ddjvu_status_t status;
    ddjvu_pageinfo_t pageinfo;

    while(true)
    {
        status = ddjvu_document_get_pageinfo(m_document, index, &pageinfo);

        if(status < DDJVU_JOB_OK)
        {
            clearMessageQueue(m_context, true);
        }
        else
        {
            break;
        }
    }

    if(status >= DDJVU_JOB_FAILED)
    {
        return 0;
    }

    return new DjVuPage(this, index, pageinfo);
}
void FileAttachmentAnnotationWidget::save(bool open)
{
#ifndef HAS_POPPLER_24

    QMutexLocker mutexLocker(m_mutex);

#endif // HAS_POPPLER_24

    Poppler::EmbeddedFile* embeddedFile = m_annotation->embeddedFile();

    QString filePath = QFileDialog::getSaveFileName(0, tr("Save file attachment"), embeddedFile->name());

    if(!filePath.isEmpty())
    {
        QFile file(filePath);

        if(file.open(QIODevice::WriteOnly | QIODevice::Truncate))
        {
            file.write(embeddedFile->data());

            file.close();

            if(open)
            {
                QDesktopServices::openUrl(QUrl(filePath));
            }
        }
        else
        {
            QMessageBox::warning(0, tr("Warning"), tr("Could not save file attachment to '%1'.").arg(filePath));
        }
    }
}
/*!
    Fetch the credential data from the credential cache.

    If auth is 0 (as it is when called from createRequest()), this will try to
    look up with an empty realm. That fails in most cases for HTTP (because the
    realm is seldom empty for HTTP challenges). In any case, QHttpNetworkConnection
    never sends the credentials on the first attempt: it needs to find out what
    authentication methods the server supports.

    For FTP, realm is always empty.
*/
QNetworkAuthenticationCredential
QNetworkAccessAuthenticationManager::fetchCachedCredentials(const QUrl &url,
                                                     const QAuthenticator *authentication)
{
    if (!url.password().isEmpty())
        return QNetworkAuthenticationCredential(); // no need to set credentials if it already has them

    QString realm;
    if (authentication)
        realm = authentication->realm();

    QByteArray cacheKey = authenticationKey(url, realm);

    QMutexLocker mutexLocker(&mutex);
    if (!authenticationCache.hasEntry(cacheKey))
        return QNetworkAuthenticationCredential();

    QNetworkAuthenticationCache *auth =
        static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey));
    QNetworkAuthenticationCredential *cred = auth->findClosestMatch(url.path());
    QNetworkAuthenticationCredential ret;
    if (cred)
        ret = *cred;
    authenticationCache.releaseEntry(cacheKey);
    return ret;
}
Beispiel #6
0
void QNoiseGate::setResistance(double resistance)
{
    QMutexLocker mutexLocker(&_mutex);
    _resistance = resistance;
    emit resistanceChanged(_resistance);
    emit resistanceChanged((int)_resistance);
}
Beispiel #7
0
GLC_Object& GLC_Object::operator=(const GLC_Object& object)
{
	QMutexLocker mutexLocker(&m_Mutex);
	m_Uid= object.m_Uid;
	m_Name= object.m_Name;
	return *this;
}
Beispiel #8
0
void QNoiseGate::setThreshold(double threshold)
{
    QMutexLocker mutexLocker(&_mutex);
    _threshold = threshold;
    emit thresholdChanged(_threshold);
    emit thresholdChanged((int)_threshold);
}
Beispiel #9
0
void QNoiseGate::setSensitivy(double sensitivity)
{
    QMutexLocker mutexLocker(&_mutex);
    _sensitivity = sensitivity;
    emit sensitivityChanged(_sensitivity);
    emit sensitivityChanged((int)_sensitivity);
}
Beispiel #10
0
AudioFifo::AudioFifo(uint sampleSize, uint numSamples) :
	m_fifo(0)
{
	QMutexLocker mutexLocker(&m_mutex);

	create(sampleSize, numSamples);
}
QNetworkAuthenticationCredential
QNetworkAccessAuthenticationManager::fetchCachedProxyCredentials(const QNetworkProxy &p,
                                                     const QAuthenticator *authenticator)
{
    QNetworkProxy proxy = p;
    if (proxy.type() == QNetworkProxy::DefaultProxy) {
        proxy = QNetworkProxy::applicationProxy();
    }
    if (!proxy.password().isEmpty())
        return QNetworkAuthenticationCredential(); // no need to set credentials if it already has them

    QString realm;
    if (authenticator)
        realm = authenticator->realm();

    QMutexLocker mutexLocker(&mutex);
    QByteArray cacheKey = proxyAuthenticationKey(proxy, realm);
    if (cacheKey.isEmpty())
        return QNetworkAuthenticationCredential();
    if (!authenticationCache.hasEntry(cacheKey))
        return QNetworkAuthenticationCredential();

    QNetworkAuthenticationCache *auth =
        static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey));
    QNetworkAuthenticationCredential cred = *auth->findClosestMatch(QString());
    authenticationCache.releaseEntry(cacheKey);

    // proxy cache credentials always have exactly one item
    Q_ASSERT_X(!cred.isNull(), "QNetworkAccessManager",
               "Internal inconsistency: found a cache key for a proxy, but it's empty");
    return cred;
}
QString Model::DjVuPage::text(const QRectF& rect) const
{
    QMutexLocker mutexLocker(&m_parent->m_mutex);

    miniexp_t pageTextExp;

    while(true)
    {
        pageTextExp = ddjvu_document_get_pagetext(m_parent->m_document, m_index, "word");

        if(pageTextExp == miniexp_dummy)
        {
            clearMessageQueue(m_parent->m_context, true);
        }
        else
        {
            break;
        }
    }

    const QString text = loadText(pageTextExp, QTransform::fromScale(m_resolution / 72.0, m_resolution / 72.0).mapRect(rect).toRect(), m_size.height());

    ddjvu_miniexp_release(m_parent->m_document, pageTextExp);

    return text.trimmed();
}
void QNetworkAccessAuthenticationManager::cacheCredentials(const QUrl &url,
                                                  const QAuthenticator *authenticator)
{
    Q_ASSERT(authenticator);
    QString domain = QString::fromLatin1("/"); // FIXME: make QAuthenticator return the domain
    QString realm = authenticator->realm();

    QMutexLocker mutexLocker(&mutex);

    // Set two credentials actually: one with and one without the username in the URL
    QUrl copy = url;
    copy.setUserName(authenticator->user());
    do {
        QByteArray cacheKey = authenticationKey(copy, realm);
        if (authenticationCache.hasEntry(cacheKey)) {
            QNetworkAuthenticationCache *auth =
                static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey));
            auth->insert(domain, authenticator->user(), authenticator->password());
            authenticationCache.releaseEntry(cacheKey);
        } else {
            QNetworkAuthenticationCache *auth = new QNetworkAuthenticationCache;
            auth->insert(domain, authenticator->user(), authenticator->password());
            authenticationCache.addEntry(cacheKey, auth);
        }

        if (copy.userName().isEmpty()) {
            break;
        } else {
            copy.setUserName(QString());
        }
    } while (true);
}
Beispiel #14
0
	void DeviceCopyThread::stop()
	{
		disconnect();
		
		QMutexLocker mutexLocker(&mMutex);
		
		mContinue = false;
	}
Beispiel #15
0
 STDMETHODIMP QAsyncReader::BeginFlush()
 {
     QMutexLocker mutexLocker(&m_mutexWait);
     QWriteLocker locker(&m_lock);
     m_flushing = true;
     m_requestWait.wakeOne();
     return S_OK;
 }
Beispiel #16
0
void
JobQueue::Close()
{
	if (fMutexInitialized && fNewJobConditionInitialized) {
		PthreadMutexLocker mutexLocker(fMutex);
		fClosed = true;
		pthread_cond_broadcast(&fNewJobCondition);
	}
}
Beispiel #17
0
void RenderTask::wait()
{
    QMutexLocker mutexLocker(&m_mutex);

    while(m_isRunning)
    {
        m_waitCondition.wait(&m_mutex);
    }
}
Beispiel #18
0
QNetworkAccessManager* evernoteNetworkAccessManager() {
    static QSharedPointer<QNetworkAccessManager> networkAccessManager_;
    static QMutex networkAccessManagerMutex;
    QMutexLocker mutexLocker(&networkAccessManagerMutex);
    if(networkAccessManager_.isNull()) {
        networkAccessManager_ = QSharedPointer<QNetworkAccessManager>(new QNetworkAccessManager);
    }
    return networkAccessManager_.data();
}
void Model::DjVuDocument::loadProperties(QStandardItemModel* propertiesModel) const
{
    Document::loadProperties(propertiesModel);

    QMutexLocker mutexLocker(&m_mutex);

    propertiesModel->setColumnCount(2);

    miniexp_t annoExp;

    while(true)
    {
        annoExp = ddjvu_document_get_anno(m_document, TRUE);

        if(annoExp == miniexp_dummy)
        {
            clearMessageQueue(m_context, true);
        }
        else
        {
            break;
        }
    }

    const int annoLength = miniexp_length(annoExp);

    for(int annoN = 0; annoN < annoLength; ++annoN)
    {
        miniexp_t listExp = miniexp_nth(annoN, annoExp);
        const int listLength = miniexp_length(listExp);

        if(listLength <= 1 || qstrncmp(miniexp_to_name(miniexp_nth(0, listExp)), "metadata", 8) != 0)
        {
            continue;
        }

        for(int listN = 1; listN < listLength; ++listN)
        {
            miniexp_t keyValueExp = miniexp_nth(listN, listExp);

            if(miniexp_length(keyValueExp) != 2)
            {
                continue;
            }

            const QString key = QString::fromUtf8(miniexp_to_name(miniexp_nth(0, keyValueExp)));
            const QString value = QString::fromUtf8(miniexp_to_str(miniexp_nth(1, keyValueExp)));

            if(!key.isEmpty() && !value.isEmpty())
            {
                propertiesModel->appendRow(QList< QStandardItem* >() << new QStandardItem(key) << new QStandardItem(value));
            }
        }
    }

    ddjvu_miniexp_release(m_document, annoExp);
}
Beispiel #20
0
void AudioFifo::clear()
{
	QMutexLocker mutexLocker(&m_mutex);

	m_fill = 0;
	m_head = 0;
	m_tail = 0;

	m_writeWaitCondition.wakeOne();
}
void QOggSimplePlayer::internalStart()
{
    QMutexLocker mutexLocker(&mutex);
    needPlay=true;
    if(output==NULL)
        return;
    internalStop();
    readDone();
    output->start(&buffer);
}
void AnnotationWidget::on_textChanged()
{
#ifndef HAS_POPPLER_24

    QMutexLocker mutexLocker(m_mutex);

#endif // HAS_POPPLER_24

    m_annotation->setContents(toPlainText());
}
void WebEngine::addResource(Resource *resource) {
    // The list of pending requests may be accessed from multiple server
    // and other threads, so we have to make sure to lock properly.
    MutexLocker mutexLocker(_resourcesMutex); Q_UNUSED(mutexLocker);
    if(resource == 0) {
        return;
    }

    resource->setParent(this);
    _resources.insert(resource);
}
void CodeReaderThread::checkForCodes(const QImage &image)
{
    QMutexLocker mutexLocker(&m_mutex);

    m_image = QImage(image);

    if (!isRunning())
        start();
    else
        m_condition.wakeOne();
}
Beispiel #25
0
void FCDInput::stopInput()
{
	QMutexLocker mutexLocker(&m_mutex);

	if(m_FCDThread) {
		m_FCDThread->stopWork();
		// wait for thread to quit ?
		delete m_FCDThread;
		m_FCDThread = NULL;
	}
	m_deviceDescription.clear();
}
Beispiel #26
0
string OSMapEx::GererateAndInsert(SInt64 lastingTime)
{
	OSMutexLocker mutexLocker(&m_Mutex);
	string  strSessionId;
	do
	{
		strSessionId = OSMapEx::GenerateSessionId();//生成sessionid
	} while (m_Map.find(strSessionId) != m_Map.end());//如果是重复的就一直生成直到不是重复的
	strMapData strTemp(lastingTime + OS::Microseconds(), 0);//0表示自动删除,验证1次就删除
	m_Map.insert(MapType::value_type(strSessionId, strTemp));
	return strSessionId;
}
Beispiel #27
0
bool OSMapEx::Insert(const string& strSessionId, SInt64 lastingTime)
{
	OSMutexLocker mutexLocker(&m_Mutex);
	if (m_Map.find(strSessionId) != m_Map.end())//已经存在
		return false;
	else
	{
		strMapData strTemp(lastingTime + OS::Microseconds(), 1);//1表示不自动删除,直到超时再删除
		m_Map.insert(MapType::value_type(strSessionId, strTemp));
		return true;
	}
}
void TorrentStorrage::remove(QString infoHash)
{
	QMutexLocker mutexLocker(m_pMapSynkMutex);
	QMap<QString, Torrent*>::Iterator it = m_torrentsMap.find(infoHash);
	int index = indexOf(it.value());

	if(index >= 0)
	{
		QList<Torrent*>::removeAt(index);
		m_torrentsMap.remove(infoHash);
	}
}
DB DatabasePool::get() {


    logDebug("DatabasePool::getConnection(): Get database connection..");

    while (true) {

        logDebug("DatabasePool::getConnection(): lock mutex..");
        QMutexLocker mutexLocker(&_getDatabaseConnectionMutex);
        logDebug("DatabasePool::getConnection(): mutex locked successful..");

        // Überprüfen, ob diesem Thread bereits eine Datenbankverbindung hat, wenn ja, dann die selbe wieder zurückgeben:
        if (_freedDatabaseConnections.contains(QThread::currentThreadId())) {
            logDebug("DatabasePool::getConnection(): Thread already have a database connection, returns the same...");
            return _getThreadConnection();
        }

        try {

            logDebug("DatabasePool::getConnection(): Free connections in pool: %1", QString::number(_pool.size()));
            if (_pool.size() > 0) {

                // Verfügbare Verbindung aus dem Pool holen:
                logDebug("DatabasePool::getConnection(): Return the next free connection from the pool.");
                return _getNextConnection();
            }

            // Da keine Verbindung verfügbar, überprüfen, ob das maximale Limit an Verbindungen erreicht wurde?
            if (_maxConnections > _countConnections) {

                logNotice("DatabasePool::getConnection(): No db connection available, max %1, created %2, create a new...", QString::number(_maxConnections), QString::number(_countConnections));
                _createPoolConnection();

                return _getNextConnection();
            }

            logError("DatabasePool::getConnection(): No connection available (max %1, created %2), sleep 50ms..", QString::number(_maxConnections), QString::number(_countConnections));
        }
        catch (SqlException *e) {

            /**
              * @TODO: Defekte Datenbankverbindungen filtern???
              */

            throw e;
        }

        // Wenn keine Datenbankverbindung zurückgegeben werden konnte, so Mutex entsperren und 50ms schlafen...
        mutexLocker.unlock();
        usleep(50);
    }
}
Beispiel #30
0
void VCSJobRunner::stop()
{
    {
        QMutexLocker mutexLocker(&d->m_mutex); Q_UNUSED(mutexLocker);
        d->m_keepRunning = false;
        //Create a dummy task to break the cycle
        QSharedPointer<VCSJob> job(0);
        d->m_jobs.enqueue(job);
        d->m_waiter.wakeAll();
    }

    wait();
}