Register the model service and start working on
looking it up
This commit is contained in:
parent
5446b2509f
commit
0cae557ab5
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
*.pyc
|
||||
*~
|
||||
|
@ -10,6 +10,7 @@ from sugar.browser import NotificationBar
|
||||
from sugar.browser import NavigationToolbar
|
||||
from sugar.presence.PresenceService import PresenceService
|
||||
from sugar.p2p.model.LocalModel import LocalModel
|
||||
from sugar.p2p.model.RemoteModel import RemoteModel
|
||||
|
||||
_BROWSER_ACTIVITY_TYPE = "_web_olpc._udp"
|
||||
_SERVICE_URI_TAG = "URI"
|
||||
@ -46,20 +47,16 @@ class BrowserActivity(activity.Activity):
|
||||
self.embed.load_address(address)
|
||||
self._notif_bar.hide()
|
||||
|
||||
#def set_mode(self, mode):
|
||||
# self._mode = mode
|
||||
# if mode == BrowserActivity.LEADING:
|
||||
# self._notif_bar.set_text('Share this page with the group.')
|
||||
# self._notif_bar.set_action('set_shared_location', 'Share')
|
||||
# self._notif_bar.set_icon('stock_shared-by-me')
|
||||
# self._notif_bar.show()
|
||||
def set_mode(self, mode):
|
||||
self._mode = mode
|
||||
if mode == BrowserActivity.LEADING:
|
||||
self._notif_bar.set_text('Share this page with the group.')
|
||||
self._notif_bar.set_action('set_shared_location', 'Share')
|
||||
self._notif_bar.set_icon('stock_shared-by-me')
|
||||
self._notif_bar.show()
|
||||
|
||||
def _setup_shared(self, uri):
|
||||
pass
|
||||
#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 _setup_shared(self, service, no):
|
||||
self._model = RemoteModel(service, notification_service)
|
||||
|
||||
def on_connected_to_shell(self):
|
||||
self.set_ellipsize_tab(True)
|
||||
@ -106,9 +103,10 @@ class BrowserActivity(activity.Activity):
|
||||
stype=_BROWSER_ACTIVITY_TYPE, properties=properties)
|
||||
|
||||
# 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._update_shared_location()
|
||||
|
||||
self.set_mode(BrowserActivity.LEADING)
|
||||
|
||||
def __title_cb(self, embed):
|
||||
|
@ -2,9 +2,8 @@ from sugar.p2p.Notifier import Notifier
|
||||
import network
|
||||
|
||||
class NotificationListener:
|
||||
def __init__(self, group, name):
|
||||
service = group.get_service(name, Notifier.TYPE)
|
||||
server = network.GroupServer(service.get_group_address(),
|
||||
def __init__(self, service):
|
||||
server = network.GroupServer(service.get_address(),
|
||||
service.get_port(),
|
||||
self._recv_multicast)
|
||||
server.start()
|
||||
|
@ -2,15 +2,8 @@ from sugar.p2p import network
|
||||
from sugar.presence.Service import Service
|
||||
|
||||
class Notifier:
|
||||
TYPE = "_olpc_model_notification._udp"
|
||||
ADDRESS = "224.0.0.222"
|
||||
PORT = 6300
|
||||
|
||||
def __init__(self, group, name):
|
||||
service = Service(name, Notifier.TYPE, Notifier.PORT, Notifier.ADDRESS)
|
||||
service.register(group)
|
||||
|
||||
address = service.get_group_address()
|
||||
def __init__(self, service):
|
||||
address = service.get_address()
|
||||
port = service.get_port()
|
||||
self._client = network.GroupClient(address, port)
|
||||
|
||||
|
@ -19,14 +19,15 @@ class LocalModel(AbstractModel):
|
||||
SERVICE_TYPE = "_olpc_model._tcp"
|
||||
SERVICE_PORT = 6300
|
||||
|
||||
def __init__(self, pservice, model_id):
|
||||
def __init__(self, activity, pservice, service):
|
||||
AbstractModel.__init__(self)
|
||||
self._pservice = pservice
|
||||
self._model_id = model_id
|
||||
self._activity = activity
|
||||
self._service = service
|
||||
self._values = {}
|
||||
|
||||
self._setup_service()
|
||||
self._notifier = Notifier(group, model_id)
|
||||
self._notifier = Notifier(service)
|
||||
|
||||
def get_value(self, key):
|
||||
return self._values[key]
|
||||
@ -37,10 +38,9 @@ class LocalModel(AbstractModel):
|
||||
self._notifier.notify(key)
|
||||
|
||||
def _setup_service(self):
|
||||
self._service = self._pservice.share_activity(self,
|
||||
service = self._pservice.share_activity(self._activity,
|
||||
stype = LocalModel.SERVICE_TYPE,
|
||||
'', port=LocalModel.PORT_TYPE
|
||||
properties=properties)
|
||||
address = '', port = LocalModel.SERVICE_PORT)
|
||||
self._setup_server(service)
|
||||
|
||||
# FIXME this is duplicated with StreamReader
|
||||
|
@ -4,11 +4,11 @@ from sugar.p2p.NotificationListener import NotificationListener
|
||||
from sugar.p2p.model.AbstractModel import AbstractModel
|
||||
|
||||
class RemoteModel(AbstractModel):
|
||||
def __init__(self, group, service):
|
||||
def __init__(self, service, notification_service):
|
||||
AbstractModel.__init__(self)
|
||||
|
||||
self._service = service
|
||||
self._group = group
|
||||
self._notification_service = notification_service
|
||||
|
||||
addr = "http://%s:%d" % (service.get_address(), service.get_port())
|
||||
self._client = xmlrpclib.ServerProxy(addr)
|
||||
@ -23,5 +23,5 @@ class RemoteModel(AbstractModel):
|
||||
|
||||
def _setup_notification_listener(self):
|
||||
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)
|
||||
|
@ -122,6 +122,15 @@ class PresenceService(gobject.GObject):
|
||||
self._server = dbus.Interface(self._bus.get_object(avahi.DBUS_NAME,
|
||||
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):
|
||||
"""Start the presence service by kicking off service discovery."""
|
||||
self._lock.acquire()
|
||||
|
Loading…
Reference in New Issue
Block a user