Exemple #1
0
bool KST::duplicateDependents(KstVectorPtr vectorFor, KstDataObjectDataObjectMap& duplicatedMap, QMap<KstVectorPtr, KstVectorPtr> &duplicatedVectors) {
  // work with a copy of the data object list
  KST::dataObjectList.lock().readLock();
  KstDataObjectList dol = QDeepCopy<KstDataObjectList>(KST::dataObjectList);
  KST::dataObjectList.lock().readUnlock();
  
  for (KstDataObjectList::Iterator i = dol.begin(); i != dol.end(); ++i) {
    if ((*i)->uses(vectorFor)) {
      if (duplicatedMap.contains(*i)) {
        (duplicatedMap[*i])->replaceDependency(vectorFor, duplicatedVectors[vectorFor]);  
      } else {
        KstDataObjectPtr newObject = (*i)->makeDuplicate(duplicatedMap);
        newObject->replaceDependency(vectorFor, duplicatedVectors[vectorFor]);
        if (newObject) {
          KST::dataObjectList.lock().writeLock();
          KST::dataObjectList.append(newObject.data());
          KST::dataObjectList.lock().writeUnlock();
          (*i)->duplicateDependents(duplicatedMap);
        }
      }
    }
  }

  return true;
}
Exemple #2
0
bool UpdateThread::doUpdates(bool force, bool *gotData) {
  KstObject::UpdateType U = KstObject::NO_CHANGE;

  _updatedCurves.clear(); // HACK

  if (gotData) {
    *gotData = false;
  }
  
#if UPDATEDEBUG > 0
  if (force) {
    qDebug() << "Forced update!" << endl;
  }
#endif

  _updateCounter++;
  if (_updateCounter < 1) {
    _updateCounter = 1; // check for wrap around
  }

#if UPDATEDEBUG > 2
  qDebug() << "UPDATE: counter=" << _updateCounter << endl;
#endif

  {
    // Must make a copy to avoid deadlock
    KstBaseCurveList cl;
    KstDataObjectList dol;
    kstObjectSplitList<KstDataObject, KstBaseCurve>(KST::dataObjectList, cl, dol);
    qSort(cl); 
    qSort(dol); 

    // Update all curves
    for (uint i = 0; i < cl.count(); ++i) {
      KstBaseCurvePtr bcp = cl[i];
      bcp->writeLock();
      assert(bcp.data());
#if UPDATEDEBUG > 1
      qDebug() << "updating curve: " << (void*)bcp << " - " << bcp->tagName() << endl;
#endif
      KstObject::UpdateType ut = bcp->update(_updateCounter);
      bcp->unlock();

      if (ut == KstObject::UPDATE) { // HACK
        _updatedCurves.append(bcp);
      }

      if (U != KstObject::UPDATE) {
        U = ut;
        if (U == KstObject::UPDATE) {
#if UPDATEDEBUG > 0
          qDebug() << "Curve " << bcp->tagName() << " said UPDATE" << endl;
#endif
        }
      }

      if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
        qDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
        return U == KstObject::UPDATE;
      }
    }

    // Update all data objects
    for (uint i = 0; i < dol.count(); ++i) {
      KstDataObjectPtr dp = dol[i];
      dp->writeLock();
      assert(dp.data());
#if UPDATEDEBUG > 1
      qDebug() << "updating data object: " << (void*)dp << " - " << dp->tagName() << endl;
#endif
      dp->update(_updateCounter);
      dp->unlock();

      if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
        qDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
        return U == KstObject::UPDATE;
      }
    }
  }

  // Update the files
  if (!_paused) { // don't update even if paused && force
    KST::dataSourceList.lock().readLock();
    unsigned cnt = KST::dataSourceList.count();
    for (uint i = 0; i < cnt; ++i) {
      KstDataSourcePtr dsp = KST::dataSourceList[i];

      dsp->writeLock();
      dsp->update(_updateCounter);
      dsp->unlock();

      if (_done) {
        KST::dataSourceList.lock().unlock();
        return false;
      }
    }
    KST::dataSourceList.lock().unlock();
  }

  if (KstScalar::scalarsDirty()) {
    KstScalar::clearScalarsDirty(); // Must do this first and take a risk of
                                    // falling slightly behind
    KST::scalarList.lock().readLock();
    KstScalarList sl = Q3DeepCopy<KstScalarList>(KST::scalarList.list()); // avoid deadlock on exit
    KST::scalarList.lock().unlock();
    for (KstScalarList::ConstIterator i = sl.begin(); i != sl.end(); ++i) {
      KstScalarPtr sp = *i;

      sp->writeLock();
      KstObject::UpdateType ut = sp->update(_updateCounter);
      sp->unlock();

      if (ut == KstObject::UPDATE) {
        U = KstObject::UPDATE;
      }

      if (_done) {
        return false;
      }
    }
  }

  if (U == KstObject::UPDATE) {
    qDebug() << "Update plots" << endl;
    if (gotData) { // FIXME: do we need to consider all the other exit points?
      *gotData = true;
    }
  }

#if UPDATEDEBUG > 1
  qDebug() << "6 Returning from scan with U=" << (int)U << endl;
#endif
  return U == KstObject::UPDATE;
}
Exemple #3
0
void KstObjectItem::update(bool recursive) {
  switch (_rtti) {
    case RTTI_OBJ_DATA_VECTOR:
      {
        KstVectorPtr px = *KST::vectorList.findTag(_name);
        assert(px.data());
        assert(dynamic_cast<KstRVector*>(px.data()));
        KstRVectorPtr x = static_cast<KstRVector*>(px.data());
        setText(2, QString::number(x->getUsage() - 3)); // caller has a ptr
        setText(3, QString::number(x->sampleCount()));
        setText(4, i18n("%3: %4 [%1..%2]").arg(x->reqStartFrame())
            .arg(x->reqStartFrame() + x->reqNumFrames())
            .arg(x->getFilename())
            .arg(x->getField()));
        _removable = x->getUsage() == 3;
        break;
      }
    case RTTI_OBJ_VECTOR:
      {
        KstVectorPtr x = *KST::vectorList.findTag(_name);
        assert(x.data());
        setText(2, QString::number(x->getUsage() - 2)); //caller also points
        setText(3, QString::number(x->sampleCount()));
        setText(4, i18n("[%1..%2]").arg(x->min()).arg(x->max()));
        _removable = false;
        break;
      }
    case RTTI_OBJ_OBJECT:
      {
        KstDataObjectPtr x = *KST::dataObjectList.findTag(_name);
        assert(x.data());
        setText(1, x->typeString());
        setText(2, QString::number(x->getUsage() - 1)); // our pointer
        setText(3, QString::number(x->sampleCount()));
        setText(4, x->propertyString());
        if (recursive) {
          QPtrStack<QListViewItem> trash;

          for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
            KstObjectItem *oi = static_cast<KstObjectItem*>(i);
            if (x->outputVectors().findTag(oi->tagName()) == x->outputVectors().end()) {
              trash.push(i);
            }
          }
          trash.setAutoDelete(true);
          trash.clear();

          for (KstVectorMap::Iterator p = x->outputVectors().begin();
              p != x->outputVectors().end();
              ++p) {
            bool found = false;
            for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
              KstObjectItem *oi = static_cast<KstObjectItem*>(i);
              if (oi->tagName() == p.data()->tagName()) {
                oi->update();
                found = true;
                break;
              }
            }
            if (!found) {
              new KstObjectItem(this, p.data(), _dm);
            }
          }
        }
        _removable = x->getUsage() == 1;
        break;
      }
    default:
      assert(0);
  }
}