30 if ( token_ptr.has_value() && token_ptr->expired() ) {
35 if ( stateMachine_ptr.has_value() && stateMachine_ptr->expired() ) {
47 systemState = std::make_unique<SystemState>(
this, scenario);
84 auto command = std::move(
commands.front());
93 event->processBy(
this);
112 throw std::runtime_error(
"Engine: unexpected absence of event");
117 if ( !
process->isExecutable ) {
118 throw std::runtime_error(
"Engine: process '" +
process->id +
"' is not executable");
121 throw std::runtime_error(
"Engine: instance of process '" +
process->id +
"' has no id");
124 throw std::runtime_error(
"Engine: instance of process '" +
process->id +
"' has no timestamp");
129 systemState->instances.back()->run(std::move(status));
140 Token* token =
const_cast<Token*
>(
event->token);
142 systemState->tokensAwaitingReadyEvent.remove(token);
150 commands.emplace_back(std::bind(&Token::advanceToReady,token), token);
155 Token* token =
const_cast<Token*
>(
event->token);
159 token->occupySequentialPerformer();
164 token->
status =
event->entryStatus.value();
167 commands.emplace_back(std::bind(&Token::advanceToEntered,token), token);
172 Token* token =
const_cast<Token*
>(
event->token);
175 assert( token->
node );
179 assert( extensionElements );
180 assert( extensionElements->choices.size() == event->
choices.size() );
182 for (
size_t i = 0; i < extensionElements->choices.size(); i++) {
183 extensionElements->attributeRegistry.setValue( extensionElements->choices[i]->attribute, token->
status, *token->
data, token->
globals, event->
choices[i] );
186 commands.emplace_back(std::bind(&Token::advanceToCompleted,token), token);
191 Token* token =
const_cast<Token*
>(
event->token);
192 systemState->tokensAwaitingCompletionEvent.remove(token);
196 commands.emplace_back(std::bind(&Token::advanceToCompleted,token), token);
200 Token* token =
const_cast<Token*
>(
event->token);
203 assert( token->
node );
205 auto message_ptr =
event->message.lock();
206 assert( message_ptr );
222 commands.emplace_back(std::bind(&Token::advanceToCompleted,token), token);
227 Token* token =
const_cast<Token*
>(
event->token);
231 token->releaseSequentialPerformer();
236 token->
status =
event->exitStatus.value();
239 commands.emplace_back(std::bind(&Token::advanceToExiting,token), token);
243 Token* token =
const_cast<Token*
>(
event->token);
244 commands.emplace_back(std::bind(&Token::advanceToFailed,token), token);
251 while ( !
systemState->tokensAwaitingTimer.empty() ) {
252 auto it =
systemState->tokensAwaitingTimer.begin();
253 auto [time, token_ptr] = *it;
257 auto token = token_ptr.lock();
260 commands.emplace_back(std::bind(&Token::advanceToCompleted,token.get()), token.get());
261 systemState->tokensAwaitingTimer.remove(token.get());
void connect(SystemState *systemState)
ReadyHandler readyHandler
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.
ConditionalEventObserver conditionalEventObserver
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< SystemState > systemState
TaskCompletionHandler taskCompletionHandler
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.
ScenarioUpdater scenarioUpdater
void subscribe(EventDispatcher *eventDispatcher)
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.
Abstract base class for scenarios holding 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.
std::vector< number > choices
Represents an event that increments the current time.
Class representing the event of a token having completed an activity.
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