Beremiz_service.py
changeset 1987 8d1aca3c9e83
parent 1984 081265cda5b1
child 1988 19ca02e8074f
equal deleted inserted replaced
1986:88048a0dd0c3 1987:8d1aca3c9e83
   415         self.servicepublisher = None
   415         self.servicepublisher = None
   416         self.statuschange = statuschange
   416         self.statuschange = statuschange
   417         self.evaluator = evaluator
   417         self.evaluator = evaluator
   418         self.pyruntimevars = pyruntimevars
   418         self.pyruntimevars = pyruntimevars
   419 
   419 
       
   420     def _to_be_published(self):
       
   421         return self.servicename is not None and \
       
   422                self.ip_addr is not None and \
       
   423                self.ip_addr != "localhost" and \
       
   424                self.ip_addr != "127.0.0.1"
       
   425 
       
   426     def PrintServerInfo(self):
       
   427         print(_("Pyro port :"), self.port)
       
   428 
       
   429         # Beremiz IDE detects LOCAL:// runtime is ready by looking
       
   430         # for self.workdir in the daemon's stdout.
       
   431         print(_("Current working directory :"), self.workdir)
       
   432 
       
   433         if self._to_be_published():
       
   434             print(_("Publishing service on local network"))
       
   435 
       
   436         sys.stdout.flush()
       
   437 
       
   438 
   420     def PyroLoop(self):
   439     def PyroLoop(self):
   421         while self.continueloop:
   440         while self.continueloop:
   422             pyro.initServer()
   441             pyro.initServer()
   423             self.daemon = pyro.Daemon(host=self.ip_addr, port=self.port)
   442             self.daemon = pyro.Daemon(host=self.ip_addr, port=self.port)
       
   443 
   424             # pyro never frees memory after connection close if no timeout set
   444             # pyro never frees memory after connection close if no timeout set
   425             # taking too small timeout value may cause
   445             # taking too small timeout value may cause
   426             # unwanted diconnection when IDE is kept busy for long periods
   446             # unwanted diconnection when IDE is kept busy for long periods
   427             self.daemon.setTimeout(60)
   447             self.daemon.setTimeout(60)
   428 
   448 
   429             uri = self.daemon.connect(self.plcobj, "PLCObject")
   449             uri = self.daemon.connect(self.plcobj, "PLCObject")
   430 
   450 
   431             print(_("Pyro port :"), self.port)
   451             if self._to_be_published():
   432             print(_("Pyro object's uri :"), uri)
       
   433 
       
   434             # Beremiz IDE detects daemon start by looking
       
   435             # for self.workdir in the daemon's stdout.
       
   436             # Therefore don't delete the following line
       
   437             print(_("Current working directory :"), self.workdir)
       
   438 
       
   439             # Configure and publish service
       
   440             # Not publish service if localhost in address params
       
   441             if self.servicename is not None and \
       
   442                self.ip_addr is not None and \
       
   443                self.ip_addr != "localhost" and \
       
   444                self.ip_addr != "127.0.0.1":
       
   445                 print(_("Publishing service on local network"))
       
   446                 self.servicepublisher = ServicePublisher.ServicePublisher()
   452                 self.servicepublisher = ServicePublisher.ServicePublisher()
   447                 self.servicepublisher.RegisterService(self.servicename, self.ip_addr, self.port)
   453                 self.servicepublisher.RegisterService(self.servicename, self.ip_addr, self.port)
   448 
   454 
   449             self.daemon.requestLoop()
   455             self.daemon.requestLoop()
   450             self.daemon.sock.close()
   456             self.daemon.sock.close()
   629 plcobj.StatusChange()
   635 plcobj.StatusChange()
   630 
   636 
   631 pyro_thread = Thread(target=pyroserver.PyroLoop)
   637 pyro_thread = Thread(target=pyroserver.PyroLoop)
   632 pyro_thread.start()
   638 pyro_thread.start()
   633 
   639 
   634 sys.stdout.flush()
   640 pyroserver.PrintServerInfo()
   635 
   641 
   636 if havetwisted or havewx:
   642 if havetwisted or havewx:
   637     if havetwisted:
   643     if havetwisted:
   638         # reactor._installSignalHandlersAgain()
   644         # reactor._installSignalHandlersAgain()
   639         def ui_thread_target():
   645         def ui_thread_target():