Browse Source

Fix service_set operation

Yentl Van Tendeloo 7 years ago
parent
commit
2ce7210d5a

+ 5 - 0
scripts/HUTN_service.py

@@ -26,6 +26,7 @@ def clean_code(code):
     return code
     return code
 
 
 def compile_service(port):
 def compile_service(port):
+    print("Start with port " + str(port))
     start = time.time()
     start = time.time()
     temp_file = ".tmp_%s" % port
     temp_file = ".tmp_%s" % port
 
 
@@ -59,6 +60,7 @@ def compile_service(port):
 
 
     mode = service_get(port)
     mode = service_get(port)
     code = service_get(port)
     code = service_get(port)
+    print("Service set: " + str(port))
 
 
     try:
     try:
         if mode == "code":
         if mode == "code":
@@ -76,7 +78,10 @@ def compile_service(port):
         raise
         raise
     print("Compile took %ss" % (time.time() - start))
     print("Compile took %ss" % (time.time() - start))
 
 
+print("Start service")
 service_register("compiler", compile_service)
 service_register("compiler", compile_service)
+print("Service OK")
+
 try:
 try:
     while raw_input() != "STOP":
     while raw_input() != "STOP":
         pass
         pass

+ 0 - 1
scripts/JSON_service.py

@@ -77,7 +77,6 @@ def json_service(port):
     print("JSON took %ss" % (time.time() - start))
     print("JSON took %ss" % (time.time() - start))
 
 
 service_register("JSON", json_service)
 service_register("JSON", json_service)
-print("JSON service ready!")
 
 
 try:
 try:
     while raw_input() != "STOP":
     while raw_input() != "STOP":

+ 9 - 0
wrappers/classes/modelverse.xml

@@ -1759,17 +1759,26 @@
                     <state id="service">
                     <state id="service">
                         <transition cond="self.expect_response_partial('', pop=False)" target=".">
                         <transition cond="self.expect_response_partial('', pop=False)" target=".">
                             <script>
                             <script>
+                                print("Starting new thread")
                                 import modelverse
                                 import modelverse
                                 thrd = threading.Thread(target=self.service_function, args=[self.responses.pop(0)])
                                 thrd = threading.Thread(target=self.service_function, args=[self.responses.pop(0)])
                                 thrd.daemon = True
                                 thrd.daemon = True
                                 thrd.start()
                                 thrd.start()
+                                print("Thread diverged")
                             </script>
                             </script>
                         </transition>
                         </transition>
+
                         <transition cond="self.expect_action(None, 'service_stop')" target="../../operations/service_stop">
                         <transition cond="self.expect_action(None, 'service_stop')" target="../../operations/service_stop">
                             <script>
                             <script>
                                 self.load_action(None)
                                 self.load_action(None)
                             </script>
                             </script>
                         </transition>
                         </transition>
+
+                        <transition after="1" target=".">
+                            <script>
+                                print("Responses: " + str(self.responses))
+                            </script>
+                        </transition>
                     </state>
                     </state>
 
 
                     <state id="modelling">
                     <state id="modelling">

+ 2 - 1
wrappers/modelverse.py

@@ -469,10 +469,11 @@ def service_get(port):
 
 
 def service_set(port, value):
 def service_set(port, value):
     """Set a value on a specified port."""
     """Set a value on a specified port."""
-    value = json.dumps(value)
     if isinstance(value, type([])):
     if isinstance(value, type([])):
+        value = json.dumps(value)
         urllib2.urlopen(urllib2.Request("http://%s" % controller.address, urllib.urlencode({"op": "set_input", "data": value, "taskname": port}))).read()
         urllib2.urlopen(urllib2.Request("http://%s" % controller.address, urllib.urlencode({"op": "set_input", "data": value, "taskname": port}))).read()
     else:
     else:
+        value = json.dumps(value)
         urllib2.urlopen(urllib2.Request("http://%s" % controller.address, urllib.urlencode({"op": "set_input", "value": value, "taskname": port}))).read()
         urllib2.urlopen(urllib2.Request("http://%s" % controller.address, urllib.urlencode({"op": "set_input", "value": value, "taskname": port}))).read()
 
 
 def service_poll(port):
 def service_poll(port):

+ 18 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Tue Oct 31 12:59:12 2017
+Date:   Tue Oct 31 13:17:17 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server
@@ -539,6 +539,8 @@ class Modelverse(RuntimeClassBase):
         
         
         # state /initialized/behaviour/wait_for_action/service
         # state /initialized/behaviour/wait_for_action/service
         self.states["/initialized/behaviour/wait_for_action/service"] = State(117, "/initialized/behaviour/wait_for_action/service", self)
         self.states["/initialized/behaviour/wait_for_action/service"] = State(117, "/initialized/behaviour/wait_for_action/service", self)
+        self.states["/initialized/behaviour/wait_for_action/service"].setEnter(self._initialized_behaviour_wait_for_action_service_enter)
+        self.states["/initialized/behaviour/wait_for_action/service"].setExit(self._initialized_behaviour_wait_for_action_service_exit)
         
         
         # state /initialized/behaviour/wait_for_action/modelling
         # state /initialized/behaviour/wait_for_action/modelling
         self.states["/initialized/behaviour/wait_for_action/modelling"] = State(118, "/initialized/behaviour/wait_for_action/modelling", self)
         self.states["/initialized/behaviour/wait_for_action/modelling"] = State(118, "/initialized/behaviour/wait_for_action/modelling", self)
@@ -1677,6 +1679,10 @@ class Modelverse(RuntimeClassBase):
         _initialized_behaviour_wait_for_action_service_1.setTrigger(None)
         _initialized_behaviour_wait_for_action_service_1.setTrigger(None)
         _initialized_behaviour_wait_for_action_service_1.setGuard(self._initialized_behaviour_wait_for_action_service_1_guard)
         _initialized_behaviour_wait_for_action_service_1.setGuard(self._initialized_behaviour_wait_for_action_service_1_guard)
         self.states["/initialized/behaviour/wait_for_action/service"].addTransition(_initialized_behaviour_wait_for_action_service_1)
         self.states["/initialized/behaviour/wait_for_action/service"].addTransition(_initialized_behaviour_wait_for_action_service_1)
+        _initialized_behaviour_wait_for_action_service_2 = Transition(self, self.states["/initialized/behaviour/wait_for_action/service"], [self.states["/initialized/behaviour/wait_for_action/service"]])
+        _initialized_behaviour_wait_for_action_service_2.setAction(self._initialized_behaviour_wait_for_action_service_2_exec)
+        _initialized_behaviour_wait_for_action_service_2.setTrigger(Event("_0after"))
+        self.states["/initialized/behaviour/wait_for_action/service"].addTransition(_initialized_behaviour_wait_for_action_service_2)
         
         
         # transition /initialized/behaviour/wait_for_action/modelling/recognized/manual
         # transition /initialized/behaviour/wait_for_action/modelling/recognized/manual
         _initialized_behaviour_wait_for_action_modelling_recognized_manual_0 = Transition(self, self.states["/initialized/behaviour/wait_for_action/modelling/recognized/manual"], [self.states["/initialized/behaviour/leaving_manual"]])
         _initialized_behaviour_wait_for_action_modelling_recognized_manual_0 = Transition(self, self.states["/initialized/behaviour/wait_for_action/modelling/recognized/manual"], [self.states["/initialized/behaviour/leaving_manual"]])
@@ -2163,6 +2169,12 @@ class Modelverse(RuntimeClassBase):
     def _initialized_behaviour_operations_service_stop_enter(self):
     def _initialized_behaviour_operations_service_stop_enter(self):
         self.raiseInternalEvent(Event("request", None, [['service_stop']]))
         self.raiseInternalEvent(Event("request", None, [['service_stop']]))
     
     
+    def _initialized_behaviour_wait_for_action_service_enter(self):
+        self.addTimer(0, 1)
+    
+    def _initialized_behaviour_wait_for_action_service_exit(self):
+        self.removeTimer(0)
+    
     def _initialized_behaviour_going_manual_init_enter(self):
     def _initialized_behaviour_going_manual_init_enter(self):
         self.context = None
         self.context = None
         self.current_model = self.actions[None][0]["parameters"][0]
         self.current_model = self.actions[None][0]["parameters"][0]
@@ -3262,10 +3274,12 @@ class Modelverse(RuntimeClassBase):
         return self.expect_action(None, ['element_list', 'element_list_nice', 'types', 'types_full', 'read_info', 'read_attrs', 'read_defined_attrs', 'instantiate', 'delete_element', 'attr_assign', 'attr_assign_code', 'attr_delete', 'read_outgoing', 'read_incoming', 'read_association_source', 'read_association_destination', 'connections_between', 'define_attribute', 'undefine_attribute', 'all_instances', 'attr_optional', 'attr_type', 'attr_name'])
         return self.expect_action(None, ['element_list', 'element_list_nice', 'types', 'types_full', 'read_info', 'read_attrs', 'read_defined_attrs', 'instantiate', 'delete_element', 'attr_assign', 'attr_assign_code', 'attr_delete', 'read_outgoing', 'read_incoming', 'read_association_source', 'read_association_destination', 'connections_between', 'define_attribute', 'undefine_attribute', 'all_instances', 'attr_optional', 'attr_type', 'attr_name'])
     
     
     def _initialized_behaviour_wait_for_action_service_0_exec(self, parameters):
     def _initialized_behaviour_wait_for_action_service_0_exec(self, parameters):
+        print("Starting new thread")
         import modelverse
         import modelverse
         thrd = threading.Thread(target=self.service_function, args=[self.responses.pop(0)])
         thrd = threading.Thread(target=self.service_function, args=[self.responses.pop(0)])
         thrd.daemon = True
         thrd.daemon = True
         thrd.start()
         thrd.start()
+        print("Thread diverged")
     
     
     def _initialized_behaviour_wait_for_action_service_0_guard(self, parameters):
     def _initialized_behaviour_wait_for_action_service_0_guard(self, parameters):
         return self.expect_response_partial('', pop=False)
         return self.expect_response_partial('', pop=False)
@@ -3276,6 +3290,9 @@ class Modelverse(RuntimeClassBase):
     def _initialized_behaviour_wait_for_action_service_1_guard(self, parameters):
     def _initialized_behaviour_wait_for_action_service_1_guard(self, parameters):
         return self.expect_action(None, 'service_stop')
         return self.expect_action(None, 'service_stop')
     
     
+    def _initialized_behaviour_wait_for_action_service_2_exec(self, parameters):
+        print("Responses: " + str(self.responses))
+    
     def _initialized_behaviour_wait_for_action_modelling_recognized_manual_0_guard(self, parameters):
     def _initialized_behaviour_wait_for_action_modelling_recognized_manual_0_guard(self, parameters):
         return self.expect_action(self.context, 'exit')
         return self.expect_action(self.context, 'exit')