Get page sharing back to work

This commit is contained in:
Marco Pesenti Gritti 2006-06-17 22:06:40 -04:00
parent 6d7940949a
commit afc587212e
4 changed files with 24 additions and 14 deletions

View File

@ -1,9 +1,11 @@
import logging
import xml.sax.saxutils
import dbus import dbus
import pygtk import pygtk
pygtk.require('2.0') pygtk.require('2.0')
import gtk import gtk
import geckoembed import geckoembed
import xml.sax.saxutils
from sugar.shell import activity from sugar.shell import activity
from sugar.browser import NotificationBar from sugar.browser import NotificationBar
@ -25,26 +27,30 @@ class BrowserActivity(activity.Activity):
activity.Activity.__init__(self, _BROWSER_ACTIVITY_TYPE) activity.Activity.__init__(self, _BROWSER_ACTIVITY_TYPE)
self.uri = uri self.uri = uri
self._mode = mode self._mode = mode
logging.debug('Start presence service')
self._pservice = PresenceService.get_instance() self._pservice = PresenceService.get_instance()
self._pservice.start() self._pservice.start()
logging.debug('Track browser activities')
self._pservice.connect('service-appeared', self._service_appeared_cb) self._pservice.connect('service-appeared', self._service_appeared_cb)
self._pservice.track_service_type(_BROWSER_ACTIVITY_TYPE) self._pservice.track_service_type(_BROWSER_ACTIVITY_TYPE)
self._pservice.track_service_type(LocalModel.SERVICE_TYPE)
self._share_service = None self._share_service = None
self._model_service = None self._model_service = None
self._notif_service = None self._notif_service = None
self._model = None self._model = None
def _service_appeared_cb(self, pservice, buddy, service): def _service_appeared_cb(self, pservice, buddy, service):
print 'Got service ' + service.get_type() print 'appeared ' + service.get_type()
if service.get_type() == _BROWSER_ACTIVITY_TYPE: if service.get_type() == _BROWSER_ACTIVITY_TYPE:
print 'Activity service found'
self._notif_service = service self._notif_service = service
elif service.get_type() == LocalModel.SERVICE_TYPE: elif service.get_type() == LocalModel.SERVICE_TYPE:
print 'Model service found' if self._mode != BrowserActivity.LEADING:
self._model_service = service self._model_service = service
if self._notif_service and self._model_service: if self._notif_service and self._model_service:
print 'Create remote model'
self._model = RemoteModel(self._model_service, self._notif_service) self._model = RemoteModel(self._model_service, self._notif_service)
self._model.add_listener(self.__shared_location_changed_cb) self._model.add_listener(self.__shared_location_changed_cb)
@ -75,9 +81,6 @@ class BrowserActivity(activity.Activity):
self._notif_bar.set_icon('stock_shared-by-me') self._notif_bar.set_icon('stock_shared-by-me')
self._notif_bar.show() self._notif_bar.show()
def _follow(self, service):
self._pservice.track_service_type(LocalModel.SERVICE_TYPE)
def on_connected_to_shell(self): def on_connected_to_shell(self):
self.set_ellipsize_tab(True) self.set_ellipsize_tab(True)
self.set_can_close(True) self.set_can_close(True)
@ -107,10 +110,10 @@ class BrowserActivity(activity.Activity):
plug.show() plug.show()
vbox.show() vbox.show()
if self._mode == BrowserActivity.FOLLOWING: # FIXME remove, when we join the activity this will happen automatically
self._follow(self.uri) self._pservice.track_activity(self.get_id())
def get_embed(self): def get_embed(self):
return self.embed return self.embed

View File

@ -1,8 +1,11 @@
import logging
from sugar.p2p.Notifier import Notifier from sugar.p2p.Notifier import Notifier
import network from sugar.p2p import network
class NotificationListener: class NotificationListener:
def __init__(self, service): def __init__(self, service):
logging.debug('Start notification listener. Service %s, address %s, port %s' % (service.get_type(), service.get_address(), service.get_port()))
server = network.GroupServer(service.get_address(), server = network.GroupServer(service.get_address(),
service.get_port(), service.get_port(),
self._recv_multicast) self._recv_multicast)

View File

@ -1,4 +1,5 @@
import socket import socket
import logging
from sugar.presence.Service import Service from sugar.presence.Service import Service
from sugar.p2p.Notifier import Notifier from sugar.p2p.Notifier import Notifier
@ -50,6 +51,7 @@ class LocalModel(AbstractModel):
port = service.get_port() port = service.get_port()
while not started and tries > 0: while not started and tries > 0:
try: try:
logging.debug('Start model server on port %d' % (port))
p2p_server = network.GlibXMLRPCServer(("", port)) p2p_server = network.GlibXMLRPCServer(("", port))
p2p_server.register_instance(ModelRequestHandler(self)) p2p_server.register_instance(ModelRequestHandler(self))
started = True started = True

View File

@ -1,4 +1,5 @@
import xmlrpclib import xmlrpclib
import logging
from sugar.p2p.NotificationListener import NotificationListener from sugar.p2p.NotificationListener import NotificationListener
from sugar.p2p.model.AbstractModel import AbstractModel from sugar.p2p.model.AbstractModel import AbstractModel
@ -11,6 +12,7 @@ class RemoteModel(AbstractModel):
self._notification_service = notification_service self._notification_service = notification_service
addr = "http://%s:%d" % (service.get_address(), service.get_port()) addr = "http://%s:%d" % (service.get_address(), service.get_port())
logging.debug('Setup remote model ' + addr)
self._client = xmlrpclib.ServerProxy(addr) self._client = xmlrpclib.ServerProxy(addr)
self._setup_notification_listener() self._setup_notification_listener()