PyroServer: fixed naming of class, and reorganized methods in order to ease subclassing, in case of customization of service publication on the local network (i.e. zeroconf)
authorEdouard Tisserant
Fri, 21 Dec 2018 13:43:41 +0100
changeset 2476 1881d0ff5ae2
parent 2475 39ba6a125a97
child 2477 4866c01e7428
PyroServer: fixed naming of class, and reorganized methods in order to ease subclassing, in case of customization of service publication on the local network (i.e. zeroconf)
Beremiz_service.py
runtime/PyroServer.py
--- a/Beremiz_service.py	Fri Dec 21 13:39:41 2018 +0100
+++ b/Beremiz_service.py	Fri Dec 21 13:43:41 2018 +0100
@@ -37,7 +37,7 @@
 from six.moves import builtins
 
 import runtime
-from runtime.PyroServer import Server
+from runtime.PyroServer import PyroServer
 from runtime.xenomai import TryPreloadXenomai
 from runtime import LogMessageAndException
 from runtime import PlcStatus
@@ -504,7 +504,7 @@
 runtime.CreatePLCObjectSingleton(
     WorkingDir, argv, statuschange, evaluator, pyruntimevars)
 
-pyroserver = Server(servicename, interface, port)
+pyroserver = PyroServer(servicename, interface, port)
 
 if havewx:
     taskbar_instance = BeremizTaskBarIcon(pyroserver)
--- a/runtime/PyroServer.py	Fri Dec 21 13:39:41 2018 +0100
+++ b/runtime/PyroServer.py	Fri Dec 21 13:43:41 2018 +0100
@@ -19,7 +19,7 @@
 from runtime.ServicePublisher import ServicePublisher
 
 
-class Server(object):
+class PyroServer(object):
     def __init__(self, servicename, ip_addr, port):
         self.continueloop = True
         self.daemon = None
@@ -41,6 +41,7 @@
         sys.stdout.flush()
 
     def PyroLoop(self, when_ready):
+        if self._to_be_published(): self.Publish()
         while self.continueloop:
             Pyro.config.PYRO_MULTITHREADED = 0
             pyro.initServer()
@@ -56,23 +57,24 @@
 
             self.daemon.connect(pyro_obj, "PLCObject")
 
-            if self._to_be_published():
-                self.servicepublisher = ServicePublisher()
-                self.servicepublisher.RegisterService(self.servicename, self.ip_addr, self.port)
-
             when_ready()
             self.daemon.requestLoop()
             self.daemon.sock.close()
+        self.Unpublish()
 
     def Restart(self):
-        self._stop()
+        self.daemon.shutdown(True)
 
     def Quit(self):
         self.continueloop = False
-        self._stop()
+        self.daemon.shutdown(True)
 
-    def _stop(self):
+    def Publish(self):
+        self.servicepublisher = ServicePublisher("PYRO")
+        self.servicepublisher.RegisterService(self.servicename,
+                                              self.ip_addr, self.port)
+
+    def Unpublish(self):
         if self.servicepublisher is not None:
             self.servicepublisher.UnRegisterService()
             self.servicepublisher = None
-        self.daemon.shutdown(True)