Register the model service and start working on

looking it up
This commit is contained in:
Marco Pesenti Gritti 2006-06-16 14:20:09 -04:00
parent 5446b2509f
commit 0cae557ab5
7 changed files with 36 additions and 36 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
*.pyc *.pyc
*~

View File

@ -10,6 +10,7 @@ from sugar.browser import NotificationBar
from sugar.browser import NavigationToolbar from sugar.browser import NavigationToolbar
from sugar.presence.PresenceService import PresenceService from sugar.presence.PresenceService import PresenceService
from sugar.p2p.model.LocalModel import LocalModel from sugar.p2p.model.LocalModel import LocalModel
from sugar.p2p.model.RemoteModel import RemoteModel
_BROWSER_ACTIVITY_TYPE = "_web_olpc._udp" _BROWSER_ACTIVITY_TYPE = "_web_olpc._udp"
_SERVICE_URI_TAG = "URI" _SERVICE_URI_TAG = "URI"
@ -46,20 +47,16 @@ class BrowserActivity(activity.Activity):
self.embed.load_address(address) self.embed.load_address(address)
self._notif_bar.hide() self._notif_bar.hide()
#def set_mode(self, mode): def set_mode(self, mode):
# self._mode = mode self._mode = mode
# if mode == BrowserActivity.LEADING: if mode == BrowserActivity.LEADING:
# self._notif_bar.set_text('Share this page with the group.') self._notif_bar.set_text('Share this page with the group.')
# self._notif_bar.set_action('set_shared_location', 'Share') self._notif_bar.set_action('set_shared_location', 'Share')
# 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 _setup_shared(self, uri): def _setup_shared(self, service, no):
pass self._model = RemoteModel(service, notification_service)
#self._model = self._group.get_store().get_model(uri)
#if self._model:
# self.set_mode(BrowserActivity.FOLLOWING)
# self._model.add_listener(self.__shared_location_changed_cb)
def on_connected_to_shell(self): def on_connected_to_shell(self):
self.set_ellipsize_tab(True) self.set_ellipsize_tab(True)
@ -106,9 +103,10 @@ class BrowserActivity(activity.Activity):
stype=_BROWSER_ACTIVITY_TYPE, properties=properties) stype=_BROWSER_ACTIVITY_TYPE, properties=properties)
# Create our activity-specific browser sharing service # Create our activity-specific browser sharing service
self._model = LocalModel(stype) self._model = LocalModel(self, self._pservice, self._share_service)
self._model.set_value('owner', self._pservice.get_owner().get_nick_name()) self._model.set_value('owner', self._pservice.get_owner().get_nick_name())
self._update_shared_location() self._update_shared_location()
self.set_mode(BrowserActivity.LEADING) self.set_mode(BrowserActivity.LEADING)
def __title_cb(self, embed): def __title_cb(self, embed):

View File

@ -2,9 +2,8 @@ from sugar.p2p.Notifier import Notifier
import network import network
class NotificationListener: class NotificationListener:
def __init__(self, group, name): def __init__(self, service):
service = group.get_service(name, Notifier.TYPE) server = network.GroupServer(service.get_address(),
server = network.GroupServer(service.get_group_address(),
service.get_port(), service.get_port(),
self._recv_multicast) self._recv_multicast)
server.start() server.start()

View File

@ -2,15 +2,8 @@ from sugar.p2p import network
from sugar.presence.Service import Service from sugar.presence.Service import Service
class Notifier: class Notifier:
TYPE = "_olpc_model_notification._udp" def __init__(self, service):
ADDRESS = "224.0.0.222" address = service.get_address()
PORT = 6300
def __init__(self, group, name):
service = Service(name, Notifier.TYPE, Notifier.PORT, Notifier.ADDRESS)
service.register(group)
address = service.get_group_address()
port = service.get_port() port = service.get_port()
self._client = network.GroupClient(address, port) self._client = network.GroupClient(address, port)

View File

@ -19,14 +19,15 @@ class LocalModel(AbstractModel):
SERVICE_TYPE = "_olpc_model._tcp" SERVICE_TYPE = "_olpc_model._tcp"
SERVICE_PORT = 6300 SERVICE_PORT = 6300
def __init__(self, pservice, model_id): def __init__(self, activity, pservice, service):
AbstractModel.__init__(self) AbstractModel.__init__(self)
self._pservice = pservice self._pservice = pservice
self._model_id = model_id self._activity = activity
self._service = service
self._values = {} self._values = {}
self._setup_service() self._setup_service()
self._notifier = Notifier(group, model_id) self._notifier = Notifier(service)
def get_value(self, key): def get_value(self, key):
return self._values[key] return self._values[key]
@ -37,10 +38,9 @@ class LocalModel(AbstractModel):
self._notifier.notify(key) self._notifier.notify(key)
def _setup_service(self): def _setup_service(self):
self._service = self._pservice.share_activity(self, service = self._pservice.share_activity(self._activity,
stype=LocalModel.SERVICE_TYPE, stype = LocalModel.SERVICE_TYPE,
'', port=LocalModel.PORT_TYPE address = '', port = LocalModel.SERVICE_PORT)
properties=properties)
self._setup_server(service) self._setup_server(service)
# FIXME this is duplicated with StreamReader # FIXME this is duplicated with StreamReader

View File

@ -4,11 +4,11 @@ from sugar.p2p.NotificationListener import NotificationListener
from sugar.p2p.model.AbstractModel import AbstractModel from sugar.p2p.model.AbstractModel import AbstractModel
class RemoteModel(AbstractModel): class RemoteModel(AbstractModel):
def __init__(self, group, service): def __init__(self, service, notification_service):
AbstractModel.__init__(self) AbstractModel.__init__(self)
self._service = service self._service = service
self._group = group 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())
self._client = xmlrpclib.ServerProxy(addr) self._client = xmlrpclib.ServerProxy(addr)
@ -23,5 +23,5 @@ class RemoteModel(AbstractModel):
def _setup_notification_listener(self): def _setup_notification_listener(self):
name = self._service.get_name() name = self._service.get_name()
self._notification = NotificationListener(self._group, name) self._notification = NotificationListener(self._notification_service)
self._notification.add_listener(self._notify_model_change) self._notification.add_listener(self._notify_model_change)

View File

@ -122,6 +122,15 @@ class PresenceService(gobject.GObject):
self._server = dbus.Interface(self._bus.get_object(avahi.DBUS_NAME, self._server = dbus.Interface(self._bus.get_object(avahi.DBUS_NAME,
avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER) avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
def get_activity_service(activity, stype):
uid = activity.get_id()
if self._activity_services.has_key(uid):
services = self._activity_services[uid]
for service in services:
if group.get_stype() == stype:
return service
return None
def start(self): def start(self):
"""Start the presence service by kicking off service discovery.""" """Start the presence service by kicking off service discovery."""
self._lock.acquire() self._lock.acquire()