Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2007-06-07 16:43:58 (GMT)
committer Simon McVittie <simon.mcvittie@collabora.co.uk>2007-06-07 16:43:58 (GMT)
commitd8d17269195332d6c04c9e20457953a7b0974320 (patch)
tree6defdf5aec84df4ee810d5664b07b947c97b9ddd
parentb8146d899d82feb762b2b2f4daad5494bb0d028c (diff)
activity, server_plugin: communicate activity join result via a callback rather than a GLib signal
-rw-r--r--src/activity.py37
-rw-r--r--src/server_plugin.py85
2 files changed, 65 insertions, 57 deletions
diff --git a/src/activity.py b/src/activity.py
index ac1378f..c97ffd9 100644
--- a/src/activity.py
+++ b/src/activity.py
@@ -127,6 +127,10 @@ class Activity(ExportedGObject):
self._member_handles = set()
self._joined = False
+ self._join_cb = None
+ self._join_err_cb = None
+ self._join_is_sharing = False
+
# the telepathy client
self._tp = tp
self._room = room
@@ -496,32 +500,31 @@ class Activity(ExportedGObject):
return True
- def _joined_cb(self, tp, activity_id, room_handle, text_channel, exc,
- userdata):
+ def _joined_cb(self, tp, activity_id, room_handle, text_channel, exc):
"""XXX - not documented yet
"""
if activity_id != self.props.id:
# Not for us
return
- (sigid, async_cb, async_err_cb, am_sharing) = userdata
- self._tp.disconnect(sigid)
-
self._room = room_handle
- verb = am_sharing and 'Share' or 'Join'
+ verb = self._join_is_sharing and 'Share' or 'Join'
if exc:
_logger.debug("%s of activity %s failed: %s" % (verb, self._id,
exc))
- async_err_cb(exc)
+ self._join_err_cb(exc)
else:
self._handle_share_join(tp, text_channel)
- if am_sharing:
+ if self._join_is_sharing:
self.send_properties()
self._ps.owner.add_activity(self)
- async_cb(dbus.ObjectPath(self._object_path))
+ self._join_cb(dbus.ObjectPath(self._object_path))
_logger.debug("%s of activity %s succeeded" % (verb, self._id))
+ self._join_cb = None
+ self._join_err_cb = None
+
def join(self, async_cb, async_err_cb, sharing):
"""Local method for the local user to attempt to join the activity.
@@ -534,13 +537,23 @@ class Activity(ExportedGObject):
_joined_cb method; this callback is set up within this method.
"""
_logger.debug("Starting share/join of activity %s", self._id)
+
if self._joined:
async_err_cb(RuntimeError("Already joined activity %s"
% self.props.id))
return
- sigid = self._tp.connect('activity-joined', self._joined_cb)
- self._tp.join_activity(self.props.id, (sigid, async_cb, async_err_cb,
- sharing))
+
+ if self._join_cb is not None:
+ # FIXME: or should we trigger all the attempts?
+ async_err_cb(RuntimeError('Already trying to join activity %s'
+ % self.props.id))
+ return
+
+ self._join_cb = async_cb
+ self._join_err_cb = async_err_cb
+ self._join_is_sharing = sharing
+
+ self._tp.join_activity(self.props.id, self._joined_cb)
_logger.debug("triggered share/join attempt on activity %s", self._id)
def get_channels(self):
diff --git a/src/server_plugin.py b/src/server_plugin.py
index 954551d..914315c 100644
--- a/src/server_plugin.py
+++ b/src/server_plugin.py
@@ -157,16 +157,6 @@ class ServerPlugin(gobject.GObject):
# properties: dict { str => object }
# FIXME: are these all the properties or just those that changed?
(gobject.SIGNAL_RUN_FIRST, None, [object, object, object]),
- 'activity-joined':
- # join_activity() succeeded
- # args:
- # activity ID: str
- # activity room handle: int or long
- # channel: telepathy.client.Channel, or None on failure
- # error: None, or Exception on failure
- # userdata as passed to join_activity
- (gobject.SIGNAL_RUN_FIRST, None, [object, object, object, object,
- object]),
}
def __init__(self, registry, owner, icon_cache):
@@ -478,14 +468,17 @@ class ServerPlugin(gobject.GObject):
reply_handler=set_self_avatar_cb,
error_handler=lambda e: self._log_error_cb("setting avatar", e))
- def _join_activity_channel_props_set_cb(self, activity_id, handle,
- channel, userdata):
- self._joined_activities.append((activity_id, handle))
+ def emit_joined_activity(self, activity_id, room):
+ self._joined_activities.append((activity_id, room))
self._set_self_activities()
- self.emit('activity-joined', activity_id, handle, channel, None, userdata)
+
+ def _join_activity_channel_props_set_cb(self, activity_id, handle,
+ channel, callback):
+ self.emit_joined_activity(activity_id, handle)
+ callback(self, activity_id, handle, channel, None)
def _join_activity_channel_props_listed_cb(self, activity_id,
- handle, channel, userdata,
+ handle, channel, callback,
props, prop_specs):
props_to_set = []
@@ -501,16 +494,16 @@ class ServerPlugin(gobject.GObject):
if props_to_set:
channel[PROPERTIES_INTERFACE].SetProperties(props_to_set,
reply_handler=lambda: self._join_activity_channel_props_set_cb(
- activity_id, handle, channel, userdata),
+ activity_id, handle, channel, callback),
error_handler=lambda e: self._join_error_cb(
- activity_id, userdata,
+ activity_id, callback,
'SetProperties(%r)' % props_to_set, e))
else:
self._join_activity_channel_props_set_cb(activity_id,
- handle, channel, userdata)
+ handle, channel, callback)
def _join_activity_create_channel_cb(self, activity_id, handle,
- userdata, chan_path):
+ callback, chan_path):
channel = Channel(self._conn.service_name, chan_path)
props = {
'anonymous': False, # otherwise buddy resolution breaks
@@ -521,11 +514,11 @@ class ServerPlugin(gobject.GObject):
}
channel[PROPERTIES_INTERFACE].ListProperties(
reply_handler=lambda prop_specs: self._join_activity_channel_props_listed_cb(
- activity_id, handle, channel, userdata, props, prop_specs),
+ activity_id, handle, channel, callback, props, prop_specs),
error_handler=lambda e: self._join_error_cb(
- activity_id, userdata, 'ListProperties', e))
+ activity_id, callback, 'ListProperties', e))
- def _join_activity_get_channel_cb(self, activity_id, userdata,
+ def _join_activity_get_channel_cb(self, activity_id, callback,
handles):
if not self._activities.has_key(activity_id):
self._activities[activity_id] = handles[0]
@@ -533,24 +526,40 @@ class ServerPlugin(gobject.GObject):
if (activity_id, handles[0]) in self._joined_activities:
e = RuntimeError("Already joined activity %s" % activity_id)
_logger.debug('%s', e)
- self.emit('activity-joined', activity_id, handles[0], None, e, userdata)
+ callback(self, activity_id, handles[0], None, e)
return
self._conn[CONN_INTERFACE].RequestChannel(CHANNEL_TYPE_TEXT,
HANDLE_TYPE_ROOM, handles[0], True,
reply_handler=lambda *args: self._join_activity_create_channel_cb(
- activity_id, handles[0], userdata, *args),
+ activity_id, handles[0], callback, *args),
error_handler=lambda e: self._join_error_cb(activity_id,
- userdata, 'RequestChannel(TEXT, ROOM, %r, True)' % handles[0],
+ callback, 'RequestChannel(TEXT, ROOM, %r, True)' % handles[0],
e))
- def _join_error_cb(self, activity_id, userdata, where, err):
+ def _join_error_cb(self, activity_id, callback, where, err):
e = Exception("Error joining/sharing activity %s: (%s): %s"
% (activity_id, where, err))
_logger.debug('%s', e)
- self.emit('activity-joined', activity_id, 0, None, e, userdata)
+ callback(self, activity_id, 0, None, e)
- def _internal_join_activity(self, activity_id, userdata):
+ def join_activity(self, activity_id, callback):
+ """Share activity with the network, or join an activity on the
+ network (or locally)
+
+ activity_id -- unique ID for the activity
+ callback -- callback to be called when the join succeeds or fails,
+ with arguments:
+ self
+ activity ID: str
+ activity room handle: int or long
+ channel: telepathy.client.Channel, or None on failure
+ error: None, or Exception on failure
+
+ Asks the Telepathy server to create a "conference" channel
+ for the activity or return a handle to an already created
+ conference channel for the activity.
+ """
handle = self._activities.get(activity_id)
if not handle:
# FIXME: figure out why the server can't figure this out itself
@@ -558,28 +567,14 @@ class ServerPlugin(gobject.GObject):
self._conn[CONN_INTERFACE].RequestHandles(HANDLE_TYPE_ROOM,
[room_jid],
reply_handler=lambda *args: self._join_activity_get_channel_cb(
- activity_id, userdata, *args),
+ activity_id, callback, *args),
error_handler=lambda e: self._join_error_cb(activity_id,
- userdata, 'RequestHandles([%u])' % room_jid,
+ callback, 'RequestHandles([%u])' % room_jid,
e))
else:
- self._join_activity_get_channel_cb(activity_id, userdata,
+ self._join_activity_get_channel_cb(activity_id, callback,
[handle])
- def join_activity(self, activity_id, userdata):
- """Share activity with the network, or join an activity on the
- network (or locally)
-
- activity_id -- unique ID for the activity
- userdata -- opaque token to be passed in the resulting event
- (id, callback, errback) normally
-
- Asks the Telepathy server to create a "conference" channel
- for the activity or return a handle to an already created
- conference channel for the activity.
- """
- self._internal_join_activity(activity_id, userdata)
-
def _ignore_success_cb(self):
"""Ignore an event (null-operation)"""