[telepathy-python/master] Added new ChannelManager class.
Jonny Lamb
jonny.lamb at collabora.co.uk
Thu Jul 16 01:49:34 PDT 2009
Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
src/server/__init__.py | 1 +
src/server/channelmanager.py | 76 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+), 0 deletions(-)
create mode 100644 src/server/channelmanager.py
diff --git a/src/server/__init__.py b/src/server/__init__.py
index 52e804f..aa077be 100644
--- a/src/server/__init__.py
+++ b/src/server/__init__.py
@@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from telepathy.server.connmgr import *
from telepathy.server.conn import *
from telepathy.server.channel import *
+from telepathy.server.channelmanager import *
from telepathy.server.handle import *
from telepathy.server.media import *
from telepathy.server.properties import *
diff --git a/src/server/channelmanager.py b/src/server/channelmanager.py
new file mode 100644
index 0000000..27a14be
--- /dev/null
+++ b/src/server/channelmanager.py
@@ -0,0 +1,76 @@
+# telepathy-python - Base classes defining the interfaces of the Telepathy framework
+#
+# Copyright (C) 2009 Collabora Limited
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+from telepathy.errors import NotImplemented
+
+from telepathy.interfaces import (CHANNEL_INTERFACE,
+ CHANNEL_TYPE_CONTACT_LIST,
+ CHANNEL_TYPE_TEXT)
+
+class ChannelManager(object):
+
+ def __init__(self, connection):
+ self._conn = connection
+
+ self._requestable_channel_classes = dict()
+ self._channels = dict()
+
+ def close(self):
+ for channel_type in self._requestable_channel_classes:
+ for channel in self._channels[channel_type].values():
+ if channel._type == CHANNEL_TYPE_CONTACT_LIST:
+ channel.remove_from_connection()
+ else:
+ channel.Close()
+
+ def _get_type_requested_handle(self, props):
+ type = props[CHANNEL_INTERFACE + '.ChannelType']
+ requested = props[CHANNEL_INTERFACE + '.Requested']
+ target_handle = props[CHANNEL_INTERFACE + '.TargetHandle']
+ target_handle_type = props[CHANNEL_INTERFACE + '.TargetHandleType']
+
+ handle = self._conn._handles[target_handle_type, target_handle]
+
+ return (type, requested, handle)
+
+ def channel_exists(self, props):
+ type, _, handle = self._get_type_requested_handle(props)
+
+ if type in self._channels:
+ if handle in self._channels[type]:
+ return True
+
+ return False
+
+ def channel_for_props(self, props, signal=True, **args):
+ type, _, handle = self._get_type_requested_handle(props)
+
+ if type not in self._requestable_channel_classes:
+ raise NotImplemented('Unknown channel type "%s"' % type)
+
+ channel = self._requestable_channel_classes[type](
+ props, **args)
+
+ self._conn.add_channels([channel], signal=signal)
+ self._channels[type][handle] = channel
+
+ return channel
+
+ def _implement_channel_class(self, type, make_channel):
+ self._requestable_channel_classes[type] = make_channel
+ self._channels.setdefault(type, {})
--
1.5.6.5
More information about the telepathy-commits
mailing list