Example #1
0
void Rectangle::draw()
{
	getShader()->beginShader();
    if (getShader()->drawShaded()) {
		getShader()->beginShading();
    	beginList();
    	if(!isCached())
    	{
			glRectf(x, y, width, height);
		}
    	endList();
 	    getShader()->endShading();
	}
    if (getShader()->drawOutline()) {
    	getShader()->beginOutline();
		beginList();
    	if(!isCached())
    	{
			glRectf(x, y, width, height);
		}
    	endList();
    	getShader()->endOutline();

    }
    getShader()->endShader();
}
void QGeoMapReplyNokia::networkFinished()
{
    if (!m_reply)
        return;

    if (m_reply->error() != QNetworkReply::NoError)
        return;

    QVariant fromCache = m_reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute);
    setCached(fromCache.toBool());

    if (!isCached()) {
        QAbstractNetworkCache *cache = m_reply->manager()->cache();
        if (cache) {
            QNetworkCacheMetaData metaData = cache->metaData(m_reply->url());
            QDateTime exp = QDateTime::currentDateTime();
            exp = exp.addDays(14);
            metaData.setExpirationDate(exp);
            cache->updateMetaData(metaData);
        }
    }

    setMapImageData(m_reply->readAll());
    setMapImageFormat("PNG");
    setFinished(true);

    m_reply->deleteLater();
    m_reply = 0;
}
const char * FileCacheDataEx::getCacheData(
    off_t offset, off_t& wanted, char *pBuf, long len )
{
    if ( isCached() )
    {
        if ( offset > m_lSize )
        {
            wanted = 0;
            return pBuf;
        }
        if ( wanted > m_lSize - offset )
            wanted = m_lSize - offset;
        return m_pCache + offset;
    }
    else
    {
        assert( m_fd != -1 );
        off_t off = nio_lseek( m_fd, offset, SEEK_SET );
/*        if ( D_ENABLED( DL_MORE ))
            LOG_D(( "lseek() return %d", (int)off ));*/
        if ( off == offset )
        {
            wanted = nio_read( m_fd, pBuf, len );
        }
        else
        {
            wanted = -1;
        }
        return pBuf;
    }

}
Example #4
0
const QVariant &Settings::localValue(const QString &key, const QVariant &def) {
  QString normKey = normalizedKey(group, key);
  if(!isCached(normKey)) {
    create_qsettings;
    setCacheValue(normKey, s.value(normKey, def));
  }
  return cacheValue(normKey);
}
Example #5
0
void Settings::removeLocalKey(const QString &key) {
  create_qsettings;
  s.beginGroup(group);
  s.remove(key);
  s.endGroup();
  QString normKey = normalizedKey(group, key);
  if(isCached(normKey))
    settingsCache.remove(normKey);
}
bool GlareBaseOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
{
	if (isCached()) {
		return false;
	}
	else {
		rcti newInput;
		newInput.xmax = this->getWidth();
		newInput.xmin = 0;
		newInput.ymax = this->getHeight();
		newInput.ymin = 0;
		return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
	}
}
Example #7
0
void Settings::removeLocalKey(const QString &key)
{
    create_qsettings;
    s.beginGroup(group);
    s.remove(key);
    s.endGroup();
    QString normKey = normalizedKey(group, key);
    if (isCached(normKey)) {
        settingsCache.remove(normKey);
    }
    if (hasNotifier(normKey)) {
        emit notifier(normKey)->valueChanged({});
    }
}
Example #8
0
QVariant Settings::localValue(const QString& key, const QVariant& def) const
{
    QString normKey = normalizedKey(_group, key);
    if (!isCached(normKey)) {
        create_qsettings;
        // Since we're loading from settings anyways, cache whether or not the key exists on disk
        setCacheKeyPersisted(normKey, s.contains(normKey));
        // Cache key value
        setCacheValue(normKey, s.value(normKey, def));
    }
    if (cacheKeyPersisted(normKey)) {
        return cacheValue(normKey);
    }
    // Don't return possibly wrong cached values
    // A key gets cached with the first default value requested and never changes afterwards
    return def;
}
Example #9
0
QVariant CloudRouteModel::data( const QModelIndex& index, int role ) const
{
    if ( index.isValid() && index.row() >= 0 && index.row() < d->m_items.size() ) {
        switch( role ) {
        case Qt::DecorationRole: return preview( index );
        case Timestamp: return d->m_items.at( index.row() ).identifier();
        case Name: return d->m_items.at( index.row() ).name();
        case PreviewUrl: return d->m_items.at( index.row() ).previewUrl();
        case Distance: return d->m_items.at( index.row() ).distance();
        case Duration: return d->m_items.at( index.row() ).duration();
        case IsCached: return isCached( index );
        case IsDownloading: return isDownloading( index );
        case IsOnCloud: return d->m_items.at( index.row() ).onCloud();
        }
    }
    
    return QVariant();
}
Example #10
0
uint64_t FileCacheManager::readFromCache(const sp<DataSource>& mSource, uint64_t offset, char* data, uint64_t readSize){
	Mutex::Autolock autoLock(mLock);
	uint64_t readOffset;
	uint64_t readLen;
	if(isCached(mSource, offset)){
		readOffset = offset - fileOffset;
		if((offset + readSize) > (fileOffset + cachedLen)){
			readLen = (fileOffset + cachedLen - offset);
		}else{
			readLen = readSize;
		}
		memcpy(data, cachedData + readOffset, readLen);

		//ALOGE("[FileCacheManager] Read From Cache: cacheOffset=%lld, cacheLen=%lld, readOffset=%lld, readSize=%lld, retReadSize=%lld",
		//						fileOffset, cachedLen, readOffset, readSize, readLen);
		return readLen;
	}else{
		readOffset = offset;
		readLen = mSource->readAt(offset, cachedData, CACHE_SIZE);
		if(readLen <= 0){
			return readLen;
		}
		cachedSource = mSource;
		fileOffset = readOffset;
		cachedLen = readLen;

		if(readSize <= readLen){
			readLen = readSize;
		}

		memcpy(data, cachedData, readLen);
		
		//ALOGE("[FileCacheManager] Read From File: cacheOffset=%lld, cacheLen=%lld, readOffset=%lld, readSize=%lld, retReadSize=%lld",
		//						fileOffset, cachedLen, readOffset, readSize, readLen);
		return readLen;
	}
}
Example #11
0
vector<float>& KernelCache::getRow(int i)
{
  //cout << "gettingRow " << i << endl;
  if (isCached(i)) {
    //cout << "cached" << endl;
    // remove pattern i from its current position in the list
    lru.erase(lruPtr[i]);
  }
  else {
    //cout << "numCached: " << numCached << endl;
    if (numCached >= numCacheable) {  // need to erase something
      //cout << "erasing..." << endl;
      int elementToErase = lru.back();
      setCached(elementToErase, false);
      rowPtr[i] = rowPtr[elementToErase];
      lru.pop_back();
    }
    else {
      // create the new row:
      //cout << "creating row..." << endl;
      rowPtr[i] = numCached;
      rows[numCached] = vector<float>(length);
      ++numCached;
    }
    setCached(i, true);
    for (int j = 0; j < length; j++) {
      rows[rowPtr[i]][j] = data->kernel->eval(data, i, j, data);
    }
  }
  lru.insert(lru.begin(), i);
  lruPtr[i] = lru.begin();
  //cout << "finished get row" << endl;

  vector<float> &retval = rows[rowPtr[i]];
  return retval;
}
Example #12
0
void SingleExtractor::extractContour(ContourGeometry* contourGeometry, float isovalue, float R, float G, float B) const
{
	contourGeometry->allocateVertexBuffers(m_Width*m_Height);
	contourGeometry->allocateTriangleBuffers(m_Width*m_Height);
	//contourGeometry->setUseColors(false);
	contourGeometry->setUseColors(true);
	contourGeometry->setIsovalue(isovalue);
	unsigned int numCellsX = m_Width-1;
	unsigned int numCellsY = m_Height-1;
	unsigned int numCellsZ = m_Depth-1;

	bool cacheAvailable[12];

	unsigned int offsetTable[8];
	unsigned int withinSliceOffsetTable[8];
	unsigned int cacheOffsetTable[12];
	buildOffsetTable(offsetTable, m_Width, m_Height);
	buildWithinSliceOffsetTable(withinSliceOffsetTable, m_Width);
	buildEdgeCacheOffsetTable(cacheOffsetTable, m_Width);

	unsigned int cubeCase;

	unsigned int i,j,k, voxelOffset, offsetInSlice, newEdge, edgeCounter, triangleCounter, edgeID;

	// the new vertex
	GLfloat v1x, v1y, v1z, v2x, v2y, v2z, den1, den2;
	GLfloat n1x, n1y, n1z, n2x, n2y, n2z;

	// edges involved in a triangle
	unsigned int e1,e2,e3;
	unsigned int rowStart, inSliceRowStart;

	classifyVertices(0, m_Buffers->m_VertClassifications[0], isovalue);

	for (k=0; k<numCellsZ; k++) { // for every slice
		classifyVertices(k+1, m_Buffers->m_VertClassifications[1], isovalue);

		for (j=0; j<numCellsY; j++) { // for every row
			rowStart = m_Width*m_Height*k+m_Width*j;
			inSliceRowStart = m_Width*j;
			for (i=0; i<numCellsX; i++) { // for every cell
				if (i==0 || i==1 || i==numCellsX-1) {
					// isCached only changes at the start and end of a scan line
					// as well as the second voxel of every scan line
					isCached(cacheAvailable, i,j,k,m_Width,m_Height);
				}
				voxelOffset = rowStart+i;
				offsetInSlice = inSliceRowStart+i;
				cubeCase = determineCase(m_Data, withinSliceOffsetTable, offsetInSlice, isovalue);
				if (cubeCase!=0 && cubeCase!=255) {
					// for each edge involved
					for (edgeCounter=0; edgeCounter<cubeedges[cubeCase][0]; edgeCounter++) {
						edgeID = cubeedges[cubeCase][edgeCounter+1];
						// if the edge isnt cached yet, cache it
						if (!cacheAvailable[edgeID]) {

							// add the edge and get its index
							/*computeVertFromOffset(v1x, v1y, v1z, offsetTable[edges[edgeID][0]],
								m_Width, m_Height);*/
							/*computeVertFromOffset(v2x, v2y, v2z, offsetTable[edges[edgeID][1]],
								m_Width, m_Height);*/
							v1x = (GLfloat)(i + verts[edges[edgeID][0]][2]);
							v1y = (GLfloat)(j + verts[edges[edgeID][0]][1]);
							v1z = (GLfloat)(k + verts[edges[edgeID][0]][0]);
							v2x = (GLfloat)(i + verts[edges[edgeID][1]][2]);
							v2y = (GLfloat)(j + verts[edges[edgeID][1]][1]);
							v2z = (GLfloat)(k + verts[edges[edgeID][1]][0]);
							den1 = m_Data[voxelOffset+offsetTable[edges[edgeID][0]]];
							den2 = m_Data[voxelOffset+offsetTable[edges[edgeID][1]]];
							getNormal(m_Data, 
								i + verts[edges[edgeID][0]][2], 
								j + verts[edges[edgeID][0]][1], 
								k + verts[edges[edgeID][0]][0], 
								n1x, n1y, n1z);
							getNormal(m_Data, 
								i + verts[edges[edgeID][1]][2], 
								j + verts[edges[edgeID][1]][1], 
								k + verts[edges[edgeID][1]][0], 
								n2x, n2y, n2z);
							// no color
							//contourGeometry->addEdge(newEdge, v1x, v1y, v1z, n1x, n1y, n1z,
							//	v2x, v2y, v2z, n2x, n2y, n2z, den1, den2);
							// color
							contourGeometry->addEdge(newEdge, v1x, v1y, v1z, n1x, n1y, n1z,
								R,G,B, v2x, v2y, v2z, n2x, n2y, n2z, R,G,B, den1, den2);

							// The location in the cache is determined by two table lookups:
							// FromEdgeToChacheLookup[edgeID] finds which table the edge is cached in
							// offsetInSlice+cacheOffsetTable[edgeID] determines the location in that table
							m_Buffers->m_EdgeCaches[FromEdgeToChacheLookup[edgeID]][offsetInSlice+cacheOffsetTable[edgeID]] = newEdge;

						}
					}
					// All appropriate edges are now cached
					// Build the triangles, using indexes from the cache
					// for each triangle
					
					for (triangleCounter=0; triangleCounter<cubes[cubeCase][0]; triangleCounter++) {
						e1 = cubes[cubeCase][triangleCounter*3+1];
						e2 = cubes[cubeCase][triangleCounter*3+2];
						e3 = cubes[cubeCase][triangleCounter*3+3];
						
						contourGeometry->addTriangle(
							m_Buffers->m_EdgeCaches[FromEdgeToChacheLookup[e1]][offsetInSlice+cacheOffsetTable[e1]], 
							m_Buffers->m_EdgeCaches[FromEdgeToChacheLookup[e2]][offsetInSlice+cacheOffsetTable[e2]], 
							m_Buffers->m_EdgeCaches[FromEdgeToChacheLookup[e3]][offsetInSlice+cacheOffsetTable[e3]]);
					}

				}

			}

		}
		// swap the edge buffers
		m_Buffers->swapEdgeBuffers();
	}

}
void ExternalDictionaries::reloadImpl(const bool throw_on_error)
{
    const auto config_paths = getDictionariesConfigPaths(Poco::Util::Application::instance().config());

    for (const auto & config_path : config_paths)
    {
        try
        {
            reloadFromFile(config_path, throw_on_error);
        }
        catch (...)
        {
            tryLogCurrentException(log, "reloadFromFile has thrown while reading from " + config_path);

            if (throw_on_error)
                throw;
        }
    }

    /// list of recreated dictionaries to perform delayed removal from unordered_map
    std::list<std::string> recreated_failed_dictionaries;

    /// retry loading failed dictionaries
    for (auto & failed_dictionary : failed_dictionaries)
    {
        if (std::chrono::system_clock::now() < failed_dictionary.second.next_attempt_time)
            continue;

        const auto & name = failed_dictionary.first;

        try
        {
            auto dict_ptr = failed_dictionary.second.dict->clone();
            if (const auto exception_ptr = dict_ptr->getCreationException())
            {
                /// recalculate next attempt time
                std::uniform_int_distribution<UInt64> distribution(
                    0, std::exp2(failed_dictionary.second.error_count));

                failed_dictionary.second.next_attempt_time = std::chrono::system_clock::now() +
                    std::chrono::seconds{
                        std::min<UInt64>(backoff_max_sec, backoff_initial_sec + distribution(rnd_engine))};

                ++failed_dictionary.second.error_count;

                std::rethrow_exception(exception_ptr);
            }
            else
            {
                const std::lock_guard<std::mutex> lock{dictionaries_mutex};

                const auto & lifetime = dict_ptr->getLifetime();
                std::uniform_int_distribution<UInt64> distribution{lifetime.min_sec, lifetime.max_sec};
                update_times[name] = std::chrono::system_clock::now() + std::chrono::seconds{distribution(rnd_engine)};

                const auto dict_it = dictionaries.find(name);
                if (dict_it->second.dict)
                    dict_it->second.dict->set(dict_ptr.release());
                else
                    dict_it->second.dict = std::make_shared<MultiVersion<IDictionaryBase>>(dict_ptr.release());

                /// erase stored exception on success
                dict_it->second.exception = std::exception_ptr{};

                recreated_failed_dictionaries.push_back(name);
            }
        }
        catch (...)
        {
            tryLogCurrentException(log, "Failed reloading '" + name + "' dictionary");

            if (throw_on_error)
                throw;
        }
    }

    /// do not undertake further attempts to recreate these dictionaries
    for (const auto & name : recreated_failed_dictionaries)
        failed_dictionaries.erase(name);

    /// periodic update
    for (auto & dictionary : dictionaries)
    {
        const auto & name = dictionary.first;

        try
        {
            /// If the dictionary failed to load or even failed to initialize from the config.
            if (!dictionary.second.dict)
                continue;

            auto current = dictionary.second.dict->get();
            const auto & lifetime = current->getLifetime();

            /// do not update dictionaries with zero as lifetime
            if (lifetime.min_sec == 0 || lifetime.max_sec == 0)
                continue;

            /// update only non-cached dictionaries
            if (!current->isCached())
            {
                auto & update_time = update_times[current->getName()];

                /// check that timeout has passed
                if (std::chrono::system_clock::now() < update_time)
                    continue;

                SCOPE_EXIT({
                    /// calculate next update time
                    std::uniform_int_distribution<UInt64> distribution{lifetime.min_sec, lifetime.max_sec};
                    update_time = std::chrono::system_clock::now() + std::chrono::seconds{distribution(rnd_engine)};
                });

                /// check source modified
                if (current->getSource()->isModified())
                {
                    /// create new version of dictionary
                    auto new_version = current->clone();

                    if (const auto exception_ptr = new_version->getCreationException())
                        std::rethrow_exception(exception_ptr);

                    dictionary.second.dict->set(new_version.release());
                }
            }

            /// erase stored exception on success
            dictionary.second.exception = std::exception_ptr{};
        }