diff --git a/AlgebraicDataflowArchitectureModel/models/SimpleUI.model b/AlgebraicDataflowArchitectureModel/models/SimpleUI.model index 6aedfa6..6d4cb43 100644 --- a/AlgebraicDataflowArchitectureModel/models/SimpleUI.model +++ b/AlgebraicDataflowArchitectureModel/models/SimpleUI.model @@ -1,10 +1,10 @@ init { screenTemplates := { - "000": {"widgets": {"001": {"type": "textInput", "text": "", "visible": true}, - "002": {"type": "button", "text": "Next", "visible": true}}, + "000": {"widgets": {"001": {"type": "textInput", "text": "", "state": 0, "visible": true}, + "002": {"type": "button", "text": "Next", "state": 0, "visible": true}}, "layout": true}, - "001": {"widgets": {"003": {"type": "label", "text": "label", "visible": true}, - "004": {"type": "button", "text": "Back", "visible": true}}, + "001": {"widgets": {"003": {"type": "label", "text": "label", "state": 0, "visible": true}, + "004": {"type": "button", "text": "Back", "state": 0, "visible": true}}, "layout": true} } } @@ -59,14 +59,20 @@ out screen(curS, transScreen(nextScId, screen)) = screen } -channel EventHandler1(wid: Str) { - in screen.widgets.{wid="002"}.state(curState: Int, handleEvent1(nextState)) = nextState - out curScreen(curScId: Str, handleEvent1(nextState)) = if((curScId == "000") && (nextState == 0), "001", curScId) +channel EventDispatch(wid: Str) { + in screen.widgets.{wid}.state(curState: Int, dispatchEvent(curScId, wid, nextState)) = nextState + ref curScreen(curScId: Str, dispatchEvent(curScId, wid, nextState)) + out screenTemplates.{curScId}.widgets.{wid}.state(curState: Int, dispatchEvent(curScId, wid, nextState)) = nextState } -channel EventHandler2(wid: Str) { - in screen.widgets.{wid="004"}.state(curState: Int, handleEvent2(nextState)) = nextState - out curScreen(curScId: Str, handleEvent2(nextState)) = if((curScId == "001") && (nextState == 0), "000", curScId) +channel EventHandler1(scId: Str, wid: Str) { + in screenTemplates.{scId="000"}.widgets.{wid="002"}.state(curState: Int, handleEvent1(nextState)) = nextState + out curScreen(curScId: Str, handleEvent1(nextState)) = if(nextState == 0, "001", curScId) +} + +channel EventHandler2(scId: Str, wid: Str) { + in screenTemplates.{scId="001"}.widgets.{wid="004"}.state(curState: Int, handleEvent2(nextState)) = nextState + out curScreen(curScId: Str, handleEvent2(nextState)) = if(nextState == 0, "000", curScId) } channel ChangeLayout { diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Channel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Channel.java index 4e71af2..af144c8 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Channel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Channel.java @@ -110,6 +110,9 @@ channelMember.setOutside(true); } } + if (isNative) { + channelMember.getResource().getResourceHierarchy().setNative(true); + } } public void removeChannelMember(ResourcePath res) { @@ -128,6 +131,17 @@ } return resources; } + + public boolean isNative() { + return isNative; + } + + public void setNative(boolean isNative) { + this.isNative = isNative; + for (ChannelMember member: channelMembers) { + member.getResource().getResourceHierarchy().setNative(isNative); + } + } public String toString() { return channelName; @@ -143,12 +157,4 @@ } return sourceText; } - - public boolean isNative() { - return isNative; - } - - public void setNative(boolean isNative) { - this.isNative = isNative; - } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourceHierarchy.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourceHierarchy.java index b8a6fe3..9ce7e94 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourceHierarchy.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourceHierarchy.java @@ -18,6 +18,7 @@ private int numParameters = 0; protected Expression initialValue; protected String initText; + protected boolean isNative = false; public ResourceHierarchy(String resourceName) { this.parent = null; @@ -211,6 +212,14 @@ public void setInitText(String initText) { this.initText = initText; } + + public boolean isNative() { + return isNative; + } + + public void setNative(boolean isNative) { + this.isNative = isNative; + } public String toString() { if (parent == null) return resourceName; diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java b/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java index 154a8a5..373fdfc 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java @@ -202,15 +202,22 @@ } List updatedOutResIds = nextSystemState.updateResourceState(outResId, outResVar[0], curResState, nextResState); if (updatedOutResIds != null) { - Set ancestors = new HashSet<>(); - for (ResourceIdentifier updatedOutResId: updatedOutResIds) { - while (updatedOutResId != null && !ancestors.contains(updatedOutResId)) { // In addition to the target state, its ancestors' states are also changed. - ancestors.add(updatedOutResId); - for (Event nextEvent: getNextEvents(updatedOutResId, curSystemState, nextSystemState)) { - fireEvent(nextEvent, curSystemState, nextSystemState); + if (out.getResource().getResourceHierarchy().isNative()) { + // For a native output resource, neither ancestor nor descendants are changed. + for (Event nextEvent: getNextEvents(outResId, curSystemState, nextSystemState)) { + fireEvent(nextEvent, curSystemState, nextSystemState); + } + } else { + // When a normal resource is updated. + Set ancestors = new HashSet<>(); + for (ResourceIdentifier updatedOutResId: updatedOutResIds) { + while (updatedOutResId != null && !ancestors.contains(updatedOutResId)) { // In addition to the target state, its ancestors' states are also changed. + ancestors.add(updatedOutResId); + for (Event nextEvent: getNextEvents(updatedOutResId, curSystemState, nextSystemState)) { + fireEvent(nextEvent, curSystemState, nextSystemState); + } + updatedOutResId = (ResourceIdentifier) updatedOutResId.getParent(); } - if (channel.isNative()) break; // To avoid multiple updates of the same resource. - updatedOutResId = (ResourceIdentifier) updatedOutResId.getParent(); } } }