Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/mmm_modules
diff options
context:
space:
mode:
authorC. Neves <cn@sueste.net>2007-11-08 17:21:00 (GMT)
committer C. Neves <cn@sueste.net>2007-11-08 17:21:00 (GMT)
commita0e7e770798e965788ab62c56279c1bb8b174147 (patch)
tree08af45ee98285a8624e81dd2d2909e327b397711 /mmm_modules
parentddb53471b4e7dc1d19235672f3080cdc0afb1cf4 (diff)
Updated to use the tube helpers in Sugar.
Diffstat (limited to 'mmm_modules')
-rw-r--r--mmm_modules/tube_helper.py249
-rw-r--r--mmm_modules/tubeconn.py107
2 files changed, 148 insertions, 208 deletions
diff --git a/mmm_modules/tube_helper.py b/mmm_modules/tube_helper.py
index adb88e3..1a1964b 100644
--- a/mmm_modules/tube_helper.py
+++ b/mmm_modules/tube_helper.py
@@ -24,10 +24,10 @@
### (c) 2007 World Wide Workshop Foundation
import telepathy
-import telepathy.client
-from tubeconn import TubeConnection
+#import telepathy.client
+from sugar.presence.tubeconn import TubeConnection
from sugar.presence import presenceservice
-import dbus
+#import dbus
import logging
logger = logging.getLogger('tube_helper')
@@ -45,98 +45,140 @@ class TubeHelper (object):
self.service = service
self.pservice = presenceservice.get_instance()
- bus = dbus.Bus()
- name, path = self.pservice.get_preferred_connection()
- self.tp_conn_name = name
- self.tp_conn_path = path
- self.conn = telepathy.client.Connection(name, path)
+ #bus = dbus.Bus()
+
+
+ #name, path = self.pservice.get_preferred_connection()
+ #self.tp_conn_name = name
+ #self.tp_conn_path = path
+ #self.conn = telepathy.client.Connection(name, path)
self.game_tube = False
self.initiating = None
- self.connect('shared', self._shared_cb)
# Buddy object for you
owner = self.pservice.get_owner()
self.owner = owner
- if self._shared_activity:
- # we are joining the activity
- self.connect('joined', self._joined_cb)
- self._shared_activity.connect('buddy-joined',
- self._buddy_joined_cb)
- self._shared_activity.connect('buddy-left',
- self._buddy_left_cb)
- if self.get_shared():
- # we've already joined
- self._joined_cb()
+ self.connect('shared', self._shared_cb)
+ self.connect('joined', self._joined_cb)
+
+ #if self._shared_activity:
+ # # we are joining the activity
+ # self.conn = self._shared_activity.telepathy_conn
+ # self.tubes_chan = self._shared_activity.telepathy_tubes_chan
+ # self.text_chan = self._shared_activity.telepathy_text_chan
+ # self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal('NewTube',
+ # self._new_tube_cb)
+ # self.connect('joined', self._joined_cb)
+ # self._shared_activity.connect('buddy-joined',
+ # self._buddy_joined_cb)
+ # self._shared_activity.connect('buddy-left',
+ # self._buddy_left_cb)
+ # if self.get_shared():
+ # # we've already joined
+ # self._joined_cb()
+
+
+ def _sharing_setup(self):
+ if self._shared_activity is None:
+ logger.error('Failed to share or join activity')
+ return
- def _shared_cb(self, activity):
- logger.debug('My activity was shared')
- self.initiating = True
- self.shared_cb()
- self._setup()
+ self.conn = self._shared_activity.telepathy_conn
+ self.tubes_chan = self._shared_activity.telepathy_tubes_chan
+ self.text_chan = self._shared_activity.telepathy_text_chan
- for buddy in self._shared_activity.get_joined_buddies():
- pass # Can do stuff with newly acquired buddies here
+ self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal('NewTube',
+ self._new_tube_cb)
self._shared_activity.connect('buddy-joined', self._buddy_joined_cb)
self._shared_activity.connect('buddy-left', self._buddy_left_cb)
+ def _shared_cb(self, activity):
+ logger.debug('My activity was shared')
+ self.initiating = True
+ self._sharing_setup()
+
logger.debug('This is my activity: making a tube...')
- id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferTube(
- telepathy.TUBE_TYPE_DBUS, self.service, {})
+ id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(
+ self.service, {})
+ self.shared_cb()
+
+ #def _shared_cb(self, activity):
+ # logger.debug('My activity was shared')
+ # self.initiating = True
+ # #self._setup()
+ #
+ # self.conn = self._shared_activity.telepathy_conn
+ # self.tubes_chan = self._shared_activity.telepathy_tubes_chan
+ # self.text_chan = self._shared_activity.telepathy_text_chan
+ # self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal('NewTube',
+ # self._new_tube_cb)
+ #
+ # for buddy in self._shared_activity.get_joined_buddies():
+ # pass # Can do stuff with newly acquired buddies here
+ #
+ # self._shared_activity.connect('buddy-joined', self._buddy_joined_cb)
+ # self._shared_activity.connect('buddy-left', self._buddy_left_cb)
+ #
+ # logger.debug('This is my activity: making a tube...')
+# # id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferTube(
+# # telepathy.TUBE_TYPE_DBUS, self.service, {})
+ #
+ # self.shared_cb()
def shared_cb (self):
""" override this """
pass
- # FIXME: presence service should be tubes-aware and give us more help
- # with this
- def _setup(self):
- if self._shared_activity is None:
- logger.error('Failed to share or join activity')
- return
-
- bus_name, conn_path, channel_paths =\
- self._shared_activity.get_channels()
-
- # Work out what our room is called and whether we have Tubes already
- room = None
- tubes_chan = None
- text_chan = None
- for channel_path in channel_paths:
- channel = telepathy.client.Channel(bus_name, channel_path)
- htype, handle = channel.GetHandle()
- if htype == telepathy.HANDLE_TYPE_ROOM:
- logger.debug('Found our room: it has handle#%d "%s"',
- handle, self.conn.InspectHandles(htype, [handle])[0])
- room = handle
- ctype = channel.GetChannelType()
- if ctype == telepathy.CHANNEL_TYPE_TUBES:
- logger.debug('Found our Tubes channel at %s', channel_path)
- tubes_chan = channel
- elif ctype == telepathy.CHANNEL_TYPE_TEXT:
- logger.debug('Found our Text channel at %s', channel_path)
- text_chan = channel
-
- if room is None:
- logger.error("Presence service didn't create a room")
- return
- if text_chan is None:
- logger.error("Presence service didn't create a text channel")
- return
-
- # Make sure we have a Tubes channel - PS doesn't yet provide one
- if tubes_chan is None:
- logger.debug("Didn't find our Tubes channel, requesting one...")
- tubes_chan = self.conn.request_channel(telepathy.CHANNEL_TYPE_TUBES,
- telepathy.HANDLE_TYPE_ROOM, room, True)
-
- self.tubes_chan = tubes_chan
- self.text_chan = text_chan
-
- tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal('NewTube',
- self._new_tube_cb)
+# # FIXME: presence service should be tubes-aware and give us more help
+# # with this
+# def _setup(self):
+# if self._shared_activity is None:
+# logger.error('Failed to share or join activity')
+# return
+#
+# bus_name, conn_path, channel_paths =\
+# self._shared_activity.get_channels()
+#
+# # Work out what our room is called and whether we have Tubes already
+# room = None
+# tubes_chan = None
+# text_chan = None
+# for channel_path in channel_paths:
+# channel = telepathy.client.Channel(bus_name, channel_path)
+# htype, handle = channel.GetHandle()
+# if htype == telepathy.HANDLE_TYPE_ROOM:
+# logger.debug('Found our room: it has handle#%d "%s"',
+# handle, self.conn.InspectHandles(htype, [handle])[0])
+# room = handle
+# ctype = channel.GetChannelType()
+# if ctype == telepathy.CHANNEL_TYPE_TUBES:
+# logger.debug('Found our Tubes channel at %s', channel_path)
+# tubes_chan = channel
+# elif ctype == telepathy.CHANNEL_TYPE_TEXT:
+# logger.debug('Found our Text channel at %s', channel_path)
+# text_chan = channel
+#
+# if room is None:
+# logger.error("Presence service didn't create a room")
+# return
+# if text_chan is None:
+# logger.error("Presence service didn't create a text channel")
+# return
+#
+# # Make sure we have a Tubes channel - PS doesn't yet provide one
+# if tubes_chan is None:
+# logger.debug("Didn't find our Tubes channel, requesting one...")
+# tubes_chan = self.conn.request_channel(telepathy.CHANNEL_TYPE_TUBES,
+# telepathy.HANDLE_TYPE_ROOM, room, True)
+#
+# self.tubes_chan = tubes_chan
+# self.text_chan = text_chan
+#
+# tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal('NewTube',
+# self._new_tube_cb)
def _list_tubes_reply_cb(self, tubes):
for tube_info in tubes:
@@ -153,9 +195,8 @@ class TubeHelper (object):
self._buddy_joined_cb(self, buddy)
logger.debug('Joined an existing shared activity')
- self.joined_cb()
self.initiating = False
- self._setup()
+ self._sharing_setup()
logger.debug('This is not my activity: waiting for a tube...')
self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].ListTubes(
@@ -174,43 +215,49 @@ class TubeHelper (object):
if (type == telepathy.TUBE_TYPE_DBUS and
service == self.service):
if state == telepathy.TUBE_STATE_LOCAL_PENDING:
- self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].AcceptTube(id)
+ self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id)
- tube_conn = TubeConnection(self.conn,
+ self.tube_conn = TubeConnection(self.conn,
self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES],
id, group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP])
+
logger.debug("creating game tube")
- self.game_tube = self.tube_class(tube_conn, self.initiating, self)
+ self.game_tube = self.tube_class(self.tube_conn, self.initiating, self)
+
self.new_tube_cb()
+ def get_bus_name (self):
+ return self.tube_conn.participants.get(self.tubes_chan[telepathy.CHANNEL_INTERFACE_GROUP].GetSelfHandle(), None)
+
def new_tube_cb (self):
""" override this """
pass
def _get_buddy(self, cs_handle):
"""Get a Buddy from a channel specific handle."""
- logger.debug('Trying to find owner of handle %u...', cs_handle)
- group = self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP]
- my_csh = group.GetSelfHandle()
- logger.debug('My handle in that group is %u', my_csh)
- if my_csh == cs_handle:
- handle = self.conn.GetSelfHandle()
- logger.debug('CS handle %u belongs to me, %u', cs_handle, handle)
- elif group.GetGroupFlags() & telepathy.CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES:
- handle = group.GetHandleOwners([cs_handle])[0]
- logger.debug('CS handle %u belongs to %u', cs_handle, handle)
- else:
- handle = cs_handle
- logger.debug('non-CS handle %u belongs to itself', handle)
-
- # XXX: deal with failure to get the handle owner
- assert handle != 0
-
- # XXX: we're assuming that we have Buddy objects for all contacts -
- # this might break when the server becomes scalable.
- return self.pservice.get_buddy_by_telepathy_handle(self.tp_conn_name,
- self.tp_conn_path, handle)
+ return self._shared_activity.get_buddy_by_handle(cs_handle)
+ #logger.debug('Trying to find owner of handle %u...', cs_handle)
+ #group = self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP]
+ #my_csh = group.GetSelfHandle()
+ #logger.debug('My handle in that group is %u', my_csh)
+ #if my_csh == cs_handle:
+ # handle = self.conn.GetSelfHandle()
+ # logger.debug('CS handle %u belongs to me, %u', cs_handle, handle)
+ #elif group.GetGroupFlags() & telepathy.CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES:
+ # handle = group.GetHandleOwners([cs_handle])[0]
+ # logger.debug('CS handle %u belongs to %u', cs_handle, handle)
+ #else:
+ # handle = cs_handle
+ # logger.debug('non-CS handle %u belongs to itself', handle)
+ #
+ # # XXX: deal with failure to get the handle owner
+ # assert handle != 0
+ #
+ ## XXX: we're assuming that we have Buddy objects for all contacts -
+ ## this might break when the server becomes scalable.
+ #return self.pservice.get_buddy_by_telepathy_handle(self.tp_conn_name,
+ # self.tp_conn_path, handle)
def _buddy_joined_cb (self, activity, buddy):
logger.debug('Buddy %s joined' % buddy.props.nick)
diff --git a/mmm_modules/tubeconn.py b/mmm_modules/tubeconn.py
deleted file mode 100644
index d1c1403..0000000
--- a/mmm_modules/tubeconn.py
+++ /dev/null
@@ -1,107 +0,0 @@
-# This should eventually land in telepathy-python, so has the same license:
-
-# Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
-#
-# This program 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 program 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 program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-
-__all__ = ('TubeConnection',)
-__docformat__ = 'reStructuredText'
-
-
-import logging
-
-from dbus.connection import Connection
-
-
-logger = logging.getLogger('telepathy.tubeconn')
-
-
-class TubeConnection(Connection):
-
- def __new__(cls, conn, tubes_iface, tube_id, address=None,
- group_iface=None, mainloop=None):
- if address is None:
- address = tubes_iface.GetDBusServerAddress(tube_id)
- self = super(TubeConnection, cls).__new__(cls, address,
- mainloop=mainloop)
-
- self._tubes_iface = tubes_iface
- self.tube_id = tube_id
- self.participants = {}
- self.bus_name_to_handle = {}
- self._mapping_watches = []
-
- if group_iface is None:
- method = conn.GetSelfHandle
- else:
- method = group_iface.GetSelfHandle
- method(reply_handler=self._on_get_self_handle_reply,
- error_handler=self._on_get_self_handle_error)
-
- return self
-
- def _on_get_self_handle_reply(self, handle):
- self.self_handle = handle
- match = self._tubes_iface.connect_to_signal('DBusNamesChanged',
- self._on_dbus_names_changed)
- self._tubes_iface.GetDBusNames(self.tube_id,
- reply_handler=self._on_get_dbus_names_reply,
- error_handler=self._on_get_dbus_names_error)
- self._dbus_names_changed_match = match
-
- def _on_get_self_handle_error(self, e):
- logging.basicConfig()
- logger.error('GetSelfHandle failed: %s', e)
-
- def close(self):
- self._dbus_names_changed_match.remove()
- self._on_dbus_names_changed(self.tube_id, (), self.participants.keys())
- super(TubeConnection, self).close()
-
- def _on_get_dbus_names_reply(self, names):
- self._on_dbus_names_changed(self.tube_id, names, ())
-
- def _on_get_dbus_names_error(self, e):
- logging.basicConfig()
- logger.error('GetDBusNames failed: %s', e)
-
- def _on_dbus_names_changed(self, tube_id, added, removed):
- if tube_id == self.tube_id:
- for handle, bus_name in added:
- if handle == self.self_handle:
- # I've just joined - set my unique name
- self.set_unique_name(bus_name)
- self.participants[handle] = bus_name
- self.bus_name_to_handle[bus_name] = handle
-
- # call the callback while the removed people are still in
- # participants, so their bus names are available
- for callback in self._mapping_watches:
- callback(added, removed)
-
- for handle in removed:
- bus_name = self.participants.pop(handle, None)
- self.bus_name_to_handle.pop(bus_name, None)
-
- def watch_participants(self, callback):
- self._mapping_watches.append(callback)
- if self.participants:
- # GetDBusNames already returned: fake a participant add event
- # immediately
- added = []
- for k, v in self.participants.iteritems():
- added.append((k, v))
- callback(added, [])