BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
Engine.h
Go to the documentation of this file.
1#ifndef BPMNOS_Execution_Engine_H
2#define BPMNOS_Execution_Engine_H
3
4#include <set>
5#include <vector>
6#include <list>
7#include "Event.h"
10#include "events/ErrorEvent.h"
11#include "events/ReadyEvent.h"
12#include "events/EntryEvent.h"
13#include "events/ChoiceEvent.h"
16#include "events/ExitEvent.h"
17//#include "Notifier.h"
18#include "Mediator.h"
19#include "EventDispatcher.h"
20#include "SystemState.h"
22#include "ScenarioUpdater.h"
23#include "ReadyHandler.h"
25
26namespace BPMNOS::Execution {
27
28class Token;
29class StateMachine;
30//class Listener;
31class Controller;
32
33class Engine : public Mediator {
34 friend class Token;
35 friend class StateMachine;
37// friend void EventDispatcher::subscribe(Engine* engine);
38public:
39 Engine();
40 ~Engine();
41public:
42
43 /**
44 * @brief Runs a scenario as long as there is a token or new instantiations. Terminates when the time if the system exceeds the timeout.
45 */
46 BPMNOS::number run(const BPMNOS::Model::Scenario* scenario, BPMNOS::number timeout = std::numeric_limits<BPMNOS::number>::max());
47
48 void process(const ReadyEvent* event);
49 void process(const EntryEvent* event);
50 void process(const ChoiceEvent* event);
51 void process(const CompletionEvent* event);
52 void process(const MessageDeliveryEvent* event);
53 void process(const ExitEvent* event);
54 void process(const ErrorEvent* event);
55 void process([[maybe_unused]] const ClockTickEvent* event);
56 void process([[maybe_unused]] const TerminationEvent* event);
57
58/**
59 * @brief Returns the timestamp the engine is in.
60 */
62
63/**
64 * @brief Returns a pointer to the system state
65 */
67
68protected:
69
70 /**
71 * @brief Class storing a command to be executed by the engine
72 */
73 class Command {
74 public:
75 Command(std::function<void()>&& f )
76 : function(std::move(f)) {};
77
78 Command(std::function<void()>&& f, StateMachine* stateMachine )
79 : function(std::move(f))
80 , stateMachine_ptr(stateMachine->weak_from_this()) {};
81
82 Command(std::function<void()>&& f, Token* token )
83 : function(std::move(f))
84 , stateMachine_ptr(const_cast<StateMachine*>(token->owner)->weak_from_this())
85 , token_ptr(token->weak_from_this()) {};
86
87 void execute();
88 private:
89 std::function<void()> function;
90 std::optional< std::weak_ptr<StateMachine> > stateMachine_ptr; ///< Pointer to the state machine that the command refers to
91 std::optional< std::weak_ptr<Token> > token_ptr; ///< Pointer to the token that the command refers to
92 };
93
94 std::list<Command> commands; ///< List of commands to be executed
95
96 void addInstances(); ///< Method adding all new instances and advancing tokens as much as possible
97
98 void deleteInstance(StateMachine* instance); ///< Method removing completed instance
99
100 BPMNOS::number clockTick; ///< Timestep used to advance the current time by systemState.time += clockTick
101 std::unique_ptr<SystemState> systemState;
106
107 bool advance();
109// friend void Token::notify() const;
110};
111
112} // namespace BPMNOS::Execution
113
114#endif // BPMNOS_Execution_Engine_H
Class storing a command to be executed by the engine.
Definition Engine.h:73
Command(std::function< void()> &&f, StateMachine *stateMachine)
Definition Engine.h:78
Command(std::function< void()> &&f, Token *token)
Definition Engine.h:82
Command(std::function< void()> &&f)
Definition Engine.h:75
ReadyHandler readyHandler
Definition Engine.h:104
void process(const ReadyEvent *event)
Definition Engine.cpp:138
void deleteInstance(StateMachine *instance)
Method removing completed instance.
Definition Engine.cpp:133
BPMNOS::number clockTick
Timestep used to advance the current time by systemState.time += clockTick.
Definition Engine.h:100
ConditionalEventObserver conditionalEventObserver
Definition Engine.h:102
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...
Definition Engine.cpp:43
std::unique_ptr< SystemState > systemState
Definition Engine.h:101
TaskCompletionHandler taskCompletionHandler
Definition Engine.h:105
std::list< Command > commands
List of commands to be executed.
Definition Engine.h:94
const SystemState * getSystemState()
Returns a pointer to the system state.
Definition Engine.cpp:274
BPMNOS::number getCurrentTime()
Returns the timestamp the engine is in.
Definition Engine.cpp:270
void addInstances()
Method adding all new instances and advancing tokens as much as possible.
Definition Engine.cpp:115
ScenarioUpdater scenarioUpdater
Definition Engine.h:103
Class dispatching a ready event when the required data is available for a token at an activity.
Observer that updates scenario state during execution.
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.
Definition SystemState.h:21
EventDispatcher for task completion events.
Represents a token running through a (sub)process.
Definition Token.h:35
Abstract base class for scenarios holding data for all BPMN instances.
Definition Scenario.h:21
BPMNOS_NUMBER_TYPE number
Definition Number.h:50
STL namespace.
Represents the event that choices are made for a DecisionTask.
Definition ChoiceEvent.h:15
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.
Definition EntryEvent.h:15
Represents the event of an error being raised.
Definition ErrorEvent.h:14
Represents the event of a token exiting a node.
Definition ExitEvent.h:15
Represents an abstract base class for a class that is an event listener and notifier.
Definition Mediator.h:13
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.
Definition ReadyEvent.h:15
Represents an event causing the engine to terminate.