Register the model service and start working on
looking it up
This commit is contained in:
@@ -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,
|
||||
stype=LocalModel.SERVICE_TYPE,
|
||||
'', port=LocalModel.PORT_TYPE
|
||||
properties=properties)
|
||||
service = self._pservice.share_activity(self._activity,
|
||||
stype = LocalModel.SERVICE_TYPE,
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user