[commands] Fix compose-while-scheduled issue and test all compositions (#5581)

This commit is contained in:
Ryan Blue
2023-12-23 15:12:13 -05:00
committed by GitHub
parent aeb1a4aa33
commit ef1cb3f41e
20 changed files with 146 additions and 83 deletions

View File

@@ -374,7 +374,7 @@ class CommandScheduler final : public wpi::Sendable,
void OnCommandFinish(Action action);
/**
* Requires that the specified command hasn't been already added to a
* Requires that the specified command hasn't already been added to a
* composition.
*
* @param command The command to check
@@ -383,7 +383,7 @@ class CommandScheduler final : public wpi::Sendable,
void RequireUngrouped(const Command* command);
/**
* Requires that the specified commands not have been already added to a
* Requires that the specified commands have not already been added to a
* composition.
*
* @param commands The commands to check
@@ -392,7 +392,7 @@ class CommandScheduler final : public wpi::Sendable,
void RequireUngrouped(std::span<const std::unique_ptr<Command>> commands);
/**
* Requires that the specified commands not have been already added to a
* Requires that the specified commands have not already been added to a
* composition.
*
* @param commands The commands to check
@@ -401,6 +401,38 @@ class CommandScheduler final : public wpi::Sendable,
*/
void RequireUngrouped(std::initializer_list<const Command*> commands);
/**
* Requires that the specified command has not already been added to a
* composition and is not currently scheduled.
*
* @param command The command to check
* @throws IllegalArgumentException if the given command has already been
* composed or scheduled.
*/
void RequireUngroupedAndUnscheduled(const Command* command);
/**
* Requires that the specified commands have not already been added to a
* composition and are not currently scheduled.
*
* @param commands The commands to check
* @throws IllegalArgumentException if the given commands have already been
* composed.
*/
void RequireUngroupedAndUnscheduled(
std::span<const std::unique_ptr<Command>> commands);
/**
* Requires that the specified commands have not already been added to a
* composition and are not currently scheduled.
*
* @param commands The commands to check
* @throws IllegalArgumentException if the given commands have already been
* composed or scheduled.
*/
void RequireUngroupedAndUnscheduled(
std::initializer_list<const Command*> commands);
void InitSendable(wpi::SendableBuilder& builder) override;
private:

View File

@@ -56,7 +56,8 @@ class SelectCommand : public CommandHelper<Command, SelectCommand<Key>> {
m_defaultCommand.SetComposed(true);
for (auto&& command : foo) {
CommandScheduler::GetInstance().RequireUngrouped(command.second.get());
CommandScheduler::GetInstance().RequireUngroupedAndUnscheduled(
command.second.get());
command.second.get()->SetComposed(true);
}
@@ -77,7 +78,8 @@ class SelectCommand : public CommandHelper<Command, SelectCommand<Key>> {
: m_selector{std::move(selector)} {
m_defaultCommand.SetComposed(true);
for (auto&& command : commands) {
CommandScheduler::GetInstance().RequireUngrouped(command.second.get());
CommandScheduler::GetInstance().RequireUngroupedAndUnscheduled(
command.second.get());
command.second.get()->SetComposed(true);
}