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

Source Code for Module smartcard.pyro.server.PyroDaemon

 1  """PyroDaemon: Wrapper class around pyro daemon 
 2   
 3  __author__ = "gemalto 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  from threading import Thread 
27  import time 
28   
29  import Pyro.core 
30  import Pyro.naming 
31   
32   
33 -class PyroDaemon:
34 """Singleton class to wrap the pyro daemon.""" 35
36 - class _PyroDaemon:
37 """The pyro daemon actual wrapper class. 38 39 A single instance of this class is created 40 by the public PyroDaemon class. 41 """
42 - def __init__(self):
43 self.daemon = Pyro.core.Daemon() 44 self.handler = signal.signal(signal.SIGINT, self) 45 ns = Pyro.naming.NameServerLocator().getNS() 46 self.daemon.useNameServer(ns)
47
48 - def __call__(self, signame, sf):
49 """Ctrl+c handler that will gracefully shutdown the server 50 upon Ctrl+C signal""" 51 print 'PyroDaemon Ctrl+C handler' 52 self.daemon.shutdown(True) 53 time.sleep(1) 54 self.handler(signame, sf)
55
56 - def connect(self, object, name=None):
57 return self.daemon.connect(object, name)
58
59 - def disconnect(self, object):
60 return self.daemon.disconnect(object)
61
62 - def start(self):
63 """start pyro daemon.""" 64 self.daemon.requestLoop()
65 66 # the singleton 67 instance = None 68
69 - def __init__(self):
72
73 - def __getattr__(self, name):
74 return getattr(self.instance, name)
75 76
77 -class PyroDaemonThread(Thread):
78 """Thread running the Pyro daemon server. 79 """ 80
81 - def __init__(self):
82 """Initialize pyro event server with command line arguments. 83 For a complete list of command line arguments, see pyro documentation 84 for pyro-es start script.""" 85 Thread.__init__(self) 86 self.setDaemon(True) 87 self.setName('smartcard.pyro.server.PyroDaemonThread') 88 self.daemon = PyroDaemon()
89
90 - def run(self):
91 """Starts Pyro daemon.""" 92 self.daemon.start()
93