1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 __all__ = ('Server', )
25 __docformat__ = 'reStructuredText'
26
27 from _dbus_bindings import _Server
28 from dbus.connection import Connection
29
31 """An opaque object representing a server that listens for connections from
32 other applications.
33
34 This class is not useful to instantiate directly: you must subclass it and
35 either extend the method connection_added, or append to the
36 list on_connection_added.
37
38 :Since: 0.83
39 """
40
41 - def __new__(cls, address, connection_class=Connection,
42 mainloop=None, auth_mechanisms=None):
43 """Construct a new Server.
44
45 :Parameters:
46 `address` : str
47 Listen on this address.
48 `connection_class` : type
49 When new connections come in, instantiate this subclass
50 of dbus.connection.Connection to represent them.
51 The default is Connection.
52 `mainloop` : dbus.mainloop.NativeMainLoop or None
53 The main loop with which to associate the new connections.
54 `auth_mechanisms` : sequence of str
55 Authentication mechanisms to allow. The default is to allow
56 any authentication mechanism supported by ``libdbus``.
57 """
58 return super(Server, cls).__new__(cls, address, connection_class,
59 mainloop, auth_mechanisms)
60
62
63 self.__connections = {}
64
65 self.on_connection_added = []
66 """A list of callbacks to invoke when a connection is added.
67 They receive two arguments: this Server and the new Connection."""
68
69 self.on_connection_removed = []
70 """A list of callbacks to invoke when a connection becomes
71 disconnected. They receive two arguments: this Server and the removed
72 Connection."""
73
74
75
79
81 """Respond to the creation of a new Connection.
82
83 This base-class implementation just invokes the callbacks in
84 the on_connection_added attribute.
85
86 :Parameters:
87 `conn` : dbus.connection.Connection
88 A D-Bus connection which has just been added.
89
90 The type of this parameter is whatever was passed
91 to the Server constructor as the ``connection_class``.
92 """
93 if self.on_connection_added:
94 for cb in self.on_connection_added:
95 cb(conn)
96
98 """Respond to the disconnection of a Connection.
99
100 This base-class implementation just invokes the callbacks in
101 the on_connection_removed attribute.
102
103 :Parameters:
104 `conn` : dbus.connection.Connection
105 A D-Bus connection which has just become disconnected.
106
107 The type of this parameter is whatever was passed
108 to the Server constructor as the ``connection_class``.
109 """
110 if self.on_connection_removed:
111 for cb in self.on_connection_removed:
112 cb(conn)
113
114 address = property(_Server.get_address)
115 id = property(_Server.get_id)
116 is_connected = property(_Server.get_is_connected)
117