コード例 #1
0
ファイル: PopSession.cpp プロジェクト: Garfonso/app-services
void PopSession::CancelCommands()
{
	// TODO: need to cancel actively running command first

	MojLogInfo(m_log, "%i command(s) to be canceling in queue",
			m_commandManager->GetPendingCommandCount());

	while (m_commandManager->GetPendingCommandCount() > 0) {
		CommandManager::CommandPtr command = m_commandManager->Top();
		m_commandManager->Pop();

		if (command.get()) {
			command->Cancel();

			if (m_syncSession.get() && m_syncSession->IsActive()) {
				m_syncSession->CommandCompleted(command.get());
			}
		}
	}

	// complete sync session
	if (m_syncSession.get() && (m_syncSession->IsActive() || m_syncSession->IsStarting())) {
		MojLogInfo(m_log, "Requesting to stop sync session");
		m_syncSession->RequestStop();
	}
}
コード例 #2
0
TEST(CommandManagerTest, TestFifo)
{
	MockListener listener;

	MojRefCountedPtr<CommandManager> managerRef(new CommandManager(1));
	CommandManager& manager = *managerRef;

	CommandManager::CommandPtr c1(new MockCommand(listener, Command::NormalPriority));
	CommandManager::CommandPtr c2(new MockCommand(listener, Command::NormalPriority));
	CommandManager::CommandPtr c3(new MockCommand(listener, Command::NormalPriority));

	manager.QueueCommand(c1, false);
	manager.QueueCommand(c2, false);
	manager.QueueCommand(c3, false);

	CommandManager::CommandPtr dequeued = manager.Top();
	ASSERT_EQ(c1.get(), dequeued.get());
	manager.Pop();

	dequeued = manager.Top();
	ASSERT_EQ(c2.get(), dequeued.get());
	manager.Pop();

	dequeued = manager.Top();
	ASSERT_EQ(c3.get(), dequeued.get());
	manager.Pop();
}