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 self._model = None
def _service_appeared_cb(self, pservice, buddy, service): def _service_appeared_cb(self, pservice, buddy, service):
print 'appeared ' + service.get_type()
if service.get_type() == _BROWSER_ACTIVITY_TYPE: if service.get_type() == _BROWSER_ACTIVITY_TYPE:
self._notif_service = service self._notif_service = service
elif service.get_type() == LocalModel.SERVICE_TYPE: elif service.get_type() == LocalModel.SERVICE_TYPE:

View File

@ -1,53 +1,41 @@
import logging
from sugar.chat.Chat import Chat from sugar.chat.Chat import Chat
from sugar.presence.Service import Service from sugar.presence.Service import Service
from sugar.p2p.Stream import Stream from sugar.p2p.Stream import Stream
from sugar.presence.PresenceService import PresenceService
GROUP_CHAT_SERVICE_TYPE = "_olpc_group_chat._udp"
GROUP_CHAT_SERVICE_ADDRESS = "224.0.0.221"
GROUP_CHAT_SERVICE_PORT = 6200
class GroupChat(Chat): class GroupChat(Chat):
def __init__(self): SERVICE_TYPE = "_olpc_group_chat._udp"
SERVICE_PORT = 6200
def __init__(self, activity):
Chat.__init__(self) Chat.__init__(self)
self._chats = {} self._chats = {}
self._activity = activity
def get_group(self): self._pservice = PresenceService.get_instance()
return self._group 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): # FIXME remove, when we join the activity this will happen automatically
service = buddy.get_service(Chat.SERVICE_TYPE) # (Once we have a global presence service)
return self._buddy_stream.new_writer(service) self._pservice.track_activity(activity.get_id())
def _start(self): def _service_appeared_cb(self, pservice, buddy, service):
name = self._group.get_owner().get_nick_name() 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 def publish(self):
# specific buddy chats service = self._pservice.share_activity(self._activity,
buddy_service = Service(name, Chat.SERVICE_TYPE, Chat.SERVICE_PORT) stype = GroupChat.SERVICE_TYPE, port = GroupChat.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)
# Group chat Stream def _setup_stream(self, service):
group_service = Service(name, self._group_stream = Stream.new_from_service(service)
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)
self._group_stream.set_data_listener(self._group_recv_message) self._group_stream.set_data_listener(self._group_recv_message)
self._stream_writer = self._group_stream.new_writer() self._stream_writer = self._group_stream.new_writer()
def _group_recv_message(self, buddy, msg): def _group_recv_message(self, buddy, msg):
self.recv_message(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): class MulticastStream(Stream):
def __init__(self, service): def __init__(self, service):
Stream.__init__(self, service) Stream.__init__(self, service)
self._service = service
self._internal_start_reader() self._internal_start_reader()
def start_reader(self): def start_reader(self):
return self._reader_port return self._reader_port
def _internal_start_reader(self): def _internal_start_reader(self):
if not service.get_address(): if not self._service.get_address():
raise ValueError("service must have a valid address.") raise ValueError("service must have a valid address.")
self._pipe = MostlyReliablePipe('', self._address, self._reader_port, self._pipe = MostlyReliablePipe('', self._address, self._reader_port,
self._recv_data_cb) 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): def share_activity(self, activity, stype, properties={}, address=None, port=None):
"""Convenience function to share an activity with other buddies.""" """Convenience function to share an activity with other buddies."""
uid = activity.get_id() uid = activity.get_id()
logging.debug('Sharing activity uid %s, stype %s' % (uid, stype))
owner_nick = self._owner.get_nick_name() owner_nick = self._owner.get_nick_name()
real_stype = Service.compose_service_type(stype, uid) real_stype = Service.compose_service_type(stype, uid)
if address and type(address) != type(""): if address and type(address) != type(""):

View File

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