Package dbus :: Module server
[hide private]
[frames] | no frames]

Source Code for Module dbus.server

  1  # Copyright (C) 2008 Openismus GmbH <http://openismus.com/> 
  2  # Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/> 
  3  # 
  4  # Permission is hereby granted, free of charge, to any person 
  5  # obtaining a copy of this software and associated documentation 
  6  # files (the "Software"), to deal in the Software without 
  7  # restriction, including without limitation the rights to use, copy, 
  8  # modify, merge, publish, distribute, sublicense, and/or sell copies 
  9  # of the Software, and to permit persons to whom the Software is 
 10  # furnished to do so, subject to the following conditions: 
 11  # 
 12  # The above copyright notice and this permission notice shall be 
 13  # included in all copies or substantial portions of the Software. 
 14  # 
 15  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
 16  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 17  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 18  # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 19  # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
 20  # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 21  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 22  # DEALINGS IN THE SOFTWARE. 
 23   
 24  __all__ = ('Server', ) 
 25  __docformat__ = 'reStructuredText' 
 26   
 27  from _dbus_bindings import _Server 
 28  from dbus.connection import Connection 
 29   
30 -class Server(_Server):
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
61 - def __init__(self, *args, **kwargs):
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 # This method name is hard-coded in _dbus_bindings._Server. 75 # This is not public API.
76 - def _on_new_connection(self, conn):
79
80 - def connection_added(self, conn):
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
97 - def connection_removed(self, conn):
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