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
34 """Singleton class to wrap the pyro daemon."""
35
37 """The pyro daemon actual wrapper class.
38
39 A single instance of this class is created
40 by the public PyroDaemon class.
41 """
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
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
61
63 """start pyro daemon."""
64 self.daemon.requestLoop()
65
66
67 instance = None
68
72
75
76
78 """Thread running the Pyro daemon server.
79 """
80
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
91 """Starts Pyro daemon."""
92 self.daemon.start()
93