The notifier should own the server not the listener!
This commit is contained in:
parent
6b78600646
commit
27b89c5b24
File diff suppressed because it is too large
Load Diff
@ -2,20 +2,12 @@ from Service import Service
|
||||
import network
|
||||
|
||||
class NotificationListener:
|
||||
TYPE = "_olpc_model_notification._udp"
|
||||
ADDRESS = "224.0.0.222"
|
||||
PORT = 6300
|
||||
|
||||
def __init__(self, group, name):
|
||||
server = network.GroupServer(NotificationListener.TYPE,
|
||||
NotificationListener.PORT,
|
||||
service = group.get_service(name, Notifier.TYPE)
|
||||
server = network.GroupServer(service.get_address(),
|
||||
service.get_port(),
|
||||
self._recv_multicast)
|
||||
server.start()
|
||||
|
||||
service = Service(name, NotificationListener.TYPE,
|
||||
NotificationListener.ADDRESS,
|
||||
NotificationListener.PORT, True)
|
||||
service.register(group)
|
||||
|
||||
self._listeners = {}
|
||||
|
||||
|
@ -1,8 +1,17 @@
|
||||
import network
|
||||
from sugar.p2p.NotificationListener import NotificationListener
|
||||
from sugar.p2p import network
|
||||
|
||||
class Notifier:
|
||||
TYPE = "_olpc_model_notification._udp"
|
||||
ADDRESS = "224.0.0.222"
|
||||
PORT = 6300
|
||||
|
||||
def __init__(self, group, name):
|
||||
service = group.get_service(name)
|
||||
service = Service(name, NotificationListener.TYPE,
|
||||
NotificationListener.ADDRESS,
|
||||
NotificationListener.PORT, True)
|
||||
service.register(group)
|
||||
|
||||
address = service.get_address()
|
||||
port = service.get_port()
|
||||
self._client = network.GroupClient(address, port)
|
||||
|
@ -1,6 +1,7 @@
|
||||
import socket
|
||||
|
||||
from sugar.p2p.Service import Service
|
||||
from sugar.p2p.Notifier import Notifier
|
||||
from sugar.p2p.model.AbstractModel import AbstractModel
|
||||
from sugar.p2p import network
|
||||
|
||||
@ -25,6 +26,7 @@ class LocalModel(AbstractModel):
|
||||
self._values = {}
|
||||
|
||||
self._setup_service()
|
||||
self._notifier = Notifier(group, model_id)
|
||||
|
||||
def get_value(self, key):
|
||||
return self._values[key]
|
||||
@ -32,6 +34,7 @@ class LocalModel(AbstractModel):
|
||||
def set_value(self, key, value):
|
||||
self._values[key] = value
|
||||
self._notify_model_change(key)
|
||||
self._notifier.notify(key)
|
||||
|
||||
def _setup_service(self):
|
||||
service = Service(self._model_id, LocalModel.SERVICE_TYPE, '',
|
||||
|
0
sugar/p2p/model/__init__.py
Normal file
0
sugar/p2p/model/__init__.py
Normal file
Loading…
Reference in New Issue
Block a user