639 for thing in ["Start", "Stop", "Watchdog"]: |
639 for thing in ["Start", "Stop", "Watchdog"]: |
640 given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"] |
640 given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"] |
641 svghmi_cmds[thing] = ( |
641 svghmi_cmds[thing] = ( |
642 "Popen(" + |
642 "Popen(" + |
643 repr(shlex.split(given_command.format(**svghmi_options))) + |
643 repr(shlex.split(given_command.format(**svghmi_options))) + |
644 ")") if given_command else "pass # no command given" |
644 ")") if given_command else "None # no command given" |
645 |
645 |
646 runtimefile_path = os.path.join(buildpath, "runtime_%s_svghmi_.py" % location_str) |
646 runtimefile_path = os.path.join(buildpath, "runtime_%s_svghmi_.py" % location_str) |
647 runtimefile = open(runtimefile_path, 'w') |
647 runtimefile = open(runtimefile_path, 'w') |
648 runtimefile.write(""" |
648 runtimefile.write(""" |
649 # TODO : multiple watchdog (one for each svghmi instance) |
649 #!/usr/bin/env python |
|
650 # -*- coding: utf-8 -*- |
|
651 |
|
652 # generated by beremiz/svghmi/svghmi.py |
|
653 |
|
654 browser_proc = None |
|
655 |
650 def svghmi_{location}_watchdog_trigger(): |
656 def svghmi_{location}_watchdog_trigger(): |
651 {svghmi_cmds[Watchdog]} |
657 global browser_proc |
|
658 restart_proc = {svghmi_cmds[Watchdog]} |
|
659 waitpid_timeout(restart_proc, "SVGHMI watchdog triggered command") |
|
660 waitpid_timeout(browser_proc, "SVGHMI browser process") |
|
661 browser_proc = None |
652 |
662 |
653 max_svghmi_sessions = {maxConnections_total} |
663 max_svghmi_sessions = {maxConnections_total} |
654 |
664 |
655 def _runtime_{location}_svghmi_start(): |
665 def _runtime_{location}_svghmi_start(): |
656 global svghmi_watchdog, svghmi_servers |
666 global svghmi_watchdog, svghmi_servers, browser_proc |
657 |
667 |
658 srv = svghmi_servers.get("{interface}:{port}", None) |
668 srv = svghmi_servers.get("{interface}:{port}", None) |
659 if srv is not None: |
669 if srv is not None: |
660 svghmi_root, svghmi_listener, path_list = srv |
670 svghmi_root, svghmi_listener, path_list = srv |
661 if '{path}' in path_list: |
671 if '{path}' in path_list: |
676 NoCacheFile('{xhtml}', |
686 NoCacheFile('{xhtml}', |
677 defaultType='application/xhtml+xml')) |
687 defaultType='application/xhtml+xml')) |
678 |
688 |
679 path_list.append("{path}") |
689 path_list.append("{path}") |
680 |
690 |
681 {svghmi_cmds[Start]} |
691 browser_proc = {svghmi_cmds[Start]} |
682 |
692 |
683 if {enable_watchdog}: |
693 if {enable_watchdog}: |
684 if svghmi_watchdog is None: |
694 if svghmi_watchdog is None: |
685 svghmi_watchdog = Watchdog( |
695 svghmi_watchdog = Watchdog( |
686 {watchdog_initial}, |
696 {watchdog_initial}, |
689 else: |
699 else: |
690 raise Exception("SVGHMI {name}: only one watchdog allowed") |
700 raise Exception("SVGHMI {name}: only one watchdog allowed") |
691 |
701 |
692 |
702 |
693 def _runtime_{location}_svghmi_stop(): |
703 def _runtime_{location}_svghmi_stop(): |
694 global svghmi_watchdog, svghmi_servers |
704 global svghmi_watchdog, svghmi_servers, browser_proc |
695 |
705 |
696 if svghmi_watchdog is not None: |
706 if svghmi_watchdog is not None: |
697 svghmi_watchdog.cancel() |
707 svghmi_watchdog.cancel() |
698 svghmi_watchdog = None |
708 svghmi_watchdog = None |
699 |
709 |
705 if len(path_list)==0: |
715 if len(path_list)==0: |
706 svghmi_root.delEntity("ws") |
716 svghmi_root.delEntity("ws") |
707 svghmi_listener.stopListening() |
717 svghmi_listener.stopListening() |
708 svghmi_servers.pop("{interface}:{port}") |
718 svghmi_servers.pop("{interface}:{port}") |
709 |
719 |
710 {svghmi_cmds[Stop]} |
720 stop_proc = {svghmi_cmds[Stop]} |
|
721 waitpid_timeout(stop_proc, "SVGHMI stop command") |
|
722 waitpid_timeout(browser_proc, "SVGHMI browser process") |
|
723 browser_proc = None |
711 |
724 |
712 """.format(location=location_str, |
725 """.format(location=location_str, |
713 xhtml=target_fname, |
726 xhtml=target_fname, |
714 svghmi_cmds=svghmi_cmds, |
727 svghmi_cmds=svghmi_cmds, |
715 watchdog_initial = self.GetParamsAttributes("SVGHMI.WatchdogInitial")["value"], |
728 watchdog_initial = self.GetParamsAttributes("SVGHMI.WatchdogInitial")["value"], |