Selaa lähdekoodia

Broken version for Simon

Yentl Van Tendeloo 9 vuotta sitten
vanhempi
commit
e523e75c06

+ 3 - 0
hybrid_server/minimal_broken/runner.py

@@ -0,0 +1,3 @@
+import server
+controller = server.Controller()
+controller.start()

+ 183 - 0
hybrid_server/minimal_broken/server.py

@@ -0,0 +1,183 @@
+"""
+Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
+
+Date:   Fri Aug  5 15:59:05 2016
+
+Model author: Yentl Van Tendeloo
+Model name:   broken
+Model description:
+Broken!
+"""
+
+from sccd.runtime.statecharts_core import *
+
+# package "broken"
+
+class A(RuntimeClassBase):
+    def __init__(self, controller):
+        RuntimeClassBase.__init__(self, controller)
+        
+        self.semantics.big_step_maximality = StatechartSemantics.TakeMany
+        self.semantics.internal_event_lifeline = StatechartSemantics.Queue
+        self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
+        self.semantics.priority = StatechartSemantics.SourceParent
+        self.semantics.concurrency = StatechartSemantics.Single
+        
+        # build Statechart structure
+        self.build_statechart_structure()
+        
+        # call user defined constructor
+        A.user_defined_constructor(self)
+    
+    def user_defined_constructor(self):
+        pass
+    
+    def user_defined_destructor(self):
+        pass
+    
+    
+    # builds Statechart structure
+    def build_statechart_structure(self):
+        
+        # state <root>
+        self.states[""] = State(0, self)
+        
+        # state /x
+        self.states["/x"] = State(1, self)
+        self.states["/x"].setEnter(self._x_enter)
+        
+        # state /ready
+        self.states["/ready"] = State(2, self)
+        self.states["/ready"].setEnter(self._ready_enter)
+        
+        # state /done
+        self.states["/done"] = State(3, self)
+        
+        # add children
+        self.states[""].addChild(self.states["/x"])
+        self.states[""].addChild(self.states["/ready"])
+        self.states[""].addChild(self.states["/done"])
+        self.states[""].fixTree()
+        self.states[""].default_state = self.states["/x"]
+        
+        # transition /x
+        _x_0 = Transition(self, self.states["/x"], [self.states["/ready"]])
+        _x_0.setAction(self._x_0_exec)
+        _x_0.trigger = Event("instance_created", None)
+        self.states["/x"].addTransition(_x_0)
+        
+        # transition /ready
+        _ready_0 = Transition(self, self.states["/ready"], [self.states["/done"]])
+        _ready_0.setAction(self._ready_0_exec)
+        _ready_0.trigger = Event("close", None)
+        self.states["/ready"].addTransition(_ready_0)
+    
+    def _x_enter(self):
+        self.big_step.outputEventOM(Event("create_instance", None, [self, 'child', 'B']))
+    
+    def _ready_enter(self):
+        self.big_step.outputEventOM(Event("start_instance", None, [self, self.instancename]))
+    
+    def _x_0_exec(self, parameters):
+        instancename = parameters[0]
+        self.instancename = instancename
+        print(self.instancename)
+    
+    def _ready_0_exec(self, parameters):
+        print("CLOSED")
+        self.big_step.outputEventOM(Event("delete_instance", None, [self, self.instancename]))
+    
+    def initializeStatechart(self):
+        # enter default state
+        states = self.states["/x"].getEffectiveTargetStates()
+        self.updateConfiguration(states)
+        for state in states:
+            if state.enter:
+                state.enter()
+
+class B(RuntimeClassBase):
+    def __init__(self, controller):
+        RuntimeClassBase.__init__(self, controller)
+        
+        self.semantics.big_step_maximality = StatechartSemantics.TakeMany
+        self.semantics.internal_event_lifeline = StatechartSemantics.Queue
+        self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
+        self.semantics.priority = StatechartSemantics.SourceParent
+        self.semantics.concurrency = StatechartSemantics.Single
+        
+        # build Statechart structure
+        self.build_statechart_structure()
+        
+        # call user defined constructor
+        B.user_defined_constructor(self)
+    
+    def user_defined_constructor(self):
+        print("READY")
+    
+    def user_defined_destructor(self):
+        pass
+    
+    
+    # builds Statechart structure
+    def build_statechart_structure(self):
+        
+        # state <root>
+        self.states[""] = State(0, self)
+        
+        # state /z
+        self.states["/z"] = State(1, self)
+        self.states["/z"].setEnter(self._z_enter)
+        self.states["/z"].setExit(self._z_exit)
+        
+        # add children
+        self.states[""].addChild(self.states["/z"])
+        self.states[""].fixTree()
+        self.states[""].default_state = self.states["/z"]
+        
+        # transition /z
+        _z_0 = Transition(self, self.states["/z"], [self.states["/z"]])
+        _z_0.setAction(self._z_0_exec)
+        _z_0.trigger = Event("_0after")
+        self.states["/z"].addTransition(_z_0)
+    
+    def _z_enter(self):
+        self.addTimer(0, 0)
+        print("RUN")
+    
+    def _z_exit(self):
+        self.removeTimer(0)
+    
+    def _z_0_exec(self, parameters):
+        print("RAISE")
+        self.big_step.outputEventOM(Event("broad_cast", None, [Event("close", None, [])]))
+    
+    def initializeStatechart(self):
+        # enter default state
+        states = self.states["/z"].getEffectiveTargetStates()
+        self.updateConfiguration(states)
+        for state in states:
+            if state.enter:
+                state.enter()
+
+class ObjectManager(ObjectManagerBase):
+    def __init__(self, controller):
+        ObjectManagerBase.__init__(self, controller)
+    
+    def instantiate(self, class_name, construct_params):
+        if class_name == "A":
+            instance = A(self.controller)
+            instance.associations = {}
+            instance.associations["child"] = Association("B", 0, 1)
+        elif class_name == "B":
+            instance = B(self.controller)
+            instance.associations = {}
+            instance.associations["parent"] = Association("A", 1, 1)
+        else:
+            raise Exception("Cannot instantiate class " + class_name)
+        return instance
+
+class Controller(ThreadsControllerBase):
+    def __init__(self, keep_running = None):
+        if keep_running == None: keep_running = True
+        ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running)
+        self.object_manager.createInstance("A", [])

+ 79 - 0
hybrid_server/minimal_broken/server.xml

@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<diagram author="Yentl Van Tendeloo" name="broken">
+    <description>
+        Broken!
+    </description>
+
+    <class name="A" default="true">
+        <relationships>
+            <association name="child" class="B" min="0" max="1"/>
+        </relationships>
+
+        <scxml initial="x">
+            <state id="x">
+                <onentry>
+                    <raise scope="cd" event="create_instance">
+                        <parameter expr="'child'"/>
+                        <parameter expr="'B'"/>
+                    </raise>
+                </onentry>
+
+                <transition event="instance_created" target="../ready">
+                    <parameter name="instancename"/>
+                    <script>
+                        self.instancename = instancename
+                        print(self.instancename)
+                    </script>
+                </transition>
+
+            </state>
+            <state id="ready">
+                <onentry>
+                    <raise scope="cd" event="start_instance">
+                        <parameter expr="self.instancename"/>
+                    </raise>
+                </onentry>
+
+                <transition event="close" target="../done">
+                    <script>
+                        print("CLOSED")
+                    </script>
+                    <raise scope="cd" event="delete_instance">
+                        <parameter expr="self.instancename"/>
+                    </raise>
+                </transition>
+
+            </state>
+            <state id="done"/>
+        </scxml>
+    </class>
+
+    <class name="B">
+        <constructor>
+            <body>
+                print("READY")
+            </body>
+        </constructor>
+
+        <relationships>
+            <association name="parent" class="A" min="1" max="1"/>
+        </relationships>
+
+        <scxml initial="z">
+            <state id="z">
+                <onentry>
+                    <script>
+                        print("RUN")
+                    </script>
+                </onentry>
+                <transition after="0" target=".">
+                    <script>
+                        print("RAISE")
+                    </script>
+                    <raise scope="broad" event="close"/>
+                </transition>
+            </state>
+        </scxml>
+    </class>
+
+</diagram>