Ejemplo n.º 1
0
void TextureCache::setTexture(QImage &img, Alg::MapTreeNode *node) {
	// Update image cache
	{
		QMutexLocker lock(&imageCacheMutex);

		ImageCache::iterator it;
		QString id = _mapTree->getID(node);
		it = _images.find(id);

		// Image not yet cached, do nothing
		if ( it == _images.end() ) return;

		it->first = img;
	}

	// Update texture cache
	{
		Storage::iterator it = _storage.find(node);
		if ( it != _storage.end() ) {
			Texture *tex = it.value().get();

			// Update storage size
			_storedBytes -= tex->numBytes();
			tex->setImage(img);
			_storedBytes += tex->numBytes();

			checkResources();
		}
	}
}
Ejemplo n.º 2
0
Texture *TextureCache::get(const TextureID &id) {
	Texture *tex;
	Storage::iterator it;

	quint64 oldTick = _currentTick;
	++_currentTick;
	// Wrap. Reset lastUsed of all other tiles
	if ( _currentTick < oldTick ) {
		for ( it = _storage.begin(); it != _storage.end(); ++it )
			it.value()->lastUsed = _currentTick;
		++_currentTick;
	}

	Alg::MapTreeNode *node = NULL;
	Lookup::iterator lit = _firstLevel.find(id);
	if ( lit != _firstLevel.end() )
		tex = *lit;
	else {
		node = getNode(_mapTree, id);
		it = _storage.find(node);
		if ( it != _storage.end() )
			tex = it.value().get();
		else {
			tex = new Texture;
			tex->load(this, node);

			_storage[node] = tex;
			_storedBytes += tex->numBytes();

			checkResources(tex);
		}

		_firstLevel[id] = tex;
	}

	tex->lastUsed = _currentTick;

	// If its a dummy texture then travel up the parent chain to check
	// for valid textures
	if ( tex->isDummy ) {
		if ( node == NULL ) node = getNode(_mapTree, id);

		while ( (node = node->parent()) != NULL ) {
			it = _storage.find(node);
			if ( it == _storage.end() )
				continue;

			Texture *tmp = it.value().get();
			if ( !tmp->isDummy ) {
				tex = tmp;
				break;
			}
		}
	}

	return tex;
}
Ejemplo n.º 3
0
Settings::Settings()
{
    checkResources();

    qDebug() << "Create settings";
    port = 1234;
    rootLog  = "root";
    rootPass = "******";
    mark = 1337;
}
void killServerOnLowResources (float limit_percent)
{
  MediaSet::getMediaSet()->signalEmptyLocked.connect ([limit_percent] () {
    GST_DEBUG ("MediaSet empty, checking resources");

    try {
      checkResources (limit_percent);
    } catch (KurentoException &e) {
      if (e.getCode() == NOT_ENOUGH_RESOURCES) {
        GST_ERROR ("Resources over the limit, server will be killed");
        kill ( getpid(), SIGTERM );
      }
    }
  });
}
Ejemplo n.º 5
0
bool UpdateModel::setData(const QModelIndex &idx, const QVariant &value, int role)
{
    if (role == Qt::CheckStateRole) {
        UpdateItem *item = itemFromIndex(idx);
        const bool newValue = value.toInt() == Qt::Checked;
        const QList<AbstractResource *> apps = { item->app() };

        checkResources(apps, newValue);
        Q_ASSERT(idx.data(Qt::CheckStateRole) == value);
        Q_EMIT dataChanged(idx, idx, { Qt::CheckStateRole });
        Q_EMIT toUpdateChanged();

        return true;
    }

    return false;
}
Ejemplo n.º 6
0
//----------------------------------------------------------------------------------
void Simulation::changeEnvironment(const int& time,MeasurementsTable& table)
{
	if (mErrorCode!=EcNoError) return;

	dot("Current resources: "+ftoa(mResources));
	const double inflow = mpFunctions->R(mResources,time);
	dot("Inflow: "+ftoa(inflow));
	//Note: Inflow can also be negative
	mResources+=inflow;
	dot("New resources: "+ftoa(mResources));
	checkPopSize("void Simulation::changeEnvironment(const int& time)");
	const unsigned int popSize = SoilMiteBase::getPopSize();
	if (popSize==0) { mErrorCode = EcPopExtinct; return; }
	//Create a vector of bodySizes...
	std::vector<double> popBodySize(popSize);
	for (unsigned int i=0; i<popSize; ++i) popBodySize[i] = mPop[i]->getBodySize();
	mVectorResources = mpFunctions->distributeResources(popBodySize, mResources);
	assert(mVectorResources.size()==popBodySize.size());
	checkResources(mResources);
}
Ejemplo n.º 7
0
void
ServerMethods::create (const Json::Value &params,
                       Json::Value &response)
{
  std::string type;
  std::shared_ptr<Factory> factory;
  std::string sessionId;

  requireParams (params);

  JsonRpc::getValue (params, TYPE, type);

  try {
    JsonRpc::getValue (params, SESSION_ID, sessionId);
  } catch (JsonRpc::CallException e) {
    sessionId = generateUUID ();
  }

  try {
    factory = moduleManager.getFactory (type);

    checkResources (resourceLimitPercent);

    std::shared_ptr <MediaObjectImpl> object;

    object = std::dynamic_pointer_cast<MediaObjectImpl> (
               factory->createObject (config, sessionId, params["constructorParams"]) );

    response[VALUE] = object->getId();
    response[SESSION_ID] = sessionId;
  } catch (KurentoException &ex) {
    Json::Value data;

    data[TYPE] = ex.getType();

    throw JsonRpc::CallException (ex.getCode (), ex.getMessage (), data);
  }
}
Ejemplo n.º 8
0
void ResourceChecker::handleFileName(const TCHAR *name, DirListEntry &info) {
  checkResources(name);
}