From 08eb2ac19676933e354d518d814ed6cd96185577 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 29 Dec 2023 09:56:37 +0100 Subject: [PATCH] Work on eclipse epsilon --- experimental_epsilon/src/InstanceHandler.egl | 30 +-- experimental_epsilon/src/InstanceState.egl | 3 +- experimental_epsilon/src/Model.egl | 18 +- .../src/gen/IoArHandlerMainInstance.hxx | 191 ++++++++++++++++-- 4 files changed, 199 insertions(+), 43 deletions(-) diff --git a/experimental_epsilon/src/InstanceHandler.egl b/experimental_epsilon/src/InstanceHandler.egl index e25fe5f..0642dab 100644 --- a/experimental_epsilon/src/InstanceHandler.egl +++ b/experimental_epsilon/src/InstanceHandler.egl @@ -1,35 +1,19 @@ -[% - import "Operations.egl"; - - var transitionTemplate : Template = TemplateFactory.load("InstanceHandlerTransition.egl"); - - var all_events = new List(); - for (transition in state.outgoing) { - all_events.add(transition.trigger.first.event.name); - } - all_events = all_events.sortBy(e | e); // sort by event name -%] -[%=sm.name%]::Transition [%=sm.name%]::[%=state.name%]Handler(ImplPtr impl, Event event) +[%=statemachine.name%]::[%=statemachine.transition_type%] [%=statemachine.name%]::[%=state.name%]Handler(ImplPtr impl, Event event) { (void)impl; // impl parameter is unused when there is no guard function being called in here - switch([%=sm.name%]_GET_INSTANCE_EVENT_ID(event)) + switch([%=statemachine.name%]_GET_INSTANCE_EVENT_ID(event)) { [% - for (an_event in all_events) { + for (an_event in state.all_events) { %] - case [%=sm.name%]_GET_STATIC_EVENT_ID([%=an_event%]): + case [%=statemachine.name%]_GET_STATIC_EVENT_ID([%=an_event%]): [% - var all_transitions = state.getOutgoingTransitions().select(t | t.trigger.first.event.name == an_event); - for (transition in all_transitions) { - transitionTemplate.populate("start_transition", transition); - transitionTemplate.populate("transition", transition); - transitionTemplate.populate("state", state); - transitionTemplate.populate("sm", sm); + for (transition in state.all_event_transitions.get(an_event)) { %] -[%=transitionTemplate.process()%] +[%=transition.start%] -> [%=transition.target%] [% - } + } } %] default: diff --git a/experimental_epsilon/src/InstanceState.egl b/experimental_epsilon/src/InstanceState.egl index 986bb6e..3f80a86 100644 --- a/experimental_epsilon/src/InstanceState.egl +++ b/experimental_epsilon/src/InstanceState.egl @@ -26,8 +26,7 @@ const [%=statemachine.name%]::[%=statemachine.transition_type%] [%=statemachine. } %] -// HANDLER -[%/*=handlerTemplate.process()*/%] +[%=handlerTemplate.process()%] [% if (state.region.isDefined()) { var regionTemplate : Template = TemplateFactory.load("InstanceRegion.egl"); diff --git a/experimental_epsilon/src/Model.egl b/experimental_epsilon/src/Model.egl index edb2427..2c71fff 100644 --- a/experimental_epsilon/src/Model.egl +++ b/experimental_epsilon/src/Model.egl @@ -1,9 +1,4 @@ [% -// Statemachine: name: String, region: Region -// Region: states: List, initial: String, history: Boolean -// State: region?: Region, parent?: String, entry?: String, exit?: String, transitions: List -// Transition: actions: List, guards: List, start: String, target: String, trigger: String - // Parse model and transform it to model-independent Tuples (TODO: Use Emfatic) operation StateMachine getModel() : Tuple { @@ -143,6 +138,19 @@ operation Tuple transformState(statemachine : Tuple) { self.region.transformRegion(statemachine); self.initial_variable_pointer = "&" + self.region.initial_variable_name; } + + self.all_events = new List(); + for (transition in self.transitions) { + if (not self.all_events.includes(transition.trigger)) { + self.all_events.add(transition.trigger); + } + } + self.all_events = self.all_events.sortBy(e | e); + + self.all_event_transitions = new Map(); + for (event in self.all_events) { + self.all_event_transitions.put(event, self.transitions.select(t | t.trigger = event)); + } } operation Tuple transformTransition(statemachine : Tuple) { diff --git a/experimental_epsilon/src/gen/IoArHandlerMainInstance.hxx b/experimental_epsilon/src/gen/IoArHandlerMainInstance.hxx index 523ddee..42a67d9 100644 --- a/experimental_epsilon/src/gen/IoArHandlerMainInstance.hxx +++ b/experimental_epsilon/src/gen/IoArHandlerMainInstance.hxx @@ -27,7 +27,26 @@ const IoArHandlerMain::Transition IoArHandlerMain::kClosedToClosedByS_PNS_Switch const IoArHandlerMain::Transition IoArHandlerMain::kClosedToClosedByS_PNS_SwitchoverRequestPrimary(kClosed); const IoArHandlerMain::Transition IoArHandlerMain::kClosedToClosedByS_PNS_WriteReq(kClosed); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::ClosedHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_ArOpend_ind): + Closed -> Open + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_ReadReq): + Closed -> Closed + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_SwitchoverRequestBackup): + Closed -> Closed + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_SwitchoverRequestPrimary): + Closed -> Closed + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_WriteReq): + Closed -> Closed + default: + return UnhandledEvent(); + } +} // State Open const IoArHandlerMain::State IoArHandlerMain::kOpen("Open", @@ -50,7 +69,28 @@ const IoArHandlerMain::Transition IoArHandlerMain::kOpenToOpenByS_PNS_Switchover const IoArHandlerMain::Transition::Action IoArHandlerMain::kOpenToOpenByS_PNS_WriteReqActions[] = {&IoArHandlerMain::Impl::Write}; const IoArHandlerMain::Transition IoArHandlerMain::kOpenToOpenByS_PNS_WriteReq(kOpen, kOpenToOpenByS_PNS_WriteReqActions); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::OpenHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_ArClosed_ind): + Open -> Closed + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_CheckModuleDiff): + Open -> Open + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_ReadReq): + Open -> Open + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_SwitchoverRequestBackup): + Open -> Open + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_SwitchoverRequestPrimary): + Open -> Open + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_WriteReq): + Open -> Open + default: + return UnhandledEvent(); + } +} // State ApplicationReady const IoArHandlerMain::State IoArHandlerMain::kApplicationReady("ApplicationReady", @@ -61,7 +101,16 @@ nullptr, // Entry nullptr); // Exit -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::ApplicationReadyHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + default: + return UnhandledEvent(); + } +} // State DynamicReconfigurationRunning const IoArHandlerMain::State IoArHandlerMain::kDynamicReconfigurationRunning("DynamicReconfigurationRunning", @@ -74,7 +123,18 @@ const IoArHandlerMain::State IoArHandlerMain::kDynamicReconfigurationRunning("Dy const IoArHandlerMain::Transition::Action IoArHandlerMain::kDynamicReconfigurationRunningToDynamicReconfigurationRunningBySPnioAppTimeoutDynReconfActions[] = {&IoArHandlerMain::Impl::DynReconfTimeoutAbortArSet}; const IoArHandlerMain::Transition IoArHandlerMain::kDynamicReconfigurationRunningToDynamicReconfigurationRunningBySPnioAppTimeoutDynReconf(kDynamicReconfigurationRunning, kDynamicReconfigurationRunningToDynamicReconfigurationRunningBySPnioAppTimeoutDynReconfActions); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::DynamicReconfigurationRunningHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(SPnioAppTimeoutDynReconf): + DynamicReconfigurationRunning -> DynamicReconfigurationRunning + default: + return UnhandledEvent(); + } +} // State DrPlugPrmSequence const IoArHandlerMain::State IoArHandlerMain::kDrPlugPrmSequence("DrPlugPrmSequence", @@ -87,7 +147,18 @@ nullptr); // Exit const IoArHandlerMain::Transition::Action IoArHandlerMain::kDrPlugPrmSequenceToDrWaitApplicationReadyPlugSubmoduleByS_PNS_PlugParamEndIndActions[] = {&IoArHandlerMain::Impl::ApplyConfiguration}; const IoArHandlerMain::Transition IoArHandlerMain::kDrPlugPrmSequenceToDrWaitApplicationReadyPlugSubmoduleByS_PNS_PlugParamEndInd(kDrWaitApplicationReadyPlugSubmodule, kDrPlugPrmSequenceToDrWaitApplicationReadyPlugSubmoduleByS_PNS_PlugParamEndIndActions); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::DrPlugPrmSequenceHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_PlugParamEndInd): + DrPlugPrmSequence -> DrWaitApplicationReadyPlugSubmodule + default: + return UnhandledEvent(); + } +} // State DrWaitApplicationReadyCnfPlugSubmodule const IoArHandlerMain::State IoArHandlerMain::kDrWaitApplicationReadyCnfPlugSubmodule("DrWaitApplicationReadyCnfPlugSubmodule", @@ -100,7 +171,18 @@ nullptr); // Exit const IoArHandlerMain::Transition::Action IoArHandlerMain::kDrWaitApplicationReadyCnfPlugSubmoduleToReadyByS_PNS_PlugApplicationReady_cnfActions[] = {&IoArHandlerMain::Impl::DrPullDone}; const IoArHandlerMain::Transition IoArHandlerMain::kDrWaitApplicationReadyCnfPlugSubmoduleToReadyByS_PNS_PlugApplicationReady_cnf(kReady, kDrWaitApplicationReadyCnfPlugSubmoduleToReadyByS_PNS_PlugApplicationReady_cnfActions); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::DrWaitApplicationReadyCnfPlugSubmoduleHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_PlugApplicationReady_cnf): + DrWaitApplicationReadyCnfPlugSubmodule -> Ready + default: + return UnhandledEvent(); + } +} // State DrWaitApplicationReadyPlugSubmodule const IoArHandlerMain::State IoArHandlerMain::kDrWaitApplicationReadyPlugSubmodule("DrWaitApplicationReadyPlugSubmodule", @@ -113,7 +195,19 @@ nullptr, // Initial const IoArHandlerMain::Transition IoArHandlerMain::kDrWaitApplicationReadyPlugSubmoduleToDrWaitApplicationReadyCnfPlugSubmoduleBySPnpbAppTimeout(kDrWaitApplicationReadyCnfPlugSubmodule); const IoArHandlerMain::Transition IoArHandlerMain::kDrWaitApplicationReadyPlugSubmoduleToDrWaitApplicationReadyPlugSubmoduleBySPnpbAppTimeout(kDrWaitApplicationReadyPlugSubmodule); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::DrWaitApplicationReadyPlugSubmoduleHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(SPnpbAppTimeout): + DrWaitApplicationReadyPlugSubmodule -> DrWaitApplicationReadyCnfPlugSubmodule + DrWaitApplicationReadyPlugSubmodule -> DrWaitApplicationReadyPlugSubmodule + default: + return UnhandledEvent(); + } +} // State DrWaitPlugCnf const IoArHandlerMain::State IoArHandlerMain::kDrWaitPlugCnf("DrWaitPlugCnf", @@ -125,7 +219,18 @@ nullptr); // Exit const IoArHandlerMain::Transition IoArHandlerMain::kDrWaitPlugCnfToDrPlugPrmSequenceByS_PNS_PlugSubmodule_cnf(kDrPlugPrmSequence); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::DrWaitPlugCnfHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_PlugSubmodule_cnf): + DrWaitPlugCnf -> DrPlugPrmSequence + default: + return UnhandledEvent(); + } +} // State DrWaitPullCnf const IoArHandlerMain::State IoArHandlerMain::kDrWaitPullCnf("DrWaitPullCnf", @@ -138,7 +243,18 @@ nullptr); // Exit const IoArHandlerMain::Transition::Action IoArHandlerMain::kDrWaitPullCnfToReadyByS_PNS_PullSubmodule_cnfActions[] = {&IoArHandlerMain::Impl::DrPullDone}; const IoArHandlerMain::Transition IoArHandlerMain::kDrWaitPullCnfToReadyByS_PNS_PullSubmodule_cnf(kReady, kDrWaitPullCnfToReadyByS_PNS_PullSubmodule_cnfActions); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::DrWaitPullCnfHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_PullSubmodule_cnf): + DrWaitPullCnf -> Ready + default: + return UnhandledEvent(); + } +} // State Ready const IoArHandlerMain::State IoArHandlerMain::kReady("Ready", @@ -153,7 +269,20 @@ const IoArHandlerMain::Transition IoArHandlerMain::kReadyToDrWaitPlugCnfByS_PNS_ const IoArHandlerMain::Transition::Action IoArHandlerMain::kReadyToDrWaitPullCnfByS_PNS_DynReconfPullActions[] = {&IoArHandlerMain::Impl::DrPull}; const IoArHandlerMain::Transition IoArHandlerMain::kReadyToDrWaitPullCnfByS_PNS_DynReconfPull(kDrWaitPullCnf, kReadyToDrWaitPullCnfByS_PNS_DynReconfPullActions); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::ReadyHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_DynReconfPlug): + Ready -> DrWaitPlugCnf + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_DynReconfPull): + Ready -> DrWaitPullCnf + default: + return UnhandledEvent(); + } +} // State Parameterizing const IoArHandlerMain::State IoArHandlerMain::kParameterizing("Parameterizing", @@ -167,7 +296,19 @@ const IoArHandlerMain::Transition::Action IoArHandlerMain::kParameterizingToWait const IoArHandlerMain::Transition IoArHandlerMain::kParameterizingToWaitApplicationReadyByS_PNS_ParamEndInd(kWaitApplicationReady, kParameterizingToWaitApplicationReadyByS_PNS_ParamEndIndActions); const IoArHandlerMain::Transition IoArHandlerMain::kParameterizingToWaitApplicationReadyCnfByS_PNS_ParamEndInd(kWaitApplicationReadyCnf); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::ParameterizingHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_ParamEndInd): + Parameterizing -> WaitApplicationReady + Parameterizing -> WaitApplicationReadyCnf + default: + return UnhandledEvent(); + } +} // State WaitApplicationReady const IoArHandlerMain::State IoArHandlerMain::kWaitApplicationReady("WaitApplicationReady", @@ -180,7 +321,19 @@ nullptr, // Initial const IoArHandlerMain::Transition IoArHandlerMain::kWaitApplicationReadyToWaitApplicationReadyBySPnpbAppTimeout(kWaitApplicationReady); const IoArHandlerMain::Transition IoArHandlerMain::kWaitApplicationReadyToWaitApplicationReadyCnfBySPnpbAppTimeout(kWaitApplicationReadyCnf); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::WaitApplicationReadyHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(SPnpbAppTimeout): + WaitApplicationReady -> WaitApplicationReady + WaitApplicationReady -> WaitApplicationReadyCnf + default: + return UnhandledEvent(); + } +} // State WaitApplicationReadyCnf const IoArHandlerMain::State IoArHandlerMain::kWaitApplicationReadyCnf("WaitApplicationReadyCnf", @@ -194,4 +347,16 @@ const IoArHandlerMain::Transition IoArHandlerMain::kWaitApplicationReadyCnfToApp const IoArHandlerMain::Transition::Action IoArHandlerMain::kWaitApplicationReadyCnfToWaitApplicationReadyCnfByS_PNS_ApplicationReady_cnfActions[] = {&IoArHandlerMain::Impl::AbortAr}; const IoArHandlerMain::Transition IoArHandlerMain::kWaitApplicationReadyCnfToWaitApplicationReadyCnfByS_PNS_ApplicationReady_cnf(kWaitApplicationReadyCnf, kWaitApplicationReadyCnfToWaitApplicationReadyCnfByS_PNS_ApplicationReady_cnfActions); -// HANDLER +IoArHandlerMain::Transition IoArHandlerMain::WaitApplicationReadyCnfHandler(ImplPtr impl, Event event) +{ + (void)impl; // impl parameter is unused when there is no guard function being called in here + + switch(IoArHandlerMain_GET_INSTANCE_EVENT_ID(event)) + { + case IoArHandlerMain_GET_STATIC_EVENT_ID(S_PNS_ApplicationReady_cnf): + WaitApplicationReadyCnf -> ApplicationReady + WaitApplicationReadyCnf -> WaitApplicationReadyCnf + default: + return UnhandledEvent(); + } +}