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
23namespace BPMNOS::Execution {
24
25class Token;
26class StateMachine;
27//class Listener;
28class Controller;
29
30class Engine : public Mediator {
31 friend class Token;
32 friend class StateMachine;
34// friend void EventDispatcher::subscribe(Engine* engine);
35public:
36 Engine();
37 ~Engine();
38public:
39
40 /**
41 * @brief Runs a scenario as long as there is a token or new instantiations. Terminates when the time if the system exceeds the timeout.
42 */
43 BPMNOS::number run(const BPMNOS::Model::Scenario* scenario, BPMNOS::number timeout = std::numeric_limits<BPMNOS::number>::max());
44
45 void process(const ReadyEvent* event);
46 void process(const EntryEvent* event);
47 void process(const ChoiceEvent* event);
48 void process(const CompletionEvent* event);
49 void process(const MessageDeliveryEvent* event);
50 void process(const ExitEvent* event);
51 void process(const ErrorEvent* event);
52 void process([[maybe_unused]] const ClockTickEvent* event);
53 void process([[maybe_unused]] const TerminationEvent* event);
54
55/**
56 * @brief Returns the timestamp the engine is in.
57 */
59
60/**
61 * @brief Returns a pointer to the system state
62 */
64
65protected:
66
67 /**
68 * @brief Class storing a command to be executed by the engine
69 */
70 class Command {
71 public:
72 Command(std::function<void()>&& f )
73 : function(std::move(f)) {};
74
75 Command(std::function<void()>&& f, StateMachine* stateMachine )
76 : function(std::move(f))
77 , stateMachine_ptr(stateMachine->weak_from_this()) {};
78
79 Command(std::function<void()>&& f, Token* token )
80 : function(std::move(f))
81 , stateMachine_ptr(const_cast<StateMachine*>(token->owner)->weak_from_this())
82 , token_ptr(token->weak_from_this()) {};
83
84 void execute();
85 private:
86 std::function<void()> function;
87 std::optional< std::weak_ptr<StateMachine> > stateMachine_ptr; ///< Pointer to the state machine that the command refers to
88 std::optional< std::weak_ptr<Token> > token_ptr; ///< Pointer to the token that the command refers to
89 };
90
91 std::list<Command> commands; ///< List of commands to be executed
92
93 void addInstances(); ///< Method adding all new instances and advancing tokens as much as possible
94
95 void deleteInstance(StateMachine* instance); ///< Method removing completed instance
96
97 BPMNOS::number clockTick; ///< Timestep used to advance the current time by systemState.time += clockTick
98 std::unique_ptr<SystemState> systemState;
99 std::unique_ptr<ConditionalEventObserver> conditionalEventObserver;
100
101 bool advance();
102// friend void Token::notify() const;
103};
104
105} // namespace BPMNOS::Execution
106
107#endif // BPMNOS_Execution_Engine_H
Class storing a command to be executed by the engine.
Definition Engine.h:70
Command(std::function< void()> &&f, StateMachine *stateMachine)
Definition Engine.h:75
Command(std::function< void()> &&f, Token *token)
Definition Engine.h:79
Command(std::function< void()> &&f)
Definition Engine.h:72
void process(const ReadyEvent *event)
Definition Engine.cpp:129
void deleteInstance(StateMachine *instance)
Method removing completed instance.
Definition Engine.cpp:124
BPMNOS::number clockTick
Timestep used to advance the current time by systemState.time += clockTick.
Definition Engine.h:97
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:39
std::unique_ptr< ConditionalEventObserver > conditionalEventObserver
Definition Engine.h:99
std::unique_ptr< SystemState > systemState
Definition Engine.h:98
std::list< Command > commands
List of commands to be executed.
Definition Engine.h:91
const SystemState * getSystemState()
Returns a pointer to the system state.
Definition Engine.cpp:268
BPMNOS::number getCurrentTime()
Returns the timestamp the engine is in.
Definition Engine.cpp:264
void addInstances()
Method adding all new instances and advancing tokens as much as possible.
Definition Engine.cpp:106
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
Represents a token running through a (sub)process.
Definition Token.h:35
The Scenario class holds data for all BPMN instances.
Definition Scenario.h:20
BPMNOS_NUMBER_TYPE number
Definition Number.h:42
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.