26 if ( token_ptr.has_value() && token_ptr->expired() ) {
31 if ( stateMachine_ptr.has_value() && stateMachine_ptr->expired() ) {
41 systemState = std::make_unique<SystemState>(
this, scenario);
75 auto command = std::move(
commands.front());
84 event->processBy(
this);
103 throw std::runtime_error(
"Engine: unexpected absence of event");
108 if ( !
process->isExecutable ) {
109 throw std::runtime_error(
"Engine: process '" +
process->id +
"' is not executable");
112 throw std::runtime_error(
"Engine: instance of process '" +
process->id +
"' has no id");
115 throw std::runtime_error(
"Engine: instance of process '" +
process->id +
"' has no timestamp");
120 systemState->instances.back()->run(std::move(status));
131 Token* token =
const_cast<Token*
>(
event->token);
133 systemState->tokensAwaitingReadyEvent.remove(token);
141 commands.emplace_back(std::bind(&Token::advanceToReady,token), token);
146 Token* token =
const_cast<Token*
>(
event->token);
150 token->occupySequentialPerformer();
155 token->
status =
event->entryStatus.value();
158 commands.emplace_back(std::bind(&Token::advanceToEntered,token), token);
163 Token* token =
const_cast<Token*
>(
event->token);
166 assert( token->
node );
170 assert( extensionElements );
171 assert( extensionElements->choices.size() == event->
choices.size() );
173 for (
size_t i = 0; i < extensionElements->choices.size(); i++) {
174 extensionElements->attributeRegistry.setValue( extensionElements->choices[i]->attribute, token->
status, *token->
data, token->
globals, event->
choices[i] );
177 commands.emplace_back(std::bind(&Token::advanceToCompleted,token), token);
182 Token* token =
const_cast<Token*
>(
event->token);
184 systemState->tokensAwaitingCompletionEvent.remove(token);
190 commands.emplace_back(std::bind(&Token::advanceToCompleted,token), token);
194 Token* token =
const_cast<Token*
>(
event->token);
197 assert( token->
node );
199 auto message_ptr =
event->message.lock();
200 assert( message_ptr );
216 commands.emplace_back(std::bind(&Token::advanceToCompleted,token), token);
221 Token* token =
const_cast<Token*
>(
event->token);
225 token->releaseSequentialPerformer();
230 token->
status =
event->exitStatus.value();
233 commands.emplace_back(std::bind(&Token::advanceToExiting,token), token);
237 Token* token =
const_cast<Token*
>(
event->token);
238 commands.emplace_back(std::bind(&Token::advanceToFailed,token), token);
245 while ( !
systemState->tokensAwaitingTimer.empty() ) {
246 auto it =
systemState->tokensAwaitingTimer.begin();
247 auto [time, token_ptr] = *it;
251 auto token = token_ptr.lock();
254 commands.emplace_back(std::bind(&Token::advanceToCompleted,token.get()), token.get());
255 systemState->tokensAwaitingTimer.remove(token.get());
260 throw std::runtime_error(
"Engine: TerminationEvent not yet implemented");
void process(const ReadyEvent *event)
void deleteInstance(StateMachine *instance)
Method removing completed instance.
BPMNOS::number clockTick
Timestep used to advance the current time by systemState.time += clockTick.
BPMNOS::number run(const BPMNOS::Model::Scenario *scenario, BPMNOS::number timeout=std::numeric_limits< BPMNOS::number >::max())
Runs a scenario as long as there is a token or new instantiations. Terminates when the time if the sy...
std::unique_ptr< ConditionalEventObserver > conditionalEventObserver
std::unique_ptr< SystemState > systemState
std::list< Command > commands
List of commands to be executed.
const SystemState * getSystemState()
Returns a pointer to the system state.
BPMNOS::number getCurrentTime()
Returns the timestamp the engine is in.
void addInstances()
Method adding all new instances and advancing tokens as much as possible.
std::shared_ptr< Event > fetchEvent(SystemState *systemState)
void apply(const BPMN::FlowNode *node, const BPMNOS::Model::AttributeRegistry &attributeRegistry, BPMNOS::Values &status, DataType &data, BPMNOS::Values &globals) const
Updates the status at a node based on the message content.
void notify(const Observable *observable) const
void addSubscriber(Observer *subscriber, ObservableTypes... observableTypes)
Represents a state machine for BPMN execution of a scope in the model.
A class representing the state that the execution or simulation of a given scenario is in.
Represents a token running through a (sub)process.
const BPMN::FlowNode * node
const BPMNOS::Model::AttributeRegistry & getAttributeRegistry() const
const StateMachine * owner
State machine owning the token.
SharedValues * data
Pointer to the data of the owner or owned state machine subprocesses)
std::shared_ptr< DecisionRequest > decisionRequest
const BPMN::SequenceFlow * sequenceFlow
Class representing a task in which one or more choices have to be made.
Class holding extension elements representing execution data for nodes.
The Scenario class holds data for all BPMN instances.
Class representing adhoc subprocesses with sequential ordering.
std::unique_ptr< ExtensionElements > extensionElements
Scope * parent
Reference to the parent node.
T * represents()
Attempts to cast the element to the specified type T.
Base class for BPMN elements that may contain a ChildNode elements.
void erase_ptr(std::vector< std::unique_ptr< T > > &container, const T *elementPtr)
Erase a specific element from a vector of unique pointers.
BPMNOS_NUMBER_TYPE number
Represents the event that choices are made for a DecisionTask.
Represents an event that increments the current time.
Class representing the event of a token having completed an activity.
std::optional< Values > updatedStatus
Represents the event of a token entering a node.
std::optional< Values > entryStatus
Represents the event of an error being raised.
Represents the event of a token exiting a node.
std::optional< Values > exitStatus
Represents the event of a message from the message pool being delivered.
Represents the event of a token ready to enter a node inclduing necressary new attribute data.
BPMNOS::Values statusAttributes
BPMNOS::Values dataAttributes
Represents an event causing the engine to terminate.
Represents the event that a timer is triggered.
static constexpr size_t Instance
static constexpr size_t Timestamp