void PeerObject::readStdin()
{
	QReadLocker		readLocker(&m_peerStreamLock);

	// m_dbgLog.write("PeerObject::readStdin()\n");
	// m_dbgLog.flush();

// 	qDebug("PeerObject::readStdin()");

	while(m_peerSocket->canReadLine()) {
		QString				line(m_peerSocket->readLine());

		QChar					cmd(line.at(0));
		QByteArray		data(QByteArray::fromHex(line.mid(1).toLatin1()));

		// Close?
		if(cmd == 'c') {
// 			qDebug("===== Received close!");
			disconnect(m_peerSocket, SIGNAL(readyRead()), this, SLOT(readStdin()));

// 			m_dbgLog.write("PeerObject::readStdin() - close\n");
// 			m_dbgLog.flush();
			m_close	=	true;

			// m_dbgLog.write("Locking: 97\n");// m_dbgLog.flush();
			QReadLocker	readLocker(&m_dataDescriptionLock);
			// m_dbgLog.write("Ok: 97\n");// m_dbgLog.flush();

			if(m_dataDescription.isEmpty()) {
// 				m_dbgLog.write("c: close!\n");
// 				m_dbgLog.flush();
				close();
			}

			return;
		}

		static int recCount	=	0;
		recCount++;
		Logger::log("Read commands", recCount);
// 		m_dbgLog.write("Received: ");
// 		m_dbgLog.write(QString("(%1) %2").arg(++recCount).arg(cmd).toLatin1());
// 		m_dbgLog.write(data);
// 		m_dbgLog.write("\n");
// 		m_dbgLog.flush();

		// m_dbgLog.write("Locking: 113\n");// m_dbgLog.flush();
		QWriteLocker		writeLock(&m_dataDescriptionLock);
		// m_dbgLog.write("Ok: 113\n");// m_dbgLog.flush();
		m_dataDescription.append(QPair<QChar, QByteArray>(cmd, data));
		writeLock.unlock();

		callSlotQueued(this, "checkReadData");
	}
}
void TestLocalSocket_Peer::onDisconnected()
{
	QWriteLocker		readLocker(&m_recDiscLock);
	
	m_recDisconnectedSignal	=	true;
	m_recDiscSignalChanged.wakeAll();
}
Beispiel #3
0
void*
object_depot_obtain(object_depot* depot)
{
	ReadLocker readLocker(depot->outer_lock);
	InterruptsLocker interruptsLocker;

	depot_cpu_store* store = object_depot_cpu(depot);

	// To better understand both the Alloc() and Free() logic refer to
	// Bonwick's ``Magazines and Vmem'' [in 2001 USENIX proceedings]

	// In a nutshell, we try to get an object from the loaded magazine
	// if it's not empty, or from the previous magazine if it's full
	// and finally from the Slab if the magazine depot has no full magazines.

	if (store->loaded == NULL)
		return NULL;

	while (true) {
		if (!store->loaded->IsEmpty())
			return store->loaded->Pop();

		if (store->previous
			&& (store->previous->IsFull()
				|| exchange_with_full(depot, store->previous))) {
			std::swap(store->previous, store->loaded);
		} else
			return NULL;
	}
}
Beispiel #4
0
QPixmap SvgHandler::renderSvg( const QString &name, const QString& keyname, int width, int height, const QString& element )
{
    QPixmap pixmap( width, height );
    pixmap.fill( Qt::transparent );

    QReadLocker readLocker( &m_lock );
    if( ! m_renderers[name] )
    {
        readLocker.unlock();
        if( !loadSvg( name ) )
            return pixmap;
        readLocker.relock();
    }

    const QString key = QString("%1:%2x%3")
        .arg( keyname )
        .arg( width )
        .arg( height );


    if ( !m_cache->find( key, pixmap ) ) {
//         debug() << QString("svg %1 not in cache...").arg( key );

        QPainter pt( &pixmap );
        if ( element.isEmpty() )
            m_renderers[name]->render( &pt, QRectF( 0, 0, width, height ) );
        else
            m_renderers[name]->render( &pt, element, QRectF( 0, 0, width, height ) );
  
        m_cache->insert( key, pixmap );
    }

    return pixmap;
}
    QString BasicKeywordsModel::getTitle() {
        QReadLocker readLocker(&m_TitleLock);

        Q_UNUSED(readLocker);

        return m_Title;
    }
    QString BasicKeywordsModel::getKeywordsString() {
        QReadLocker readLocker(&m_KeywordsLock);

        Q_UNUSED(readLocker);

        return m_KeywordsList.join(", ");
    }
    QSet<QString> BasicKeywordsModel::getKeywordsSet() {
        QReadLocker readLocker(&m_KeywordsLock);

        Q_UNUSED(readLocker);

        return m_KeywordsSet;
    }
KisPaintDeviceSP KisMultipleProjection::getProjection(const QString &id, const QString &compositeOpId, KisPaintDeviceSP prototype)
{
    QReadLocker readLocker(&m_d->lock);

    PlanesMap::const_iterator constIt = m_d->planes.constFind(id);

    if (constIt == m_d->planes.constEnd() ||
        constIt->compositeOpId != compositeOpId ||
        !(*constIt->device->colorSpace() == *prototype->colorSpace())) {

        readLocker.unlock();

        {
            QWriteLocker writeLocker(&m_d->lock);

            PlanesMap::iterator writeIt = m_d->planes.find(id);
            if (writeIt == m_d->planes.end()) {
                ProjectionStruct plane;
                plane.device = new KisPaintDevice(*prototype);
                plane.compositeOpId = compositeOpId;
                writeIt = m_d->planes.insert(id, plane);
            } else if (writeIt->compositeOpId != compositeOpId ||
                       !(*writeIt->device->colorSpace() == *prototype->colorSpace())) {

                writeIt->device->makeCloneFromRough(prototype, prototype->extent());
                writeIt->compositeOpId = compositeOpId;
            }

            return writeIt->device;
        }
    }

    return constIt->device;
}
    bool BasicKeywordsModel::isDescriptionEmpty() {
        QReadLocker readLocker(&m_DescriptionLock);

        Q_UNUSED(readLocker);

        return m_Description.trimmed().isEmpty();
    }
Beispiel #10
0
    bool BasicKeywordsModel::areKeywordsEmpty() {
        QReadLocker readLocker(&m_KeywordsLock);

        Q_UNUSED(readLocker);

        return m_KeywordsList.isEmpty();
    }
Beispiel #11
0
    bool BasicKeywordsModel::isTitleEmpty() {
        QReadLocker readLocker(&m_TitleLock);

        Q_UNUSED(readLocker);

        return m_Title.trimmed().isEmpty();
    }
Beispiel #12
0
    bool BasicKeywordsModel::hasKeywordsSpellError() {
        QReadLocker readLocker(&m_KeywordsLock);

        Q_UNUSED(readLocker);

        return hasKeywordsSpellErrorUnsafe();
    }
Beispiel #13
0
    bool BasicKeywordsModel::hasKeyword(const QString &keyword) {
        QReadLocker readLocker(&m_KeywordsLock);

        Q_UNUSED(readLocker);

        return !canBeAddedUnsafe(keyword.simplified());
    }
Beispiel #14
0
    QStringList BasicKeywordsModel::getKeywords() {
        QReadLocker readLocker(&m_KeywordsLock);

        Q_UNUSED(readLocker);

        return m_KeywordsList;
    }
Beispiel #15
0
    int BasicKeywordsModel::getKeywordsCount() {
        QReadLocker readLocker(&m_KeywordsLock);

        Q_UNUSED(readLocker);

        return m_KeywordsSet.count();
    }
Beispiel #16
0
    QString BasicKeywordsModel::getDescription() {
        QReadLocker readLocker(&m_DescriptionLock);

        Q_UNUSED(readLocker);

        return m_Description;
    }
bool TestLocalSocket_Peer::waitForDisconnectedSignal(int timeout)
{
	QReadLocker		readLocker(&m_recDiscLock);
	
	if(m_recDisconnectedSignal)
		return true;
	
	return m_recDiscSignalChanged.wait(&m_recDiscLock, timeout);
}
void KisMultipleProjection::clear(const QRect &rc)
{
    QReadLocker readLocker(&m_d->lock);

    PlanesMap::const_iterator it = m_d->planes.constBegin();
    PlanesMap::const_iterator end = m_d->planes.constEnd();

    for (; it != end; ++it) {
        const_cast<KisPaintDevice*>(it->device.data())->clear(rc);
    }
}
Beispiel #19
0
QPixmap SvgHandler::addBordersToPixmap( const QPixmap &orgPixmap, int borderWidth, const QString &name, bool skipCache )
{
    int newWidth = orgPixmap.width() + borderWidth * 2;
    int newHeight = orgPixmap.height() + borderWidth *2;

    QString key;
    if( !skipCache )
    {
        key = QString("%1:%2x%3b%4")
            .arg( name )
            .arg( newWidth )
            .arg( newHeight )
            .arg( borderWidth );
    }

    QPixmap pixmap;
    if( skipCache || !m_cache->findPixmap( key, &pixmap ) )
    {
        // Cache miss! We need to create the pixmap
        // if skipCache is true, we might actually already have fetched the image, including borders from the cache....
        // so we really need to create a blank pixmap here as well, to not pollute the cached pixmap
        pixmap = QPixmap( newWidth, newHeight );
        pixmap.fill( Qt::transparent );

        QReadLocker readLocker( &m_lock );
        if( !m_renderers[m_themeFile] )
        {
            readLocker.unlock();
            if( !loadSvg( m_themeFile ) )
            {
                return pixmap;
            }
            readLocker.relock();
        }

        QPainter pt( &pixmap );

        pt.drawPixmap( borderWidth, borderWidth, orgPixmap.width(), orgPixmap.height(), orgPixmap );

        m_renderers[m_themeFile]->render( &pt, "cover_border_topleft", QRectF( 0, 0, borderWidth, borderWidth ) );
        m_renderers[m_themeFile]->render( &pt, "cover_border_top", QRectF( borderWidth, 0, orgPixmap.width(), borderWidth ) );
        m_renderers[m_themeFile]->render( &pt, "cover_border_topright", QRectF( newWidth - borderWidth , 0, borderWidth, borderWidth ) );
        m_renderers[m_themeFile]->render( &pt, "cover_border_right", QRectF( newWidth - borderWidth, borderWidth, borderWidth, orgPixmap.height() ) );
        m_renderers[m_themeFile]->render( &pt, "cover_border_bottomright", QRectF( newWidth - borderWidth, newHeight - borderWidth, borderWidth, borderWidth ) );
        m_renderers[m_themeFile]->render( &pt, "cover_border_bottom", QRectF( borderWidth, newHeight - borderWidth, orgPixmap.width(), borderWidth ) );
        m_renderers[m_themeFile]->render( &pt, "cover_border_bottomleft", QRectF( 0, newHeight - borderWidth, borderWidth, borderWidth ) );
        m_renderers[m_themeFile]->render( &pt, "cover_border_left", QRectF( 0, borderWidth, borderWidth, orgPixmap.height() ) );
    
        if( !skipCache )
            m_cache->insertPixmap( key, pixmap );
    }

    return pixmap;
}
Beispiel #20
0
    QString BasicKeywordsModel::retrieveKeyword(int wordIndex) {
        QReadLocker readLocker(&m_KeywordsLock);

        Q_UNUSED(readLocker);

        QString keyword;
        if (0 <= wordIndex && wordIndex < m_KeywordsList.length()) {
            keyword = m_KeywordsList.at(wordIndex);
        }

        return keyword;
    }
Beispiel #21
0
void
object_depot_store(object_depot* depot, void* object, uint32 flags)
{
	ReadLocker readLocker(depot->outer_lock);
	InterruptsLocker interruptsLocker;

	depot_cpu_store* store = object_depot_cpu(depot);

	// We try to add the object to the loaded magazine if we have one
	// and it's not full, or to the previous one if it is empty. If
	// the magazine depot doesn't provide us with a new empty magazine
	// we return the object directly to the slab.

	while (true) {
		if (store->loaded != NULL && store->loaded->Push(object))
			return;

		DepotMagazine* freeMagazine = NULL;
		if ((store->previous != NULL && store->previous->IsEmpty())
			|| exchange_with_empty(depot, store->previous, freeMagazine)) {
			std::swap(store->loaded, store->previous);

			if (freeMagazine != NULL) {
				// Free the magazine that didn't have space in the list
				interruptsLocker.Unlock();
				readLocker.Unlock();

				empty_magazine(depot, freeMagazine, flags);

				readLocker.Lock();
				interruptsLocker.Lock();

				store = object_depot_cpu(depot);
			}
		} else {
			// allocate a new empty magazine
			interruptsLocker.Unlock();
			readLocker.Unlock();

			DepotMagazine* magazine = alloc_magazine(depot, flags);
			if (magazine == NULL) {
				depot->return_object(depot, depot->cookie, object, flags);
				return;
			}

			readLocker.Lock();
			interruptsLocker.Lock();

			push_empty_magazine(depot, magazine);
			store = object_depot_cpu(depot);
		}
	}
}
void KisMultipleProjection::apply(KisPaintDeviceSP dstDevice, const QRect &rect)
{
    QReadLocker readLocker(&m_d->lock);

    PlanesMap::const_iterator it = m_d->planes.constBegin();
    PlanesMap::const_iterator end = m_d->planes.constEnd();

    for (; it != end; ++it) {
        KisPainter gc(dstDevice);
        gc.setCompositeOp(it->compositeOpId);
        gc.bitBlt(rect.topLeft(), it->device, rect);
    }
}
void KisMultipleProjection::syncLodCache()
{
    QReadLocker readLocker(&m_d->lock);

    PlanesMap::const_iterator it = m_d->planes.constBegin();
    PlanesMap::const_iterator end = m_d->planes.constEnd();

    for (; it != end; ++it) {
        KisPaintDeviceSP device = it->device;
        QRegion dirtyRegion = device->syncLodCache(device->defaultBounds()->currentLevelOfDetail());
        Q_UNUSED(dirtyRegion);
    }
}
KisPaintDeviceList KisMultipleProjection::getLodCapableDevices() const
{
    QReadLocker readLocker(&m_d->lock);

    PlanesMap::const_iterator it = m_d->planes.constBegin();
    PlanesMap::const_iterator end = m_d->planes.constEnd();

    KisPaintDeviceList list;
    for (; it != end; ++it) {
        list << it->device;
    }

    return list;
}
Beispiel #25
0
KSvgRenderer* SvgHandler::getRenderer( const QString& name )
{
    QReadLocker readLocker( &m_lock );
    if( ! m_renderers[name] )
    {
        readLocker.unlock();
        if( !loadSvg( name ) )
        {
            QWriteLocker writeLocker( &m_lock );
            m_renderers[name] = new KSvgRenderer();
        }
        readLocker.relock();
    }
    return m_renderers[name];
}
void LocalSocketPrivate::flush()
{
	QReadLocker		readLocker(&m_writeBufferLock);
	QReadLocker		controlLock(&m_controlLock);
	
	while(m_isOpen && !m_writeBuffer.isEmpty() && !m_currentReadData.isEmpty())
	{
		controlLock.unlock();
		readLocker.unlock();
// 		qDebug("[%p] LocalSocketPrivate::flush() - flushing", this);
		writeData();
		readData();
		
		readLocker.relock();
		controlLock.relock();
	}
}
Beispiel #27
0
QPixmap SvgHandler::renderSvgWithDividers(const QString & keyname, int width, int height, const QString & element)
{

    QString name = m_themeFile;
    
    QPixmap pixmap( width, height );
    pixmap.fill( Qt::transparent );

    QReadLocker readLocker( &m_lock );
    if( ! m_renderers[name] )
    {
        readLocker.unlock();
        if( ! loadSvg( name ) )
            return pixmap;
        readLocker.relock();
    }

    const QString key = QString("%1:%2x%3-div")
            .arg( keyname )
            .arg( width )
            .arg( height );


    if ( !m_cache->find( key, pixmap ) ) {
//         debug() << QString("svg %1 not in cache...").arg( key );

        QPainter pt( &pixmap );
        if ( element.isEmpty() )
            m_renderers[name]->render( &pt, QRectF( 0, 0, width, height ) );
        else
            m_renderers[name]->render( &pt, element, QRectF( 0, 0, width, height ) );


        //add dividers. 5% spacing on each side
        int margin = width / 20;
        
        m_renderers[name]->render( &pt, "divider_top", QRectF( margin, 0 , width - 1 * margin, 1 ) );
        m_renderers[name]->render( &pt, "divider_bottom", QRectF( margin, height - 1 , width - 2 * margin, 1 ) );
    
        m_cache->insert( key, pixmap );
    }

    return pixmap;

}
Beispiel #28
0
QPixmap SvgHandler::renderSvg( const QString &name,
                               const QString& keyname,
                               int width,
                               int height,
                               const QString& element,
                               bool skipCache )
{
    QString key;
    if( !skipCache )
    {
        key = QString("%1:%2x%3")
            .arg( keyname )
            .arg( width )
            .arg( height );
    }

    QPixmap pixmap;
    if( skipCache || !m_cache->findPixmap( key, &pixmap ) )
    {
        pixmap = QPixmap( width, height );
        pixmap.fill( Qt::transparent );

        QReadLocker readLocker( &m_lock );
        if( ! m_renderers[name] )
        {
            readLocker.unlock();
            if( !loadSvg( name ) )
            {
                return pixmap;
            }
            readLocker.relock();
        }

        QPainter pt( &pixmap );
        if ( element.isEmpty() )
            m_renderers[name]->render( &pt, QRectF( 0, 0, width, height ) );
        else
            m_renderers[name]->render( &pt, element, QRectF( 0, 0, width, height ) );
  
        if( !skipCache )
            m_cache->insertPixmap( key, pixmap );
    }

    return pixmap;
}
Beispiel #29
0
    std::vector<std::shared_ptr<SpellCheck::SpellSuggestionsItem> > BasicKeywordsModel::createKeywordsSuggestionsList() {
        QReadLocker readLocker(&m_KeywordsLock);

        Q_UNUSED(readLocker);

        std::vector<std::shared_ptr<SpellCheck::SpellSuggestionsItem> > spellCheckSuggestions;
        int length = m_KeywordsList.length();
        spellCheckSuggestions.reserve(length/2);

        for (int i = 0; i < length; ++i) {
            if (!m_SpellCheckResults[i]) {
                const QString &keyword = m_KeywordsList.at(i);
                LOG_DEBUG << keyword << "has wrong spelling";

                if (!keyword.contains(QChar::Space)) {
                    spellCheckSuggestions.emplace_back(new SpellCheck::KeywordSpellSuggestions(keyword, i));
                } else {
                    QStringList items = keyword.split(QChar::Space, QString::SkipEmptyParts);
                    foreach(const QString &item, items) {
                        spellCheckSuggestions.emplace_back(new SpellCheck::KeywordSpellSuggestions(item, i, keyword));
                    }
                }
            }
        }
Beispiel #30
0
SharedNodePointer LimitedNodeList::nodeWithUUID(const QUuid& nodeUUID) {
    QReadLocker readLocker(&_nodeMutex);

    NodeHash::const_iterator it = _nodeHash.find(nodeUUID);
    return it == _nodeHash.cend() ? SharedNodePointer() : it->second;
}