BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
ScenarioUpdater.cpp
Go to the documentation of this file.
1#include "ScenarioUpdater.h"
9
10using namespace BPMNOS::Execution;
11
16
17void ScenarioUpdater::notice(const Observable* observable) {
18 // Handle ClockTick events - reveal deferred data
19 if (observable->getObservableType() == Observable::Type::Event) {
20 auto event = static_cast<const Event*>(observable);
21 if (auto clockTickEvent = event->is<ClockTickEvent>()) {
22 auto systemState = clockTickEvent->systemState;
23 auto currentTime = systemState->getTime();
24
25 if (auto dynamicScenario = dynamic_cast<const BPMNOS::Model::DynamicScenario*>(systemState->scenario)) {
26 dynamicScenario->revealData(currentTime);
27 }
28 else if (auto stochasticScenario = dynamic_cast<const BPMNOS::Model::StochasticScenario*>(systemState->scenario)) {
29 stochasticScenario->revealData(currentTime);
30 }
31 }
32 return;
33 }
34
35 // Handle Token state changes
36 if (observable->getObservableType() == Observable::Type::Token) {
37 auto token = static_cast<const Token*>(observable);
38
39 if (!token->node) {
40 return;
41 }
42
43 // Handle ARRIVED/CREATED at Activity - initialize arrival data
44 if (token->node->represents<BPMN::Activity>() &&
45 (token->state == Token::State::ARRIVED || token->state == Token::State::CREATED)) {
46 auto instanceId = token->getInstanceId();
47 Values data;
48 if (token->data) {
49 data = *token->data;
50 }
51 token->owner->systemState->scenario->initializeArrivalData(
52 instanceId, token->node, token->status, data, token->globals);
53 }
54
55 // Handle BUSY at Task - set task completion status
56 if (token->node->represents<BPMN::Task>() &&
57 token->state == Token::State::BUSY) {
58 // Exclude SendTask, ReceiveTask, DecisionTask
59 if (token->node->represents<BPMN::SendTask>() ||
60 token->node->represents<BPMN::ReceiveTask>() ||
62 return;
63 }
64
65 auto instanceId = token->getInstanceId();
66 token->owner->systemState->scenario->setTaskCompletionStatus(instanceId, token->node, token->status);
67 }
68 }
69}
void addSubscriber(Observer *subscriber, ObservableTypes... observableTypes)
Definition Notifier.h:17
void notice(const Observable *observable) override
Represents a token running through a (sub)process.
Definition Token.h:35
Class representing a task in which one or more choices have to be made.
T * represents()
Attempts to cast the element to the specified type T.
Definition bpmn++.h:16236
Represents an event that increments the current time.
virtual constexpr Type getObservableType() const =0