summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Le Thanh Duong <olivier@lethanh.be>2009-12-19 13:53:07 +0100
committerOlivier Le Thanh Duong <olivier@lethanh.be>2010-01-05 09:37:05 +0100
commit875394c04a8a3fe950565a5d3d3171081a77c945 (patch)
treea5e8e48c870a000688e126517602fc389925191f
parent5f7112933e048fa13bfb4a37f36825e879d5a3d5 (diff)
Fix CreateChannel to always return a new channel.
Fix CreateChannel to always return a new channel instead of having the same behaviour as EnsureChannel and so allow to have multiple channel of the same type created for a given TargetHandle. Provide a existing_channel function in ChanelManager that ConnectionManager can subclass to define more appropriatly if there is an existing channel that match the requested properties.
-rw-r--r--src/server/channelmanager.py38
-rw-r--r--src/server/conn.py2
2 files changed, 28 insertions, 12 deletions
diff --git a/src/server/channelmanager.py b/src/server/channelmanager.py
index aacde30..2d47604 100644
--- a/src/server/channelmanager.py
+++ b/src/server/channelmanager.py
@@ -42,9 +42,10 @@ class ChannelManager(object):
def remove_channel(self, channel):
for channel_type in self._requestable_channel_classes:
- for handle, chan in self._channels[channel_type].items():
- if channel == chan:
- del self._channels[channel_type][handle]
+ for handle, channels in self._channels[channel_type].items():
+ for chan in channels:
+ if channel == chan:
+ del self._channels[channel_type][handle]
def _get_type_requested_handle(self, props):
type = props[CHANNEL_INTERFACE + '.ChannelType']
@@ -56,32 +57,47 @@ class ChannelManager(object):
return (type, requested, handle)
- def channel_exists(self, props):
+ def existing_channel(self, props):
+ """ Return a channel corresponding to theses properties if such one exists,
+ otherwhise return None.
+ Will return the last created channel, Connection Manager should subclass this function
+ to implement more appropriate behaviour. """
+
type, _, handle = self._get_type_requested_handle(props)
if type in self._channels:
if handle in self._channels[type]:
- return True
+ if len(self._channels[type][handle]) > 0:
+ return self._channels[type][handle][-1]
- return False
+ return None
- def channel_for_props(self, props, signal=True, **args):
+ def channel_exists(self, props):
+ return self.existing_channel(props) != None
+
+ def create_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)
- if self.channel_exists(props):
- return self._channels[type][handle]
-
channel = self._requestable_channel_classes[type](
props, **args)
self._conn.add_channels([channel], signal=signal)
- self._channels[type][handle] = channel
+ if type in self._channels:
+ if handle in self._channels[type]:
+ self._channels[type].setdefault(handle, []).append(channel)
return channel
+ def channel_for_props(self, props, signal=True, **args):
+ channel = self.existing_channel(props)
+ if channel:
+ return channel
+ else:
+ return self.create_channel_for_props(props, signal, **args)
+
def _implement_channel_class(self, type, make_channel, fixed, available):
self._requestable_channel_classes[type] = make_channel
self._channels.setdefault(type, {})
diff --git a/src/server/conn.py b/src/server/conn.py
index f976223..3c017eb 100644
--- a/src/server/conn.py
+++ b/src/server/conn.py
@@ -509,7 +509,7 @@ class ConnectionInterfaceRequests(
self._validate_handle(request)
props = self._alter_properties(request)
- channel = self._channel_manager.channel_for_props(props, signal=False)
+ channel = self._channel_manager.create_channel_for_props(props, signal=False)
# Remove mutable properties
todel = []