BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
MyopicMessageTaskTerminator.cpp
Go to the documentation of this file.
4#include <cassert>
5
6using namespace BPMNOS::Execution;
7
11
21
22
23std::shared_ptr<Event> MyopicMessageTaskTerminator::dispatchEvent( [[maybe_unused]] const SystemState* systemState ) {
24 // determine whether there is another decision pending
25 if ( !otherDecisions.empty() ) {
26 return nullptr;
27 }
28
29 if ( !systemState->tokensAwaitingTimer.empty() ) {
30 return nullptr;
31 }
32
33 if ( !systemState->tokensAwaitingReadyEvent.empty() ) {
34 return nullptr;
35 }
36
37 if ( !systemState->tokensAwaitingCompletionEvent.empty() ) {
38 return nullptr;
39 }
40
41 // all tokens have moved as far as they can
42
43 // assume that no message can be delivered
44
45 for ( auto& [token_ptr, decision ] : messageDeliveryDecisions ) {
46 if( auto token = token_ptr.lock() ) {
47 assert( token );
48 // raise error at receive task
49 return std::make_shared<ErrorEvent>(token.get());
50 }
51 }
52
53 // no receive task is pending, raise error at remaining send tasks
54 for ( auto& [token,message_ptr] : systemState->messageAwaitingDelivery ) {
55 // raise error at send task
56 return std::make_shared<ErrorEvent>(token);
57 }
58
59 return nullptr;
60}
61
63 assert( dynamic_cast<const DecisionRequest*>(observable) );
64 auto request = static_cast<const DecisionRequest*>(observable);
65 assert( request->token->node );
67 request->token->node->represents<const BPMN::ReceiveTask>()
68 ) {
69 messageDeliveryDecisions.emplace_back(request->token->weak_from_this(), request->weak_from_this());
70 }
71 else {
72 otherDecisions.emplace_back(request->token->weak_from_this(), request->weak_from_this() );
73 }
74}
75
virtual void connect(Mediator *mediator)
std::shared_ptr< Event > dispatchEvent(const SystemState *systemState) override
void notice(const Observable *observable) override
void addSubscriber(Observer *subscriber, ObservableTypes... observableTypes)
Definition Notifier.h:16
A class representing the state that the execution or simulation of a given scenario is in.
Definition SystemState.h:21
Represents a pending decision.
Represents an abstract base class for a class that is an event listener and notifier.
Definition Mediator.h:13
virtual constexpr Type getObservableType() const =0