Merge branch 'master' of git+ssh://dcbw@crank.laptop.org/git/sugar

Conflicts:

	sugar/browser/BrowserActivity.py
This commit is contained in:
Dan Williams 2006-06-18 01:33:05 -04:00
commit b703d93534
5 changed files with 29 additions and 39 deletions

View File

@ -43,7 +43,6 @@ class BrowserActivity(activity.Activity):
self._model = None
def _service_appeared_cb(self, pservice, buddy, service):
print 'appeared ' + service.get_type()
if service.get_type() == _BROWSER_ACTIVITY_TYPE:
self._notif_service = service
elif service.get_type() == LocalModel.SERVICE_TYPE:

View File

@ -1,53 +1,41 @@
import logging
from sugar.chat.Chat import Chat
from sugar.presence.Service import Service
from sugar.p2p.Stream import Stream
GROUP_CHAT_SERVICE_TYPE = "_olpc_group_chat._udp"
GROUP_CHAT_SERVICE_ADDRESS = "224.0.0.221"
GROUP_CHAT_SERVICE_PORT = 6200
from sugar.presence.PresenceService import PresenceService
class GroupChat(Chat):
def __init__(self):
SERVICE_TYPE = "_olpc_group_chat._udp"
SERVICE_PORT = 6200
def __init__(self, activity):
Chat.__init__(self)
self._chats = {}
self._activity = activity
def get_group(self):
return self._group
self._pservice = PresenceService.get_instance()
self._pservice.start()
self._pservice.connect('service-appeared', self._service_appeared_cb)
self._pservice.track_service_type(GroupChat.SERVICE_TYPE)
def new_buddy_writer(self, buddy):
service = buddy.get_service(Chat.SERVICE_TYPE)
return self._buddy_stream.new_writer(service)
# FIXME remove, when we join the activity this will happen automatically
# (Once we have a global presence service)
self._pservice.track_activity(activity.get_id())
def _start(self):
name = self._group.get_owner().get_nick_name()
def _service_appeared_cb(self, pservice, buddy, service):
if service.get_type() == GroupChat.SERVICE_TYPE:
logging.debug('Group chat service appeared, setup the stream.')
self._setup_stream(service)
# Group controls the Stream for incoming messages for
# specific buddy chats
buddy_service = Service(name, Chat.SERVICE_TYPE, Chat.SERVICE_PORT)
self._buddy_stream = Stream.new_from_service(buddy_service, self._group)
self._buddy_stream.set_data_listener(getattr(self, "_buddy_recv_message"))
buddy_service.register(self._group)
def publish(self):
service = self._pservice.share_activity(self._activity,
stype = GroupChat.SERVICE_TYPE, port = GroupChat.SERVICE_PORT)
# Group chat Stream
group_service = Service(name,
GROUP_CHAT_SERVICE_TYPE,
GROUP_CHAT_SERVICE_PORT,
GROUP_CHAT_SERVICE_ADDRESS)
self._group.add_service(group_service)
self._group_stream = Stream.new_from_service(group_service, self._group)
def _setup_stream(self, service):
self._group_stream = Stream.new_from_service(service)
self._group_stream.set_data_listener(self._group_recv_message)
self._stream_writer = self._group_stream.new_writer()
def _group_recv_message(self, buddy, msg):
self.recv_message(buddy, msg)
def _buddy_recv_message(self, buddy, msg):
if not self._chats.has_key(buddy):
# chat = BuddyChat(self, buddy)
# self._chats[buddy] = chat
# chat.connect_to_shell()
pass
else:
chat = self._chats[buddy]
chat.recv_message(buddy, msg)

View File

@ -126,13 +126,14 @@ class UnicastStream(Stream):
class MulticastStream(Stream):
def __init__(self, service):
Stream.__init__(self, service)
self._service = service
self._internal_start_reader()
def start_reader(self):
return self._reader_port
def _internal_start_reader(self):
if not service.get_address():
if not self._service.get_address():
raise ValueError("service must have a valid address.")
self._pipe = MostlyReliablePipe('', self._address, self._reader_port,
self._recv_data_cb)

View File

@ -506,6 +506,7 @@ class PresenceService(gobject.GObject):
def share_activity(self, activity, stype, properties={}, address=None, port=None):
"""Convenience function to share an activity with other buddies."""
uid = activity.get_id()
logging.debug('Sharing activity uid %s, stype %s' % (uid, stype))
owner_nick = self._owner.get_nick_name()
real_stype = Service.compose_service_type(stype, uid)
if address and type(address) != type(""):

View File

@ -80,7 +80,7 @@ class ActivityHost(dbus.service.Object):
self._create_chat()
def _create_chat(self):
self._group_chat = GroupChat()
self._group_chat = GroupChat(self)
def get_chat(self):
return self._group_chat
@ -95,6 +95,7 @@ class ActivityHost(dbus.service.Object):
pass
def publish(self):
self._group_chat.publish()
self.peer_service.publish()
def tab_close_button_clicked(self, button):