Beispiel #1
0
void Permutation::applyUpdate(ulong posOrig, long long shift, Permutation::Iterator *it) {
  bool bit = (*tree)[posOrig];
  ulong rank_block;
  ulong startRank = tree->rank(bit, posOrig);
  ulong endRank;


  if (shift == 0) return;

  if (it->getPosition() > 1) {
    rank_block = tree->rank(bit, it->getPosition()-1);
  } else
    rank_block = 0;
  startRank -= rank_block;

  if (shift < 0) {
    if (posOrig+shift-1 == 0)
      endRank = 1;
    else
      endRank = tree->rank(bit, posOrig+shift-1)-rank_block+1;
  } else
    endRank = tree->rank(bit, posOrig+shift)-rank_block;
  
//   cout << "Appel: bit="<<bit<<",startRank="<<startRank<<",endRank="<<endRank<<",posOrig="<<posOrig<<",dest="<<posOrig+shift<<",shift="<<shift<<endl;

  tree->deleteBit(posOrig);
  tree->insertBit(bit, posOrig+shift);

  if (bit)
    it->right();
  else
    it->left();

  applyUpdate(it->getPosition()+startRank-1, (long long)endRank-(long long)startRank, it);
}
void rBootHttpUpdate::onTimer() {
	
	if (TcpClient::isProcessing()) return; // Will wait
	
	if (TcpClient::getConnectionState() == eTCS_Successful) {
		
		if (!isSuccessful()) {
			updateFailed();
			return;
		}
		
		currentItem++;
		if (currentItem >= items.count()) {
			debugf("\r\nFirmware download finished!");
			for (int i = 0; i < items.count(); i++) {
				debugf(" - item: %d, addr: %X, len: %d bytes", i, items[i].targetOffset, items[i].size);
			}
			
			applyUpdate();
			return;
		}
		
	} else if (TcpClient::getConnectionState() == eTCS_Failed) {
		updateFailed();
		return;
	}
	
	rBootHttpUpdateItem &it = items[currentItem];
	debugf("Download file:\r\n    (%d) %s -> %X", currentItem, it.url.c_str(), it.targetOffset);
	rBootWriteStatus = rboot_write_init(items[currentItem].targetOffset);
	startDownload(URL(it.url), eHCM_UserDefined, NULL);
}
Beispiel #3
0
void PodcastService::loadAll()
{
    QString dir=Utils::dataDir(MusicLibraryItemPodcast::constDir);

    if (!dir.isEmpty()) {
        QDir d(dir);
        QStringList entries=d.entryList(QStringList() << "*"+MusicLibraryItemPodcast::constExt, QDir::Files|QDir::Readable|QDir::NoDot|QDir::NoDotDot);
        foreach (const QString &e, entries) {
            if (!update) {
                update=new OnlineServiceMusicRoot();
            }

            MusicLibraryItemPodcast *podcast=new MusicLibraryItemPodcast(dir+e, update);
            if (podcast->load()) {
                update->append(podcast);
            } else {
                delete podcast;
            }
        }

        if (update) {
            if (update->childItems().isEmpty()) {
                delete update;
            } else {
                applyUpdate();
            }
        }
        startRssUpdateTimer();
    }
Beispiel #4
0
Updater::Updater( QWidget *parent ) :
    QDialog( parent ),
    net( this ),
    busy( false )
{
    setWindowTitle( tr( "Aktualizacje programu QMPlay2" ) );
    infoFile.setFileName( QDir::tempPath() + "/QMPlay2_download_info." + QString::number( qrand() ) );
    updateFile.setFileName( QMPlay2Core.getSettingsDir() + "QMPlay2Installer" );
#ifdef Q_OS_WIN
    updateFile.setFileName( updateFile.fileName() + ".exe" );
#endif

    infoL = new QLabel( windowTitle() );
    progressB = new QProgressBar;
    downloadUpdateB = new QPushButton( tr( "Pobierz aktualizacje" ) );
    installB = new QPushButton( tr( "Zastosuj aktualizację" ) );
    connect( downloadUpdateB, SIGNAL( clicked() ), this, SLOT( downloadUpdate() ) );
    connect( installB, SIGNAL( clicked() ), this, SLOT( applyUpdate() ) );

    QVBoxLayout *layout = new QVBoxLayout( this );
    layout->setMargin( 2 );
    layout->addWidget( infoL );
    layout->addWidget( downloadUpdateB );
    layout->addWidget( progressB );
    layout->addWidget( installB );

    progressB->hide();
    installB->hide();

    resize( 350, 0 );
}
Beispiel #5
0
  /**
   * Let k such that pi(k)=i. At the end,  pi(k)=j. Additionally, pi is still 
   * a permutation, that is each value from 1 to getSize() appears only once.
   * @return 0 if OK.
   */
  int Permutation::update(ulong i, ulong j) { 
    if (i == j)
      return 0;

    Permutation::Iterator *it = new Iterator(this);
    long long shift = j;
    shift -= i;
    applyUpdate(i,shift,it);
    
    return 0; 
  }
Beispiel #6
0
int applyInstruction(const Instruction* instr, sqlite3* db)
{
	switch(instr->iType) {
	case SQLITE_INSERT:
		return applyInsert(db, instr);
	case SQLITE_UPDATE:
		return applyUpdate(db, instr);
	case SQLITE_DELETE:
		return applyDelete(db, instr);
	default:
		return CHANGESET_CORRUPT;
	}
}
Beispiel #7
0
void DrawableEffect::update(const sf::Time& elapsed_time)
{
  sf::Int32 elapsed_ms;

  if(!_infinite)
  {
    elapsed_ms = ((elapsed_time > _duration) ? _duration : elapsed_time).asMilliseconds();
    _duration -= elapsed_time;
  }
  else
    elapsed_ms = elapsed_time.asMilliseconds();

  applyUpdate(elapsed_ms);
}
UpdateDialog::UpdateDialog(SettingsModel *settings, QWidget *parent)
    :
    QDialog(parent),
    ui(new Ui::UpdateDialog),
    m_thread(NULL),
    m_settings(settings),
    m_logFile(new QStringList()),
    m_betaUpdates(settings ? (settings->autoUpdateCheckBeta() || lamexp_version_demo()) : lamexp_version_demo()),
    m_success(false),
    m_firstShow(true),
    m_updateReadyToInstall(false),
    m_updaterProcess(NULL),
    m_binaryUpdater(lamexp_lookup_tool("wupdate.exe")),
    m_binaryWGet(lamexp_lookup_tool("wget.exe")),
    m_binaryGnuPG(lamexp_lookup_tool("gpgv.exe")),
    m_binaryKeys(lamexp_lookup_tool("gpgv.gpg"))
{
    if(m_binaryUpdater.isEmpty())
    {
        THROW("Tools not initialized correctly!");
    }

    //Init the dialog, from the .ui file
    ui->setupUi(this);
    setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);

    //Disable "X" button
    lamexp_enable_close_button(this, false);

    //Init animation
    m_animator = new QMovie(":/images/Loading3.gif");
    ui->labelAnimationCenter->setMovie(m_animator);
    m_animator->start();

    //Indicate beta updates
    if(m_betaUpdates)
    {
        setWindowTitle(windowTitle().append(" [Beta]"));
    }

    //Enable button
    connect(ui->retryButton, SIGNAL(clicked()), this, SLOT(checkForUpdates()));
    connect(ui->installButton, SIGNAL(clicked()), this, SLOT(applyUpdate()));
    connect(ui->infoLabel, SIGNAL(linkActivated(QString)), this, SLOT(linkActivated(QString)));
    connect(ui->logButton, SIGNAL(clicked()), this, SLOT(logButtonClicked()));

    //Enable progress bar
    connect(ui->progressBar, SIGNAL(valueChanged(int)), this, SLOT(progressBarValueChanged(int)));
}
void HttpFirmwareUpdate::onTimer()
{
	if (HttpClient::isProcessing()) return; // Will wait

	if (TcpClient::getConnectionState() == eTCS_Successful)
	{
		if (!isSuccessful())
		{
			updateFailed();
			return;
		}

		items[currentItem].size = pos - items[currentItem].flash;
		currentItem++;
		if (currentItem >= items.count())
		{
			debugf("\r\nFirmware download finished!");
			for (int i = 0; i < items.count(); i++)
				debugf("\t item: 0x%X 0x%X %d bytes", items[i].targetOffset, items[i].flash - INTERNAL_FLASH_START_ADDRESS, items[i].size);

			applyUpdate();
			return;
		}
		HttpFirmwareUpdateItem &prev = items[currentItem - 1];
		HttpFirmwareUpdateItem &cur = items[currentItem];
		int jmp = cur.targetOffset - prev.targetOffset - prev.size;
		pos += jmp;
		debugf("jump: %d", jmp);
	}
	else if (TcpClient::getConnectionState() == eTCS_Failed)
	{
		updateFailed();
		return;
	}

	HttpFirmwareUpdateItem &it = items[currentItem];
//	uint32_t sect = flashmem_get_sector_of_address(pos);
//	sect++;
//	pos = INTERNAL_FLASH_START_ADDRESS + sect * INTERNAL_FLASH_SECTOR_SIZE;
	it.flash = pos;
	debugf("Download file:\r\n    (%d) %s -> 0x%X", currentItem, it.url.c_str(), it.targetOffset);
	startDownload(URL(it.url), eHCM_UserDefined, NULL);
}
rpl::producer<UserPhotosSlice> UserPhotosViewer(
		UserPhotosSlice::Key key,
		int limitBefore,
		int limitAfter) {
	return [key, limitBefore, limitAfter](auto consumer) {
		auto lifetime = rpl::lifetime();
		auto builder = lifetime.make_state<UserPhotosSliceBuilder>(
			key,
			limitBefore,
			limitAfter);
		auto applyUpdate = [=](auto &&update) {
			if (builder->applyUpdate(std::forward<decltype(update)>(update))) {
				consumer.put_next(builder->snapshot());
			}
		};
		auto requestPhotosAround = [user = Auth().data().user(key.userId)](
				PhotoId photoId) {
			Auth().api().requestUserPhotos(user, photoId);
		};
		builder->insufficientPhotosAround()
			| rpl::start_with_next(requestPhotosAround, lifetime);

		Auth().storage().userPhotosSliceUpdated()
			| rpl::start_with_next(applyUpdate, lifetime);

		Auth().storage().query(Storage::UserPhotosQuery(
			key,
			limitBefore,
			limitAfter
		)) | rpl::start_with_next_done(
			applyUpdate,
			[=] { builder->checkInsufficientPhotos(); },
			lifetime);

		return lifetime;
	};
}
rpl::producer<SparseIdsSlice> SharedMediaViewer(
		Storage::SharedMediaKey key,
		int limitBefore,
		int limitAfter) {
	Expects(IsServerMsgId(key.messageId) || (key.messageId == 0));
	Expects((key.messageId != 0) || (limitBefore == 0 && limitAfter == 0));

	return [=](auto consumer) {
		auto lifetime = rpl::lifetime();
		auto builder = lifetime.make_state<SparseIdsSliceBuilder>(
			key.messageId,
			limitBefore,
			limitAfter);
		auto requestMediaAround = [
			peer = App::peer(key.peerId),
			type = key.type
		](const SparseIdsSliceBuilder::AroundData &data) {
			Auth().api().requestSharedMedia(
				peer,
				type,
				data.aroundId,
				data.direction);
		};
		builder->insufficientAround(
		) | rpl::start_with_next(requestMediaAround, lifetime);

		auto pushNextSnapshot = [=] {
			consumer.put_next(builder->snapshot());
		};

		using SliceUpdate = Storage::SharedMediaSliceUpdate;
		Auth().storage().sharedMediaSliceUpdated(
		) | rpl::filter([=](const SliceUpdate &update) {
			return (update.peerId == key.peerId)
				&& (update.type == key.type);
		}) | rpl::filter([=](const SliceUpdate &update) {
			return builder->applyUpdate(update.data);
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		using OneRemoved = Storage::SharedMediaRemoveOne;
		Auth().storage().sharedMediaOneRemoved(
		) | rpl::filter([=](const OneRemoved &update) {
			return (update.peerId == key.peerId)
				&& update.types.test(key.type);
		}) | rpl::filter([=](const OneRemoved &update) {
			return builder->removeOne(update.messageId);
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		using AllRemoved = Storage::SharedMediaRemoveAll;
		Auth().storage().sharedMediaAllRemoved(
		) | rpl::filter([=](const AllRemoved &update) {
			return (update.peerId == key.peerId);
		}) | rpl::filter([=] {
			return builder->removeAll();
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		using InvalidateBottom = Storage::SharedMediaInvalidateBottom;
		Auth().storage().sharedMediaBottomInvalidated(
		) | rpl::filter([=](const InvalidateBottom &update) {
			return (update.peerId == key.peerId);
		}) | rpl::filter([=] {
			return builder->invalidateBottom();
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		using Result = Storage::SharedMediaResult;
		Auth().storage().query(Storage::SharedMediaQuery(
			key,
			limitBefore,
			limitAfter
		)) | rpl::filter([=](const Result &result) {
			return builder->applyInitial(result);
		}) | rpl::start_with_next_done(
			pushNextSnapshot,
			[=] { builder->checkInsufficient(); },
			lifetime);

		return lifetime;
	};
}
Beispiel #12
0
    bool WriteBatchExecutor::applyWriteItem(const string& ns,
                                            const WriteBatch::WriteItem& writeItem,
                                            BSONObjBuilder* results) {
        // Clear operation's LastError before starting.
        _le->reset(true);

        uint64_t itemTimeMicros = 0;
        bool opSuccess = true;

        // Each write operation executes in its own PageFaultRetryableSection.  This means that
        // a single batch can throw multiple PageFaultException's, which is not the case for
        // other operations.
        PageFaultRetryableSection s;
        while (true) {
            try {
                // Execute the write item as a child operation of the current operation.
                CurOp childOp(_client, _client->curop());

                // TODO Modify CurOp "wrapped" constructor to take an opcode, so calling .reset()
                // is unneeded
                childOp.reset(_client->getRemote(), getOpCode(writeItem.getWriteType()));

                childOp.ensureStarted();
                OpDebug& opDebug = childOp.debug();
                opDebug.ns = ns;
                {
                    Client::WriteContext ctx(ns);

                    switch(writeItem.getWriteType()) {
                    case WriteBatch::WRITE_INSERT:
                        opSuccess = applyInsert(ns, writeItem, &childOp);
                        break;
                    case WriteBatch::WRITE_UPDATE:
                        opSuccess = applyUpdate(ns, writeItem, &childOp);
                        break;
                    case WriteBatch::WRITE_DELETE:
                        opSuccess = applyDelete(ns, writeItem, &childOp);
                        break;
                    }
                }
                childOp.done();
                itemTimeMicros = childOp.totalTimeMicros();

                opDebug.executionTime = childOp.totalTimeMillis();
                opDebug.recordStats();

                // Log operation if running with at least "-v", or if exceeds slow threshold.
                if (logger::globalLogDomain()->shouldLog(logger::LogSeverity::Debug(1))
                    || opDebug.executionTime > cmdLine.slowMS + childOp.getExpectedLatencyMs()) {

                    MONGO_TLOG(1) << opDebug.report(childOp) << endl;
                }

                // TODO Log operation if logLevel >= 3 and assertion thrown (as assembleResponse()
                // does).

                // Save operation to system.profile if shouldDBProfile().
                if (childOp.shouldDBProfile(opDebug.executionTime)) {
                    profile(*_client, getOpCode(writeItem.getWriteType()), childOp);
                }
                break;
            }
            catch (PageFaultException& e) {
                e.touch();
            }
        }

        // Fill caller's builder with results of operation, using LastError.
        results->append("ok", opSuccess);
        _le->appendSelf(*results, false);
        results->append("micros", static_cast<long long>(itemTimeMicros));

        return opSuccess;
    }
rpl::producer<SparseIdsSlice> SearchController::simpleIdsSlice(
		PeerId peerId,
		MsgId aroundId,
		const Query &query,
		int limitBefore,
		int limitAfter) {
	Expects(peerId != 0);
	Expects(IsServerMsgId(aroundId) || (aroundId == 0));
	Expects((aroundId != 0)
		|| (limitBefore == 0 && limitAfter == 0));
	Expects((query.peerId == peerId)
		|| (query.migratedPeerId == peerId));

	auto it = _cache.find(query);
	if (it == _cache.end()) {
		return [=](auto) { return rpl::lifetime(); };
	}

	auto listData = (peerId == query.peerId)
		? &it->second->peerData
		: &*it->second->migratedData;
	return [=](auto consumer) {
		auto lifetime = rpl::lifetime();
		auto builder = lifetime.make_state<SparseIdsSliceBuilder>(
			aroundId,
			limitBefore,
			limitAfter);
		builder->insufficientAround(
		) | rpl::start_with_next([=](
				const SparseIdsSliceBuilder::AroundData &data) {
			requestMore(data, query, listData);
		}, lifetime);

		auto pushNextSnapshot = [=] {
			consumer.put_next(builder->snapshot());
		};

		listData->list.sliceUpdated(
		) | rpl::filter([=](const SliceUpdate &update) {
			return builder->applyUpdate(update);
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		Auth().data().itemRemoved(
		) | rpl::filter([=](not_null<const HistoryItem*> item) {
			return (item->history()->peer->id == peerId);
		}) | rpl::filter([=](not_null<const HistoryItem*> item) {
			return builder->removeOne(item->id);
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		Auth().data().historyCleared(
		) | rpl::filter([=](not_null<const History*> history) {
			return (history->peer->id == peerId);
		}) | rpl::filter([=] {
			return builder->removeAll();
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		using Result = Storage::SparseIdsListResult;
		listData->list.query(Storage::SparseIdsListQuery(
			aroundId,
			limitBefore,
			limitAfter
		)) | rpl::filter([=](const Result &result) {
			return builder->applyInitial(result);
		}) | rpl::start_with_next_done(
			pushNextSnapshot,
			[=] { builder->checkInsufficient(); },
			lifetime);

		return lifetime;
	};
}
Beispiel #14
0
	void UniformObject::update(HdlProgram& prgm)
	{
		applyUpdate(prgm);
		hasBeenUpdated = false;
	}