Package smartcard :: Package pyro :: Package server :: Module PyroEventServer
[hide private]
[frames] | no frames]

Source Code for Module smartcard.pyro.server.PyroEventServer

  1  """Utility class to start/stop Pyro Event Server.
 
  2  
 
  3  __author__ = "http://www.gemalto.com"
 
  4  
 
  5  Copyright 2001-2011 gemalto
 
  6  Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com
 
  7  
 
  8  This file is part of pyscard.
 
  9  
 
 10  pyscard is free software; you can redistribute it and/or modify
 
 11  it under the terms of the GNU Lesser General Public License as published by
 
 12  the Free Software Foundation; either version 2.1 of the License, or
 
 13  (at your option) any later version.
 
 14  
 
 15  pyscard is distributed in the hope that it will be useful,
 
 16  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 18  GNU Lesser General Public License for more details.
 
 19  
 
 20  You should have received a copy of the GNU Lesser General Public License
 
 21  along with pyscard; if not, write to the Free Software
 
 22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 23  """ 
 24  
 
 25  import signal 
 26  import sys 
 27  from threading import Thread 
 28  import time 
 29  
 
 30  import Pyro.EventService.Server 
 31  import Pyro.naming 
 32  import Pyro.nsc 
 33  import Pyro.util 
 34  
 
 35  
 
36 -class PyroEventServer(Thread):
37 """Thread running the Pyro Event server. 38 """ 39
40 - def __init__(self, args=[]):
41 """Initialize pyro event server with command line arguments. 42 For a complete list of command line arguments, see pyro documentation 43 for pyro-es start script.""" 44 Thread.__init__(self) 45 self.setDaemon(True) 46 self.setName('smartcard.pyro.server.PyroEventServer') 47 self.args = args 48 self.handler = signal.signal(signal.SIGINT, self) 49 self.starter = None
50
51 - def run(self):
52 """Starts Pyro naming server with command line arguments (see 53 pyro documentation) """ 54 args = [] 55 for arg in self.args: 56 args.append(arg) 57 Args = Pyro.util.ArgParser() 58 Args.parse(args, 'hkmrvxn:p:b:c:d:s:i:1:2:') 59 60 hostname = Args.getOpt('n', None) 61 identification = Args.getOpt('i', None) 62 port = None 63 useNameServer = True 64 65 if port: 66 port = int(port) 67 norange = (port == 0) 68 69 self.starter = Pyro.EventService.Server.EventServiceStarter(identification=identification) 70 self.starter.start(hostname, port, useNameServer=useNameServer, norange=norange)
71
72 - def stop(self):
73 """Shutdown pyro event server.""" 74 pass
75
76 - def waitStarted(self):
77 """wait until name server is started.""" 78 started = False 79 while not started: 80 if self.starter != None: 81 started = self.starter.waitUntilStarted(0.5)
82
83 - def __call__(self, signame, sf):
84 """Ctrl+c handler that will gracefully shutdown the server 85 upon Ctrl+C signal""" 86 print 'PyroEventServer Ctrl+C handler' 87 self.stop() 88 time.sleep(1) 89 self.handler(signame, sf)
90 91 92 if __name__ == '__main__': 93 import sys 94 from smartcard.pyro.server.PyroNameServer import PyroNameServer 95 pn = PyroNameServer(sys.argv[1:]) 96 pn.start() 97 pn.waitStarted() 98 pe = PyroEventServer(sys.argv[1:]) 99 pe.start() 100 pe.waitStarted() 101 pn.listall() 102 pe.stop() 103 pn.stop() 104