1 # telepathy-python - Base classes defining the interfaces of the Telepathy framework
3 # Copyright (C) 2005, 2006 Collabora Limited
4 # Copyright (C) 2005, 2006 Nokia Corporation
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 from telepathy.errors import NotImplemented
24 from telepathy.interfaces import CONN_MGR_INTERFACE
26 from telepathy._generated.Connection_Manager \
27 import ConnectionManager as _ConnectionManager
29 class ConnectionManager(_ConnectionManager):
30 def __init__(self, name):
32 Initialise the connection manager.
34 bus_name = 'org.freedesktop.Telepathy.ConnectionManager.%s' % name
35 object_path = '/org/freedesktop/Telepathy/ConnectionManager/%s' % name
36 _ConnectionManager.__init__(self,
37 dbus.service.BusName(bus_name, dbus.Bus(), do_not_queue=True),
40 self._connections = set()
43 def connected(self, conn):
45 Add a connection to the list of connections, emit the appropriate
48 self._connections.add(conn)
49 self.NewConnection(conn._name.get_name(), conn._object_path, conn._proto)
51 def disconnected(self, conn):
53 Remove a connection from the list of connections.
55 self._connections.remove(conn)
56 if hasattr(conn, 'remove_from_connection'):
57 # requires dbus-python >= 0.81.1
58 conn.remove_from_connection()
61 return False # when called in an idle callback
63 @dbus.service.method(CONN_MGR_INTERFACE, in_signature='', out_signature='as')
64 def ListProtocols(self):
65 return self._protos.keys()
67 def RequestConnection(self, proto, parameters):
68 if proto in self._protos:
69 conn = self._protos[proto](self, parameters)
71 return (conn._name.get_name(), conn._object_path)
73 raise NotImplemented('unknown protocol %s' % proto)