mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
feat: Improve ChangeState
API
* Add `[[nodiscard]]` to `bool Device::ChangeState()` * Introduce throwing variant `void Device::ChangeStateOrThrow()` resolves #441
This commit is contained in:
committed by
Dennis Klein
parent
5ef17fddbb
commit
435d07eaf9
@@ -11,6 +11,7 @@
|
||||
|
||||
// FairMQ
|
||||
#include <fairmq/Channel.h>
|
||||
#include <fairmq/Error.h>
|
||||
#include <fairmq/Message.h>
|
||||
#include <fairmq/Parts.h>
|
||||
#include <fairmq/ProgOptions.h>
|
||||
@@ -498,21 +499,49 @@ class Device
|
||||
public:
|
||||
/// @brief Request a device state transition
|
||||
/// @param transition state transition
|
||||
/// @return whether the transition was successfully scheduled
|
||||
///
|
||||
/// The state transition may not happen immediately, but when the current state evaluates the
|
||||
/// pending transition event and terminates. In other words, the device states are scheduled
|
||||
/// cooperatively.
|
||||
bool ChangeState(const Transition transition) { return fStateMachine.ChangeState(transition); }
|
||||
[[nodiscard]] bool ChangeState(const Transition transition)
|
||||
{
|
||||
return fStateMachine.ChangeState(transition);
|
||||
}
|
||||
/// @brief Request a device state transition
|
||||
/// @param transition state transition
|
||||
/// @return whether the transition was successfully scheduled
|
||||
///
|
||||
/// The state transition may not happen immediately, but when the current state evaluates the
|
||||
/// pending transition event and terminates. In other words, the device states are scheduled
|
||||
/// cooperatively.
|
||||
bool ChangeState(const std::string& transition)
|
||||
[[nodiscard]] bool ChangeState(const std::string& transition)
|
||||
{
|
||||
return fStateMachine.ChangeState(GetTransition(transition));
|
||||
}
|
||||
/// @brief Request a device state transition
|
||||
/// @param transition state transition
|
||||
/// @throws when the transition could not have been scheduled
|
||||
///
|
||||
/// Throwing version of Device::ChangeState().
|
||||
void ChangeStateOrThrow(Transition transition)
|
||||
{
|
||||
if(!ChangeState(transition)) {
|
||||
auto const err = MakeErrorCode(ErrorCode::DeviceChangeStateFailed);
|
||||
throw std::system_error(err.value(),
|
||||
err.category(),
|
||||
tools::ToString("Invalid transition: ", transition));
|
||||
}
|
||||
}
|
||||
/// @brief Request a device state transition
|
||||
/// @param transition state transition
|
||||
/// @throws when the transition could not have been scheduled
|
||||
///
|
||||
/// Throwing version of Device::ChangeState().
|
||||
void ChangeStateOrThrow(std::string const& transition)
|
||||
{
|
||||
ChangeStateOrThrow(GetTransition(transition));
|
||||
}
|
||||
|
||||
/// @brief waits for the next state (any) to occur
|
||||
State WaitForNextState() { return fStateQueue.WaitForNext(); }
|
||||
|
Reference in New Issue
Block a user